PostgreSQL Source Code  git master
buf_table.c File Reference
#include "postgres.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
Include dependency graph for buf_table.c:

Go to the source code of this file.

Data Structures

struct  BufferLookupEnt
 

Functions

Size BufTableShmemSize (int size)
 
void InitBufTable (int size)
 
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
 

Function Documentation

◆ BufTableDelete()

void BufTableDelete ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 149 of file buf_table.c.

150 {
151  BufferLookupEnt *result;
152 
153  result = (BufferLookupEnt *)
155  tagPtr,
156  hashcode,
157  HASH_REMOVE,
158  NULL);
159 
160  if (!result) /* shouldn't happen */
161  elog(ERROR, "shared buffer hash table corrupted");
162 }
static HTAB * SharedBufHash
Definition: buf_table.c:34
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:966
#define ERROR
Definition: elog.h:39
@ HASH_REMOVE
Definition: hsearch.h:115

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

Referenced by InvalidateBuffer(), and InvalidateVictimBuffer().

◆ BufTableHashCode()

uint32 BufTableHashCode ( BufferTag tagPtr)

Definition at line 79 of file buf_table.c.

80 {
81  return get_hash_value(SharedBufHash, (void *) tagPtr);
82 }
uint32 get_hash_value(HTAB *hashp, const void *keyPtr)
Definition: dynahash.c:909

References 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 119 of file buf_table.c.

120 {
121  BufferLookupEnt *result;
122  bool found;
123 
124  Assert(buf_id >= 0); /* -1 is reserved for not-in-table */
125  Assert(tagPtr->blockNum != P_NEW); /* invalid tag */
126 
127  result = (BufferLookupEnt *)
129  tagPtr,
130  hashcode,
131  HASH_ENTER,
132  &found);
133 
134  if (found) /* found something already in the table */
135  return result->id;
136 
137  result->id = buf_id;
138 
139  return -1;
140 }
#define P_NEW
Definition: bufmgr.h:152
@ HASH_ENTER
Definition: hsearch.h:114
Assert(fmt[strlen(fmt) - 1] !='\n')
BlockNumber blockNum
Definition: buf_internals.h:97

References Assert(), buftag::blockNum, HASH_ENTER, hash_search_with_hash_value(), BufferLookupEnt::id, P_NEW, and SharedBufHash.

Referenced by BufferAlloc(), and ExtendBufferedRelShared().

◆ BufTableLookup()

int BufTableLookup ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 91 of file buf_table.c.

92 {
93  BufferLookupEnt *result;
94 
95  result = (BufferLookupEnt *)
97  tagPtr,
98  hashcode,
99  HASH_FIND,
100  NULL);
101 
102  if (!result)
103  return -1;
104 
105  return result->id;
106 }
@ HASH_FIND
Definition: hsearch.h:113

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

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

◆ BufTableShmemSize()

Size BufTableShmemSize ( int  size)

Definition at line 42 of file buf_table.c.

43 {
44  return hash_estimate_size(size, sizeof(BufferLookupEnt));
45 }
Size hash_estimate_size(long num_entries, Size entrysize)
Definition: dynahash.c:781

References hash_estimate_size().

Referenced by StrategyShmemSize().

◆ InitBufTable()

void InitBufTable ( int  size)

Definition at line 52 of file buf_table.c.

53 {
54  HASHCTL info;
55 
56  /* assume no locking is needed yet */
57 
58  /* BufferTag maps to Buffer */
59  info.keysize = sizeof(BufferTag);
60  info.entrysize = sizeof(BufferLookupEnt);
62 
63  SharedBufHash = ShmemInitHash("Shared Buffer Lookup Table",
64  size, size,
65  &info,
67 }
struct buftag BufferTag
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
#define HASH_PARTITION
Definition: hsearch.h:92
#define NUM_BUFFER_PARTITIONS
Definition: lwlock.h:95
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:341
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
long num_partitions
Definition: hsearch.h:68

References HASHCTL::entrysize, HASH_BLOBS, HASH_ELEM, HASH_PARTITION, HASHCTL::keysize, NUM_BUFFER_PARTITIONS, HASHCTL::num_partitions, SharedBufHash, and ShmemInitHash().

Referenced by StrategyInitialize().

Variable Documentation

◆ SharedBufHash

HTAB* SharedBufHash
static