From: Heikki Linnakangas Date: Mon, 30 Mar 2026 20:39:35 +0000 (+0300) Subject: Use ShmemInitStruct to allocate shmem for semaphores X-Git-Tag: REL_19_BETA1~589 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40c41dc77306bf6f8f97b0012355c0dd8e11a430;p=thirdparty%2Fpostgresql.git Use ShmemInitStruct to allocate shmem for semaphores This makes them visible in pg_shmem_allocations Reviewed-by: Tomas Vondra Discussion: https://www.postgresql.org/message-id/01ab1d41-3eda-4705-8bbd-af898f5007f1@iki.fi --- diff --git a/src/backend/port/posix_sema.c b/src/backend/port/posix_sema.c index e368e5ee7ed..40205b7d400 100644 --- a/src/backend/port/posix_sema.c +++ b/src/backend/port/posix_sema.c @@ -196,6 +196,7 @@ void PGReserveSemaphores(int maxSemas) { struct stat statbuf; + bool found; /* * We use the data directory's inode number to seed the search for free @@ -216,7 +217,8 @@ PGReserveSemaphores(int maxSemas) #else sharedSemas = (PGSemaphore) - ShmemAlloc(PGSemaphoreShmemSize(maxSemas)); + ShmemInitStruct("Semaphores", PGSemaphoreShmemSize(maxSemas), &found); + Assert(!found); #endif numSems = 0; diff --git a/src/backend/port/sysv_sema.c b/src/backend/port/sysv_sema.c index 86c4d359ef7..4b2bf84072f 100644 --- a/src/backend/port/sysv_sema.c +++ b/src/backend/port/sysv_sema.c @@ -330,6 +330,7 @@ void PGReserveSemaphores(int maxSemas) { struct stat statbuf; + bool found; /* * We use the data directory's inode number to seed the search for free @@ -344,7 +345,9 @@ PGReserveSemaphores(int maxSemas) DataDir))); sharedSemas = (PGSemaphore) - ShmemAlloc(PGSemaphoreShmemSize(maxSemas)); + ShmemInitStruct("Semaphores", PGSemaphoreShmemSize(maxSemas), &found); + Assert(!found); + numSharedSemas = 0; maxSharedSemas = maxSemas;