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.

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

Referenced by BufferAlloc(), and InvalidateBuffer().

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

◆ BufTableHashCode()

uint32 BufTableHashCode ( BufferTag tagPtr)

Definition at line 79 of file buf_table.c.

References get_hash_value().

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

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

◆ BufTableInsert()

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

Definition at line 119 of file buf_table.c.

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

Referenced by BufferAlloc().

120 {
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  (void *) 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 }
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:921
#define P_NEW
Definition: bufmgr.h:91
int result
Definition: header.h:19
#define Assert(condition)
Definition: c.h:738
static HTAB * SharedBufHash
Definition: buf_table.c:34
BlockNumber blockNum
Definition: buf_internals.h:94

◆ BufTableLookup()

int BufTableLookup ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 91 of file buf_table.c.

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

Referenced by BufferAlloc(), and PrefetchSharedBuffer().

92 {
94 
95  result = (BufferLookupEnt *)
97  (void *) tagPtr,
98  hashcode,
99  HASH_FIND,
100  NULL);
101 
102  if (!result)
103  return -1;
104 
105  return result->id;
106 }
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:921
int result
Definition: header.h:19
static HTAB * SharedBufHash
Definition: buf_table.c:34

◆ BufTableShmemSize()

Size BufTableShmemSize ( int  size)

Definition at line 42 of file buf_table.c.

References hash_estimate_size().

Referenced by StrategyShmemSize().

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

◆ InitBufTable()

void InitBufTable ( int  size)

Definition at line 52 of file buf_table.c.

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

Referenced by StrategyInitialize().

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 }
#define HASH_ELEM
Definition: hsearch.h:87
Size entrysize
Definition: hsearch.h:73
struct buftag BufferTag
#define HASH_PARTITION
Definition: hsearch.h:83
long num_partitions
Definition: hsearch.h:67
#define NUM_BUFFER_PARTITIONS
Definition: lwlock.h:112
#define HASH_BLOBS
Definition: hsearch.h:88
Size keysize
Definition: hsearch.h:72
static HTAB * SharedBufHash
Definition: buf_table.c:34
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:337

Variable Documentation

◆ SharedBufHash

HTAB* SharedBufHash
static

Definition at line 34 of file buf_table.c.