PostgreSQL Source Code git master
Loading...
Searching...
No Matches
buf_table.c File Reference
#include "postgres.h"
#include "storage/buf_internals.h"
#include "storage/subsystems.h"
Include dependency graph for buf_table.c:

Go to the source code of this file.

Data Structures

struct  BufferLookupEnt
 

Functions

static void BufTableShmemRequest (void *arg)
 
uint32 BufTableHashCode (BufferTag *tagPtr)
 
int BufTableLookup (BufferTag *tagPtr, uint32 hashcode)
 
int BufTableInsert (BufferTag *tagPtr, uint32 hashcode, int buf_id)
 
void BufTableDelete (BufferTag *tagPtr, uint32 hashcode)
 

Variables

static HTABSharedBufHash
 
const ShmemCallbacks BufTableShmemCallbacks
 

Function Documentation

◆ BufTableDelete()

void BufTableDelete ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 154 of file buf_table.c.

155{
157
160 tagPtr,
161 hashcode,
163 NULL);
164
165 if (!result) /* shouldn't happen */
166 elog(ERROR, "shared buffer hash table corrupted");
167}
static HTAB * SharedBufHash
Definition buf_table.c:34
uint32 result
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition dynahash.c:902
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
@ HASH_REMOVE
Definition hsearch.h:110
static int fb(int x)

References elog, ERROR, fb(), HASH_REMOVE, hash_search_with_hash_value(), result, and SharedBufHash.

Referenced by InvalidateBuffer(), and InvalidateVictimBuffer().

◆ BufTableHashCode()

uint32 BufTableHashCode ( BufferTag tagPtr)

Definition at line 84 of file buf_table.c.

85{
87}
uint32 get_hash_value(HTAB *hashp, const void *keyPtr)
Definition dynahash.c:845

References fb(), get_hash_value(), and SharedBufHash.

Referenced by BufferAlloc(), ExtendBufferedRelShared(), FindAndDropRelationBuffers(), InvalidateBuffer(), InvalidateVictimBuffer(), and PrefetchSharedBuffer().

◆ BufTableInsert()

int BufTableInsert ( BufferTag tagPtr,
uint32  hashcode,
int  buf_id 
)

Definition at line 124 of file buf_table.c.

125{
127 bool found;
128
129 Assert(buf_id >= 0); /* -1 is reserved for not-in-table */
130 Assert(tagPtr->blockNum != P_NEW); /* invalid tag */
131
134 tagPtr,
135 hashcode,
137 &found);
138
139 if (found) /* found something already in the table */
140 return result->id;
141
142 result->id = buf_id;
143
144 return -1;
145}
#define P_NEW
Definition bufmgr.h:200
#define Assert(condition)
Definition c.h:943
@ HASH_ENTER
Definition hsearch.h:109

References Assert, fb(), HASH_ENTER, hash_search_with_hash_value(), P_NEW, result, and SharedBufHash.

Referenced by BufferAlloc(), and ExtendBufferedRelShared().

◆ BufTableLookup()

int BufTableLookup ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 96 of file buf_table.c.

97{
99
102 tagPtr,
103 hashcode,
104 HASH_FIND,
105 NULL);
106
107 if (!result)
108 return -1;
109
110 return result->id;
111}
@ HASH_FIND
Definition hsearch.h:108

References fb(), HASH_FIND, hash_search_with_hash_value(), BufferLookupEnt::id, result, and SharedBufHash.

Referenced by BufferAlloc(), FindAndDropRelationBuffers(), and PrefetchSharedBuffer().

◆ BufTableShmemRequest()

void BufTableShmemRequest ( void arg)
static

Definition at line 48 of file buf_table.c.

49{
50 int size;
51
52 /*
53 * Request the shared buffer lookup hashtable.
54 *
55 * Since we can't tolerate running out of lookup table entries, we must be
56 * sure to specify an adequate table size here. The maximum steady-state
57 * usage is of course NBuffers entries, but BufferAlloc() tries to insert
58 * a new entry before deleting the old. In principle this could be
59 * happening in each partition concurrently, so we could need as many as
60 * NBuffers + NUM_BUFFER_PARTITIONS entries.
61 */
63
64 ShmemRequestHash(.name = "Shared Buffer Lookup Table",
65 .nelems = size,
66 .ptr = &SharedBufHash,
67 .hash_info.keysize = sizeof(BufferTag),
68 .hash_info.entrysize = sizeof(BufferLookupEnt),
69 .hash_info.num_partitions = NUM_BUFFER_PARTITIONS,
71 );
72}
int NBuffers
Definition globals.c:144
#define HASH_ELEM
Definition hsearch.h:90
#define HASH_BLOBS
Definition hsearch.h:92
#define HASH_FIXED_SIZE
Definition hsearch.h:100
#define HASH_PARTITION
Definition hsearch.h:87
#define NUM_BUFFER_PARTITIONS
Definition lwlock.h:83
#define ShmemRequestHash(...)
Definition shmem.h:179
Size keysize
Definition dynahash.c:241
const char * name

References HASH_BLOBS, HASH_ELEM, HASH_FIXED_SIZE, HASH_PARTITION, HTAB::keysize, name, NBuffers, NUM_BUFFER_PARTITIONS, SharedBufHash, and ShmemRequestHash.

Variable Documentation

◆ BufTableShmemCallbacks

const ShmemCallbacks BufTableShmemCallbacks
Initial value:
= {
.request_fn = BufTableShmemRequest,
}
static void BufTableShmemRequest(void *arg)
Definition buf_table.c:48

Definition at line 38 of file buf_table.c.

38 {
39 .request_fn = BufTableShmemRequest,
40 /* no special initialization needed, the hash table will start empty */
41};

◆ SharedBufHash

HTAB* SharedBufHash
static