PostgreSQL Source Code  git master
shmem.c File Reference
#include "postgres.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 493 of file shmem.c.

494 {
495  Size result;
496 
497  result = s1 + s2;
498  /* We are assuming Size is an unsigned type here... */
499  if (result < s1 || result < s2)
500  ereport(ERROR,
501  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
502  errmsg("requested shared memory size overflows size_t")));
503  return result;
504 }
size_t Size
Definition: c.h:592
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#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(), 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 100 of file shmem.c.

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

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

Referenced by CreateSharedMemoryAndSemaphores().

◆ InitShmemAllocation()

void InitShmemAllocation ( void  )

Definition at line 115 of file shmem.c.

116 {
117  PGShmemHeader *shmhdr = ShmemSegHdr;
118  char *aligned;
119 
120  Assert(shmhdr != NULL);
121 
122  /*
123  * Initialize the spinlock used by ShmemAlloc. We must use
124  * ShmemAllocUnlocked, since obviously ShmemAlloc can't be called yet.
125  */
127 
129 
130  /*
131  * Allocations after this point should go through ShmemAlloc, which
132  * expects to allocate everything on cache line boundaries. Make sure the
133  * first allocation begins on a cache line boundary.
134  */
135  aligned = (char *)
136  (CACHELINEALIGN((((char *) shmhdr) + shmhdr->freeoffset)));
137  shmhdr->freeoffset = aligned - (char *) shmhdr;
138 
139  /* ShmemIndex can't be set up yet (need LWLocks first) */
140  shmhdr->index = NULL;
141  ShmemIndex = (HTAB *) NULL;
142 }
#define CACHELINEALIGN(LEN)
Definition: c.h:801
Assert(fmt[strlen(fmt) - 1] !='\n')
int slock_t
Definition: s_lock.h:735
slock_t * ShmemLock
Definition: shmem.c:87
static HTAB * ShmemIndex
Definition: shmem.c:90
void * ShmemAllocUnlocked(Size size)
Definition: shmem.c:238
#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 283 of file shmem.c.

284 {
285  HASHCTL info;
286 
287  /*
288  * Create the shared memory shmem index.
289  *
290  * Since ShmemInitHash calls ShmemInitStruct, which expects the ShmemIndex
291  * hashtable to exist already, we have a bit of a circularity problem in
292  * initializing the ShmemIndex itself. The special "ShmemIndex" hash
293  * table name will tell ShmemInitStruct to fake it.
294  */
296  info.entrysize = sizeof(ShmemIndexEnt);
297 
298  ShmemIndex = ShmemInitHash("ShmemIndex",
300  &info,
302 }
#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:332
#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 510 of file shmem.c.

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

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 527 of file shmem.c.

528 {
529 #define PG_GET_SHMEM_SIZES_COLS 4
530  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
531  HASH_SEQ_STATUS hstat;
532  ShmemIndexEnt *ent;
533  Size named_allocated = 0;
535  bool nulls[PG_GET_SHMEM_SIZES_COLS];
536 
537  InitMaterializedSRF(fcinfo, 0);
538 
539  LWLockAcquire(ShmemIndexLock, LW_SHARED);
540 
541  hash_seq_init(&hstat, ShmemIndex);
542 
543  /* output all allocated entries */
544  memset(nulls, 0, sizeof(nulls));
545  while ((ent = (ShmemIndexEnt *) hash_seq_search(&hstat)) != NULL)
546  {
547  values[0] = CStringGetTextDatum(ent->key);
548  values[1] = Int64GetDatum((char *) ent->location - (char *) ShmemSegHdr);
549  values[2] = Int64GetDatum(ent->size);
550  values[3] = Int64GetDatum(ent->allocated_size);
551  named_allocated += ent->allocated_size;
552 
553  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
554  values, nulls);
555  }
556 
557  /* output shared memory allocated but not counted via the shmem index */
558  values[0] = CStringGetTextDatum("<anonymous>");
559  nulls[1] = true;
560  values[2] = Int64GetDatum(ShmemSegHdr->freeoffset - named_allocated);
561  values[3] = values[2];
562  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
563 
564  /* output as-of-yet unused shared memory */
565  nulls[0] = true;
567  nulls[1] = false;
569  values[3] = values[2];
570  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
571 
572  LWLockRelease(ShmemIndexLock);
573 
574  return (Datum) 0;
575 }
static Datum values[MAXATTR]
Definition: bootstrap.c:152
#define CStringGetTextDatum(s)
Definition: builtins.h:97
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1395
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1385
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:1172
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1785
@ 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 274 of file shmem.c.

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

References ShmemBase, and ShmemEnd.

Referenced by ReleasePredXact(), and ShmemInitStruct().

◆ ShmemAlloc()

void* ShmemAlloc ( Size  size)

Definition at line 152 of file shmem.c.

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

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

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

◆ ShmemAllocNoError()

void* ShmemAllocNoError ( Size  size)

Definition at line 172 of file shmem.c.

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

References ShmemAllocRaw(), and size.

Referenced by ShmemInitHash().

◆ ShmemAllocRaw()

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

Definition at line 186 of file shmem.c.

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

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

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

◆ ShmemAllocUnlocked()

void* ShmemAllocUnlocked ( Size  size)

Definition at line 238 of file shmem.c.

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

References Assert(), ereport, errcode(), errmsg(), ERROR, PGShmemHeader::freeoffset, MAXALIGN, ShmemBase, ShmemSegHdr, size, 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 332 of file shmem.c.

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

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

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

◆ ShmemEnd

void* ShmemEnd
static

Definition at line 85 of file shmem.c.

Referenced by InitShmemAccess(), and ShmemAddrIsValid().

◆ ShmemIndex

HTAB* ShmemIndex = NULL
static

◆ ShmemLock

slock_t* ShmemLock

Definition at line 87 of file shmem.c.

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

◆ ShmemSegHdr