PostgreSQL Source Code  git master
shmem.c File Reference
#include "postgres.h"
#include "access/transam.h"
#include "fmgr.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/lwlock.h"
#include "storage/pg_shmem.h"
#include "storage/shmem.h"
#include "storage/spin.h"
#include "utils/builtins.h"
Include dependency graph for shmem.c:

Go to the source code of this file.

Macros

#define PG_GET_SHMEM_SIZES_COLS   4
 

Functions

static void * ShmemAllocRaw (Size size, Size *allocated_size)
 
void InitShmemAccess (void *seghdr)
 
void InitShmemAllocation (void)
 
void * ShmemAlloc (Size size)
 
void * ShmemAllocNoError (Size size)
 
void * ShmemAllocUnlocked (Size size)
 
bool ShmemAddrIsValid (const void *addr)
 
void InitShmemIndex (void)
 
HTABShmemInitHash (const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
 
void * ShmemInitStruct (const char *name, Size size, bool *foundPtr)
 
Size add_size (Size s1, Size s2)
 
Size mul_size (Size s1, Size s2)
 
Datum pg_get_shmem_allocations (PG_FUNCTION_ARGS)
 

Variables

static PGShmemHeaderShmemSegHdr
 
static void * ShmemBase
 
static void * ShmemEnd
 
slock_tShmemLock
 
static HTABShmemIndex = NULL
 

Macro Definition Documentation

◆ PG_GET_SHMEM_SIZES_COLS

#define PG_GET_SHMEM_SIZES_COLS   4

Function Documentation

◆ add_size()

Size add_size ( Size  s1,
Size  s2 
)

Definition at line 494 of file shmem.c.

495 {
496  Size result;
497 
498  result = s1 + s2;
499  /* We are assuming Size is an unsigned type here... */
500  if (result < s1 || result < s2)
501  ereport(ERROR,
502  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
503  errmsg("requested shared memory size overflows size_t")));
504  return result;
505 }
size_t Size
Definition: c.h:594
int errcode(int sqlerrcode)
Definition: elog.c:860
int errmsg(const char *fmt,...)
Definition: elog.c:1075
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
char * s1
char * s2

References ereport, errcode(), errmsg(), ERROR, s1, and s2.

Referenced by _brin_parallel_estimate_shared(), _bt_parallel_estimate_shared(), ApplyLauncherShmemSize(), AsyncShmemInit(), AsyncShmemSize(), AutoVacuumShmemSize(), BackendStatusShmemSize(), BackgroundWorkerShmemSize(), BTreeShmemSize(), BufferShmemSize(), CalculateShmemSize(), CheckpointerShmemSize(), CreateSharedProcArray(), estimate_variable_size(), EstimateClientConnectionInfoSpace(), EstimateComboCIDStateSpace(), EstimateGUCStateSpace(), EstimateLibraryStateSpace(), EstimateParamExecSpace(), EstimateParamListSpace(), EstimateSnapshotSpace(), EstimateTransactionStateSpace(), ExecAggEstimate(), ExecAppendEstimate(), ExecBitmapHeapEstimate(), ExecHashEstimate(), ExecIncrementalSortEstimate(), ExecMemoizeEstimate(), ExecSortEstimate(), expand_planner_arrays(), hash_estimate_size(), index_parallelscan_estimate(), index_parallelscan_initialize(), InitializeShmemGUCs(), InjectionPointShmemSize(), LockShmemSize(), LWLockShmemSize(), MultiXactShmemSize(), PgArchShmemSize(), pgss_memsize(), PMSignalShmemSize(), PredicateLockShmemSize(), ProcArrayShmemSize(), ProcGlobalShmemSize(), ProcSignalShmemSize(), ReplicationOriginShmemSize(), ReplicationSlotsShmemSize(), RequestAddinShmemSpace(), SerializeTransactionState(), shm_toc_estimate(), SInvalShmemSize(), StatsShmemSize(), StrategyShmemSize(), table_parallelscan_estimate(), tuplesort_estimate_shared(), TwoPhaseShmemSize(), WaitEventExtensionShmemSize(), WalRcvShmemSize(), WalSndShmemSize(), and XLOGShmemSize().

◆ InitShmemAccess()

void InitShmemAccess ( void *  seghdr)

Definition at line 101 of file shmem.c.

102 {
103  PGShmemHeader *shmhdr = (PGShmemHeader *) seghdr;
104 
105  ShmemSegHdr = shmhdr;
106  ShmemBase = (void *) shmhdr;
107  ShmemEnd = (char *) ShmemBase + shmhdr->totalsize;
108 }
static void * ShmemBase
Definition: shmem.c:84
static void * ShmemEnd
Definition: shmem.c:86
static PGShmemHeader * ShmemSegHdr
Definition: shmem.c:82
Size totalsize
Definition: pg_shmem.h:34

References ShmemBase, ShmemEnd, ShmemSegHdr, and PGShmemHeader::totalsize.

Referenced by CreateSharedMemoryAndSemaphores().

◆ InitShmemAllocation()

void InitShmemAllocation ( void  )

Definition at line 116 of file shmem.c.

117 {
118  PGShmemHeader *shmhdr = ShmemSegHdr;
119  char *aligned;
120 
121  Assert(shmhdr != NULL);
122 
123  /*
124  * Initialize the spinlock used by ShmemAlloc. We must use
125  * ShmemAllocUnlocked, since obviously ShmemAlloc can't be called yet.
126  */
128 
130 
131  /*
132  * Allocations after this point should go through ShmemAlloc, which
133  * expects to allocate everything on cache line boundaries. Make sure the
134  * first allocation begins on a cache line boundary.
135  */
136  aligned = (char *)
137  (CACHELINEALIGN((((char *) shmhdr) + shmhdr->freeoffset)));
138  shmhdr->freeoffset = aligned - (char *) shmhdr;
139 
140  /* ShmemIndex can't be set up yet (need LWLocks first) */
141  shmhdr->index = NULL;
142  ShmemIndex = (HTAB *) NULL;
143 }
#define CACHELINEALIGN(LEN)
Definition: c.h:803
Assert(fmt[strlen(fmt) - 1] !='\n')
int slock_t
Definition: s_lock.h:754
slock_t * ShmemLock
Definition: shmem.c:88
static HTAB * ShmemIndex
Definition: shmem.c:91
void * ShmemAllocUnlocked(Size size)
Definition: shmem.c:239
#define SpinLockInit(lock)
Definition: spin.h:60
Definition: dynahash.c:220

References Assert(), CACHELINEALIGN, PGShmemHeader::freeoffset, PGShmemHeader::index, ShmemAllocUnlocked(), ShmemIndex, ShmemLock, ShmemSegHdr, and SpinLockInit.

Referenced by CreateSharedMemoryAndSemaphores().

◆ InitShmemIndex()

void InitShmemIndex ( void  )

Definition at line 284 of file shmem.c.

285 {
286  HASHCTL info;
287 
288  /*
289  * Create the shared memory shmem index.
290  *
291  * Since ShmemInitHash calls ShmemInitStruct, which expects the ShmemIndex
292  * hashtable to exist already, we have a bit of a circularity problem in
293  * initializing the ShmemIndex itself. The special "ShmemIndex" hash
294  * table name will tell ShmemInitStruct to fake it.
295  */
297  info.entrysize = sizeof(ShmemIndexEnt);
298 
299  ShmemIndex = ShmemInitHash("ShmemIndex",
301  &info,
303 }
#define HASH_STRINGS
Definition: hsearch.h:96
#define HASH_ELEM
Definition: hsearch.h:95
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:333
#define SHMEM_INDEX_SIZE
Definition: shmem.h:48
#define SHMEM_INDEX_KEYSIZE
Definition: shmem.h:46
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76

References HASHCTL::entrysize, HASH_ELEM, HASH_STRINGS, HASHCTL::keysize, SHMEM_INDEX_KEYSIZE, SHMEM_INDEX_SIZE, ShmemIndex, and ShmemInitHash().

Referenced by CreateOrAttachShmemStructs().

◆ mul_size()

Size mul_size ( Size  s1,
Size  s2 
)

Definition at line 511 of file shmem.c.

512 {
513  Size result;
514 
515  if (s1 == 0 || s2 == 0)
516  return 0;
517  result = s1 * s2;
518  /* We are assuming Size is an unsigned type here... */
519  if (result / s2 != s1)
520  ereport(ERROR,
521  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
522  errmsg("requested shared memory size overflows size_t")));
523  return result;
524 }

References ereport, errcode(), errmsg(), ERROR, s1, and s2.

Referenced by _brin_begin_parallel(), _bt_begin_parallel(), ApplyLauncherShmemSize(), AsyncShmemInit(), AsyncShmemSize(), AutoVacuumShmemSize(), BackendStatusShmemSize(), BackgroundWorkerShmemSize(), BTreeShmemSize(), BufferShmemSize(), CheckpointerShmemSize(), CreateSharedBackendStatus(), CreateSharedProcArray(), EstimateComboCIDStateSpace(), EstimatePendingSyncsSpace(), EstimateReindexStateSpace(), EstimateSnapshotSpace(), EstimateTransactionStateSpace(), ExecAggEstimate(), ExecHashEstimate(), ExecIncrementalSortEstimate(), ExecInitParallelPlan(), ExecMemoizeEstimate(), ExecParallelRetrieveInstrumentation(), ExecParallelRetrieveJitInstrumentation(), ExecParallelSetupTupleQueues(), ExecSortEstimate(), hash_estimate_size(), InitializeParallelDSM(), InitPredicateLocks(), LWLockShmemSize(), parallel_vacuum_init(), PGSemaphoreShmemSize(), PMSignalShmemSize(), PredicateLockShmemSize(), ProcArrayShmemSize(), ProcGlobalShmemSize(), ProcSignalShmemSize(), ReplicationOriginShmemSize(), ReplicationSlotsShmemSize(), shm_toc_estimate(), SInvalShmemSize(), tuplesort_estimate_shared(), TwoPhaseShmemSize(), WalSndShmemSize(), and XLOGShmemSize().

◆ pg_get_shmem_allocations()

Datum pg_get_shmem_allocations ( PG_FUNCTION_ARGS  )

Definition at line 528 of file shmem.c.

529 {
530 #define PG_GET_SHMEM_SIZES_COLS 4
531  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
532  HASH_SEQ_STATUS hstat;
533  ShmemIndexEnt *ent;
534  Size named_allocated = 0;
536  bool nulls[PG_GET_SHMEM_SIZES_COLS];
537 
538  InitMaterializedSRF(fcinfo, 0);
539 
540  LWLockAcquire(ShmemIndexLock, LW_SHARED);
541 
542  hash_seq_init(&hstat, ShmemIndex);
543 
544  /* output all allocated entries */
545  memset(nulls, 0, sizeof(nulls));
546  while ((ent = (ShmemIndexEnt *) hash_seq_search(&hstat)) != NULL)
547  {
548  values[0] = CStringGetTextDatum(ent->key);
549  values[1] = Int64GetDatum((char *) ent->location - (char *) ShmemSegHdr);
550  values[2] = Int64GetDatum(ent->size);
551  values[3] = Int64GetDatum(ent->allocated_size);
552  named_allocated += ent->allocated_size;
553 
554  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
555  values, nulls);
556  }
557 
558  /* output shared memory allocated but not counted via the shmem index */
559  values[0] = CStringGetTextDatum("<anonymous>");
560  nulls[1] = true;
561  values[2] = Int64GetDatum(ShmemSegHdr->freeoffset - named_allocated);
562  values[3] = values[2];
563  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
564 
565  /* output as-of-yet unused shared memory */
566  nulls[0] = true;
568  nulls[1] = false;
570  values[3] = values[2];
571  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
572 
573  LWLockRelease(ShmemIndexLock);
574 
575  return (Datum) 0;
576 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:97
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1431
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1421
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1807
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_SHARED
Definition: lwlock.h:117
uintptr_t Datum
Definition: postgres.h:64
#define PG_GET_SHMEM_SIZES_COLS
Size freeoffset
Definition: pg_shmem.h:35
TupleDesc setDesc
Definition: execnodes.h:340
Tuplestorestate * setResult
Definition: execnodes.h:339
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition: tuplestore.c:750

References CStringGetTextDatum, PGShmemHeader::freeoffset, hash_seq_init(), hash_seq_search(), InitMaterializedSRF(), Int64GetDatum(), LW_SHARED, LWLockAcquire(), LWLockRelease(), PG_GET_SHMEM_SIZES_COLS, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, ShmemIndex, ShmemSegHdr, PGShmemHeader::totalsize, tuplestore_putvalues(), and values.

◆ ShmemAddrIsValid()

bool ShmemAddrIsValid ( const void *  addr)

Definition at line 275 of file shmem.c.

276 {
277  return (addr >= ShmemBase) && (addr < ShmemEnd);
278 }

References ShmemBase, and ShmemEnd.

Referenced by ReleasePredXact(), and ShmemInitStruct().

◆ ShmemAlloc()

void* ShmemAlloc ( Size  size)

Definition at line 153 of file shmem.c.

154 {
155  void *newSpace;
156  Size allocated_size;
157 
158  newSpace = ShmemAllocRaw(size, &allocated_size);
159  if (!newSpace)
160  ereport(ERROR,
161  (errcode(ERRCODE_OUT_OF_MEMORY),
162  errmsg("out of shared memory (%zu bytes requested)",
163  size)));
164  return newSpace;
165 }
static void * ShmemAllocRaw(Size size, Size *allocated_size)
Definition: shmem.c:187

References ereport, errcode(), errmsg(), ERROR, and ShmemAllocRaw().

Referenced by CreateLWLocks(), InitPredicateLocks(), InitProcGlobal(), and ShmemInitStruct().

◆ ShmemAllocNoError()

void* ShmemAllocNoError ( Size  size)

Definition at line 173 of file shmem.c.

174 {
175  Size allocated_size;
176 
177  return ShmemAllocRaw(size, &allocated_size);
178 }

References ShmemAllocRaw().

Referenced by ShmemInitHash().

◆ ShmemAllocRaw()

static void * ShmemAllocRaw ( Size  size,
Size allocated_size 
)
static

Definition at line 187 of file shmem.c.

188 {
189  Size newStart;
190  Size newFree;
191  void *newSpace;
192 
193  /*
194  * Ensure all space is adequately aligned. We used to only MAXALIGN this
195  * space but experience has proved that on modern systems that is not good
196  * enough. Many parts of the system are very sensitive to critical data
197  * structures getting split across cache line boundaries. To avoid that,
198  * attempt to align the beginning of the allocation to a cache line
199  * boundary. The calling code will still need to be careful about how it
200  * uses the allocated space - e.g. by padding each element in an array of
201  * structures out to a power-of-two size - but without this, even that
202  * won't be sufficient.
203  */
204  size = CACHELINEALIGN(size);
205  *allocated_size = size;
206 
207  Assert(ShmemSegHdr != NULL);
208 
210 
211  newStart = ShmemSegHdr->freeoffset;
212 
213  newFree = newStart + size;
214  if (newFree <= ShmemSegHdr->totalsize)
215  {
216  newSpace = (void *) ((char *) ShmemBase + newStart);
217  ShmemSegHdr->freeoffset = newFree;
218  }
219  else
220  newSpace = NULL;
221 
223 
224  /* note this assert is okay with newSpace == NULL */
225  Assert(newSpace == (void *) CACHELINEALIGN(newSpace));
226 
227  return newSpace;
228 }
#define SpinLockRelease(lock)
Definition: spin.h:64
#define SpinLockAcquire(lock)
Definition: spin.h:62

References Assert(), CACHELINEALIGN, PGShmemHeader::freeoffset, ShmemBase, ShmemLock, ShmemSegHdr, SpinLockAcquire, and SpinLockRelease.

Referenced by ShmemAlloc(), ShmemAllocNoError(), and ShmemInitStruct().

◆ ShmemAllocUnlocked()

void* ShmemAllocUnlocked ( Size  size)

Definition at line 239 of file shmem.c.

240 {
241  Size newStart;
242  Size newFree;
243  void *newSpace;
244 
245  /*
246  * Ensure allocated space is adequately aligned.
247  */
248  size = MAXALIGN(size);
249 
250  Assert(ShmemSegHdr != NULL);
251 
252  newStart = ShmemSegHdr->freeoffset;
253 
254  newFree = newStart + size;
255  if (newFree > ShmemSegHdr->totalsize)
256  ereport(ERROR,
257  (errcode(ERRCODE_OUT_OF_MEMORY),
258  errmsg("out of shared memory (%zu bytes requested)",
259  size)));
260  ShmemSegHdr->freeoffset = newFree;
261 
262  newSpace = (void *) ((char *) ShmemBase + newStart);
263 
264  Assert(newSpace == (void *) MAXALIGN(newSpace));
265 
266  return newSpace;
267 }
#define MAXALIGN(LEN)
Definition: c.h:800

References Assert(), ereport, errcode(), errmsg(), ERROR, PGShmemHeader::freeoffset, MAXALIGN, ShmemBase, ShmemSegHdr, and PGShmemHeader::totalsize.

Referenced by InitShmemAllocation(), PGReserveSemaphores(), and SpinlockSemaInit().

◆ ShmemInitHash()

HTAB* ShmemInitHash ( const char *  name,
long  init_size,
long  max_size,
HASHCTL infoP,
int  hash_flags 
)

Definition at line 333 of file shmem.c.

338 {
339  bool found;
340  void *location;
341 
342  /*
343  * Hash tables allocated in shared memory have a fixed directory; it can't
344  * grow or other backends wouldn't be able to find it. So, make sure we
345  * make it big enough to start with.
346  *
347  * The shared memory allocator must be specified too.
348  */
349  infoP->dsize = infoP->max_dsize = hash_select_dirsize(max_size);
350  infoP->alloc = ShmemAllocNoError;
351  hash_flags |= HASH_SHARED_MEM | HASH_ALLOC | HASH_DIRSIZE;
352 
353  /* look it up in the shmem index */
354  location = ShmemInitStruct(name,
355  hash_get_shared_size(infoP, hash_flags),
356  &found);
357 
358  /*
359  * if it already exists, attach to it rather than allocate and initialize
360  * new space
361  */
362  if (found)
363  hash_flags |= HASH_ATTACH;
364 
365  /* Pass location of hashtable header to hash_create */
366  infoP->hctl = (HASHHDR *) location;
367 
368  return hash_create(name, init_size, infoP, hash_flags);
369 }
Size hash_get_shared_size(HASHCTL *info, int flags)
Definition: dynahash.c:852
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:350
long hash_select_dirsize(long num_entries)
Definition: dynahash.c:828
#define HASH_ALLOC
Definition: hsearch.h:101
#define HASH_DIRSIZE
Definition: hsearch.h:94
#define HASH_ATTACH
Definition: hsearch.h:104
#define HASH_SHARED_MEM
Definition: hsearch.h:103
void * ShmemAllocNoError(Size size)
Definition: shmem.c:173
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:388
HashAllocFunc alloc
Definition: hsearch.h:84
long dsize
Definition: hsearch.h:72
HASHHDR * hctl
Definition: hsearch.h:88
long max_dsize
Definition: hsearch.h:73
const char * name

References HASHCTL::alloc, HASHCTL::dsize, HASH_ALLOC, HASH_ATTACH, hash_create(), HASH_DIRSIZE, hash_get_shared_size(), hash_select_dirsize(), HASH_SHARED_MEM, HASHCTL::hctl, HASHCTL::max_dsize, name, ShmemAllocNoError(), and ShmemInitStruct().

Referenced by InitBufTable(), InitLocks(), InitPredicateLocks(), InitShmemIndex(), InjectionPointShmemInit(), pgss_shmem_startup(), and WaitEventExtensionShmemInit().

◆ ShmemInitStruct()

void* ShmemInitStruct ( const char *  name,
Size  size,
bool foundPtr 
)

Definition at line 388 of file shmem.c.

389 {
390  ShmemIndexEnt *result;
391  void *structPtr;
392 
393  LWLockAcquire(ShmemIndexLock, LW_EXCLUSIVE);
394 
395  if (!ShmemIndex)
396  {
397  PGShmemHeader *shmemseghdr = ShmemSegHdr;
398 
399  /* Must be trying to create/attach to ShmemIndex itself */
400  Assert(strcmp(name, "ShmemIndex") == 0);
401 
402  if (IsUnderPostmaster)
403  {
404  /* Must be initializing a (non-standalone) backend */
405  Assert(shmemseghdr->index != NULL);
406  structPtr = shmemseghdr->index;
407  *foundPtr = true;
408  }
409  else
410  {
411  /*
412  * If the shmem index doesn't exist, we are bootstrapping: we must
413  * be trying to init the shmem index itself.
414  *
415  * Notice that the ShmemIndexLock is released before the shmem
416  * index has been initialized. This should be OK because no other
417  * process can be accessing shared memory yet.
418  */
419  Assert(shmemseghdr->index == NULL);
420  structPtr = ShmemAlloc(size);
421  shmemseghdr->index = structPtr;
422  *foundPtr = false;
423  }
424  LWLockRelease(ShmemIndexLock);
425  return structPtr;
426  }
427 
428  /* look it up in the shmem index */
429  result = (ShmemIndexEnt *)
431 
432  if (!result)
433  {
434  LWLockRelease(ShmemIndexLock);
435  ereport(ERROR,
436  (errcode(ERRCODE_OUT_OF_MEMORY),
437  errmsg("could not create ShmemIndex entry for data structure \"%s\"",
438  name)));
439  }
440 
441  if (*foundPtr)
442  {
443  /*
444  * Structure is in the shmem index so someone else has allocated it
445  * already. The size better be the same as the size we are trying to
446  * initialize to, or there is a name conflict (or worse).
447  */
448  if (result->size != size)
449  {
450  LWLockRelease(ShmemIndexLock);
451  ereport(ERROR,
452  (errmsg("ShmemIndex entry size is wrong for data structure"
453  " \"%s\": expected %zu, actual %zu",
454  name, size, result->size)));
455  }
456  structPtr = result->location;
457  }
458  else
459  {
460  Size allocated_size;
461 
462  /* It isn't in the table yet. allocate and initialize it */
463  structPtr = ShmemAllocRaw(size, &allocated_size);
464  if (structPtr == NULL)
465  {
466  /* out of memory; remove the failed ShmemIndex entry */
468  LWLockRelease(ShmemIndexLock);
469  ereport(ERROR,
470  (errcode(ERRCODE_OUT_OF_MEMORY),
471  errmsg("not enough shared memory for data structure"
472  " \"%s\" (%zu bytes requested)",
473  name, size)));
474  }
475  result->size = size;
476  result->allocated_size = allocated_size;
477  result->location = structPtr;
478  }
479 
480  LWLockRelease(ShmemIndexLock);
481 
482  Assert(ShmemAddrIsValid(structPtr));
483 
484  Assert(structPtr == (void *) CACHELINEALIGN(structPtr));
485 
486  return structPtr;
487 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:953
bool IsUnderPostmaster
Definition: globals.c:116
@ HASH_REMOVE
Definition: hsearch.h:115
@ HASH_ENTER_NULL
Definition: hsearch.h:116
@ LW_EXCLUSIVE
Definition: lwlock.h:116
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:275
void * ShmemAlloc(Size size)
Definition: shmem.c:153
void * index
Definition: pg_shmem.h:37
void * location
Definition: shmem.h:54
Size size
Definition: shmem.h:55
Size allocated_size
Definition: shmem.h:56

References ShmemIndexEnt::allocated_size, Assert(), CACHELINEALIGN, ereport, errcode(), errmsg(), ERROR, HASH_ENTER_NULL, HASH_REMOVE, hash_search(), PGShmemHeader::index, IsUnderPostmaster, ShmemIndexEnt::location, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), name, ShmemAddrIsValid(), ShmemAlloc(), ShmemAllocRaw(), ShmemIndex, ShmemSegHdr, and ShmemIndexEnt::size.

Referenced by ApplyLauncherShmemInit(), AsyncShmemInit(), AutoVacuumShmemInit(), BackgroundWorkerShmemInit(), BTreeShmemInit(), CheckpointerShmemInit(), CommitTsShmemInit(), CreateSharedBackendStatus(), CreateSharedInvalidationState(), CreateSharedProcArray(), dsm_shmem_init(), DSMRegistryShmemInit(), InitBufferPool(), InitLocks(), InitPredicateLocks(), InitProcGlobal(), MultiXactShmemInit(), PgArchShmemInit(), pgss_shmem_startup(), PMSignalShmemInit(), ProcSignalShmemInit(), ReplicationOriginShmemInit(), ReplicationSlotsShmemInit(), SerialInit(), ShmemInitHash(), SimpleLruInit(), SlotSyncShmemInit(), StatsShmemInit(), StrategyInitialize(), SyncScanShmemInit(), TwoPhaseShmemInit(), VarsupShmemInit(), WaitEventExtensionShmemInit(), WalRcvShmemInit(), WalSndShmemInit(), WalSummarizerShmemInit(), XLogPrefetchShmemInit(), XLogRecoveryShmemInit(), and XLOGShmemInit().

Variable Documentation

◆ ShmemBase

void* ShmemBase
static

Definition at line 84 of file shmem.c.

Referenced by InitShmemAccess(), ShmemAddrIsValid(), ShmemAllocRaw(), and ShmemAllocUnlocked().

◆ ShmemEnd

void* ShmemEnd
static

Definition at line 86 of file shmem.c.

Referenced by InitShmemAccess(), and ShmemAddrIsValid().

◆ ShmemIndex

HTAB* ShmemIndex = NULL
static

◆ ShmemLock

slock_t* ShmemLock

Definition at line 88 of file shmem.c.

Referenced by InitShmemAllocation(), LWLockNewTrancheId(), and ShmemAllocRaw().

◆ ShmemSegHdr