typedef struct ShmemAllocatorData
{
Size free_offset; /* offset to first free space from ShmemBase */
- HASHHDR *index; /* location of ShmemIndex */
- /* protects shared memory and LWLock allocation */
+ /* protects 'free_offset' */
slock_t shmem_lock;
+
+ HASHHDR *index; /* location of ShmemIndex */
+ LWLock index_lock; /* protects ShmemIndex */
} ShmemAllocatorData;
+#define ShmemIndexLock (&ShmemAllocator->index_lock)
+
static void *ShmemAllocRaw(Size size, Size *allocated_size);
/* shared memory global variables */
/*
* In postmaster or stand-alone backend, initialize the shared memory
- * allocator and the spinlock so that we can allocate shared memory for
- * ShmemIndex using ShmemAlloc(). In a regular backend just set up the
- * pointers required by ShmemAlloc().
+ * allocator so that we can allocate shared memory for ShmemIndex using
+ * ShmemAlloc(). In a regular backend just set up the pointers required
+ * by ShmemAlloc().
*/
ShmemAllocator = (ShmemAllocatorData *) ((char *) seghdr + seghdr->content_offset);
if (!IsUnderPostmaster)
{
SpinLockInit(&ShmemAllocator->shmem_lock);
ShmemAllocator->free_offset = offset;
+ LWLockInitialize(&ShmemAllocator->index_lock, LWTRANCHE_SHMEM_INDEX);
}
ShmemSegHdr = seghdr;
Section: ClassName - WaitEventLWLock
-ShmemIndex "Waiting to find or allocate space in shared memory."
OidGen "Waiting to allocate a new OID."
XidGen "Waiting to allocate a new transaction ID."
ProcArray "Waiting to access the shared per-process data structures (typically, to get a snapshot or report a session's transaction ID)."
XactSLRU "Waiting to access the transaction status SLRU cache."
ParallelVacuumDSA "Waiting for parallel vacuum dynamic shared memory allocation."
AioUringCompletion "Waiting for another process to complete IO via io_uring."
+ShmemIndex "Waiting to find or allocate space in shared memory."
# No "ABI_compatibility" region here as WaitEventLWLock has its own C code.
*/
/* 0 is available; was formerly BufFreelistLock */
-PG_LWLOCK(1, ShmemIndex)
+/* 1 was ShmemIndex */
PG_LWLOCK(2, OidGen)
PG_LWLOCK(3, XidGen)
PG_LWLOCK(4, ProcArray)
PG_LWLOCKTRANCHE(XACT_SLRU, XactSLRU)
PG_LWLOCKTRANCHE(PARALLEL_VACUUM_DSA, ParallelVacuumDSA)
PG_LWLOCKTRANCHE(AIO_URING_COMPLETION, AioUringCompletion)
+PG_LWLOCKTRANCHE(SHMEM_INDEX, ShmemIndex)