PostgreSQL Source Code  git master
buf_table.c File Reference
#include "postgres.h"
#include "storage/buf_internals.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 148 of file buf_table.c.

149 {
150  BufferLookupEnt *result;
151 
152  result = (BufferLookupEnt *)
154  tagPtr,
155  hashcode,
156  HASH_REMOVE,
157  NULL);
158 
159  if (!result) /* shouldn't happen */
160  elog(ERROR, "shared buffer hash table corrupted");
161 }
static HTAB * SharedBufHash
Definition: buf_table.c:33
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:968
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
@ 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 78 of file buf_table.c.

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

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

119 {
120  BufferLookupEnt *result;
121  bool found;
122 
123  Assert(buf_id >= 0); /* -1 is reserved for not-in-table */
124  Assert(tagPtr->blockNum != P_NEW); /* invalid tag */
125 
126  result = (BufferLookupEnt *)
128  tagPtr,
129  hashcode,
130  HASH_ENTER,
131  &found);
132 
133  if (found) /* found something already in the table */
134  return result->id;
135 
136  result->id = buf_id;
137 
138  return -1;
139 }
#define P_NEW
Definition: bufmgr.h:188
#define Assert(condition)
Definition: c.h:858
@ HASH_ENTER
Definition: hsearch.h:114
BlockNumber blockNum
Definition: buf_internals.h:98

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

91 {
92  BufferLookupEnt *result;
93 
94  result = (BufferLookupEnt *)
96  tagPtr,
97  hashcode,
98  HASH_FIND,
99  NULL);
100 
101  if (!result)
102  return -1;
103 
104  return result->id;
105 }
@ 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 41 of file buf_table.c.

42 {
43  return hash_estimate_size(size, sizeof(BufferLookupEnt));
44 }
Size hash_estimate_size(long num_entries, Size entrysize)
Definition: dynahash.c:783
static pg_noinline void Size size
Definition: slab.c:607

References hash_estimate_size(), and size.

Referenced by StrategyShmemSize().

◆ InitBufTable()

void InitBufTable ( int  size)

Definition at line 51 of file buf_table.c.

52 {
53  HASHCTL info;
54 
55  /* assume no locking is needed yet */
56 
57  /* BufferTag maps to Buffer */
58  info.keysize = sizeof(BufferTag);
59  info.entrysize = sizeof(BufferLookupEnt);
61 
62  SharedBufHash = ShmemInitHash("Shared Buffer Lookup Table",
63  size, size,
64  &info,
66 }
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:93
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:332
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, ShmemInitHash(), and size.

Referenced by StrategyInitialize().

Variable Documentation

◆ SharedBufHash

HTAB* SharedBufHash
static