PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
buf_table.c File Reference
#include "postgres.h"
#include "storage/bufmgr.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

void BufTableDelete ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 150 of file buf_table.c.

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

Referenced by BufferAlloc(), and InvalidateBuffer().

151 {
153 
154  result = (BufferLookupEnt *)
156  (void *) tagPtr,
157  hashcode,
158  HASH_REMOVE,
159  NULL);
160 
161  if (!result) /* shouldn't happen */
162  elog(ERROR, "shared buffer hash table corrupted");
163 }
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:916
return result
Definition: formatting.c:1633
#define ERROR
Definition: elog.h:43
#define NULL
Definition: c.h:229
static HTAB * SharedBufHash
Definition: buf_table.c:35
#define elog
Definition: elog.h:219
uint32 BufTableHashCode ( BufferTag tagPtr)

Definition at line 80 of file buf_table.c.

References get_hash_value().

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

81 {
82  return get_hash_value(SharedBufHash, (void *) tagPtr);
83 }
uint32 get_hash_value(HTAB *hashp, const void *keyPtr)
Definition: dynahash.c:857
static HTAB * SharedBufHash
Definition: buf_table.c:35
int BufTableInsert ( BufferTag tagPtr,
uint32  hashcode,
int  buf_id 
)

Definition at line 120 of file buf_table.c.

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

Referenced by BufferAlloc().

121 {
123  bool found;
124 
125  Assert(buf_id >= 0); /* -1 is reserved for not-in-table */
126  Assert(tagPtr->blockNum != P_NEW); /* invalid tag */
127 
128  result = (BufferLookupEnt *)
130  (void *) tagPtr,
131  hashcode,
132  HASH_ENTER,
133  &found);
134 
135  if (found) /* found something already in the table */
136  return result->id;
137 
138  result->id = buf_id;
139 
140  return -1;
141 }
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:916
return result
Definition: formatting.c:1633
#define P_NEW
Definition: bufmgr.h:82
#define Assert(condition)
Definition: c.h:675
static HTAB * SharedBufHash
Definition: buf_table.c:35
BlockNumber blockNum
Definition: buf_internals.h:95
int BufTableLookup ( BufferTag tagPtr,
uint32  hashcode 
)

Definition at line 92 of file buf_table.c.

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

Referenced by BufferAlloc(), and PrefetchBuffer().

93 {
95 
96  result = (BufferLookupEnt *)
98  (void *) tagPtr,
99  hashcode,
100  HASH_FIND,
101  NULL);
102 
103  if (!result)
104  return -1;
105 
106  return result->id;
107 }
void * hash_search_with_hash_value(HTAB *hashp, const void *keyPtr, uint32 hashvalue, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:916
return result
Definition: formatting.c:1633
#define NULL
Definition: c.h:229
static HTAB * SharedBufHash
Definition: buf_table.c:35
Size BufTableShmemSize ( int  size)

Definition at line 43 of file buf_table.c.

References hash_estimate_size().

Referenced by StrategyShmemSize().

44 {
45  return hash_estimate_size(size, sizeof(BufferLookupEnt));
46 }
Size hash_estimate_size(long num_entries, Size entrysize)
Definition: dynahash.c:729
void InitBufTable ( int  size)

Definition at line 53 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().

54 {
55  HASHCTL info;
56 
57  /* assume no locking is needed yet */
58 
59  /* BufferTag maps to Buffer */
60  info.keysize = sizeof(BufferTag);
61  info.entrysize = sizeof(BufferLookupEnt);
63 
64  SharedBufHash = ShmemInitHash("Shared Buffer Lookup Table",
65  size, size,
66  &info,
68 }
#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:113
#define HASH_BLOBS
Definition: hsearch.h:88
Size keysize
Definition: hsearch.h:72
static HTAB * SharedBufHash
Definition: buf_table.c:35
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:317

Variable Documentation

HTAB* SharedBufHash
static

Definition at line 35 of file buf_table.c.