From: Heikki Linnakangas Date: Tue, 7 Jul 2026 19:32:36 +0000 (+0300) Subject: Cleanup comments/docs around the new shmem request callbacks X-Git-Tag: REL_19_BETA2~35 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a53d6d8aea8fe703d86dd2bdc0a3d86800eca7c3;p=thirdparty%2Fpostgresql.git Cleanup comments/docs around the new shmem request callbacks Make it explicit in the docs that the shmem initialization callbacks are called while holding ShmemIndexLock. Reviewed-by: Ashutosh Bapat Discussion: https://www.postgresql.org/message-id/CAExHW5sHs+eSiTDOd14buayc6JbBX=Hm5ssFMBK0Ki9sTGEOuA@mail.gmail.com Backpatch-through: 19 --- diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index bae16d7fb53..cb3cc09f16d 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -3739,8 +3739,8 @@ my_shmem_init(void *arg) startup, it will immediately call the appropriate callbacks, depending on whether the requested memory areas were already initialized by another backend. The callbacks will be called while holding an internal - lock, which prevents concurrent two backends from initializing the - memory area concurrently. + lock (ShmemIndexLock), which prevents the race condition of two backends + trying to initializing the memory area at the same time. diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index f1f7cd3a4ff..1fbba9c3a4c 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -918,7 +918,10 @@ CallShmemCallbacksAfterStartup(const ShmemCallbacks *callbacks) return; } - /* Hold ShmemIndexLock while we allocate all the shmem entries */ + /* + * Hold ShmemIndexLock while we allocate all the shmem entries and run all + * the initializers. + */ LWLockAcquire(ShmemIndexLock, LW_EXCLUSIVE); /* @@ -937,7 +940,7 @@ CallShmemCallbacksAfterStartup(const ShmemCallbacks *callbacks) notfound_any = true; } if (found_any && notfound_any) - elog(ERROR, "found some but not all"); + elog(ERROR, "some of the requested shmem areas have already been initialized"); /* * Allocate or attach all the shmem areas requested by the request_fn