From: Nathan Bossart <nathan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Introduce the dynamic shared memory registry.
Date: Fri, 19 Jan 2024 20:25:27 +0000
Message-ID: <E1rQvQd-002CYZ-2U@gemulon.postgresql.org> (raw)
Introduce the dynamic shared memory registry.
Presently, the most straightforward way for a shared library to use
shared memory is to request it at server startup via a
shmem_request_hook, which requires specifying the library in
shared_preload_libraries. Alternatively, the library can create a
dynamic shared memory (DSM) segment, but absent a shared location
to store the segment's handle, other backends cannot use it. This
commit introduces a registry for DSM segments so that these other
backends can look up existing segments with a library-specified
string. This allows libraries to easily use shared memory without
needing to request it at server startup.
The registry is accessed via the new GetNamedDSMSegment() function.
This function handles allocating the segment and initializing it
via a provided callback. If another backend already created and
initialized the segment, it simply attaches the segment.
GetNamedDSMSegment() locks the registry appropriately to ensure
that only one backend initializes the segment and that all other
backends just attach it.
The registry itself is comprised of a dshash table that stores the
DSM segment handles keyed by a library-specified string.
Reviewed-by: Michael Paquier, Andrei Lepikhov, Nikita Malakhov, Robert Haas, Bharath Rupireddy, Zhang Mingli, Amul Sul
Discussion: https://postgr.es/m/20231205034647.GA2705267%40nathanxps13
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/8b2bcf3f287c79eaebf724cba57e5ff664b01e06
Modified Files
--------------
doc/src/sgml/xfunc.sgml | 49 ++++-
src/backend/storage/ipc/Makefile | 1 +
src/backend/storage/ipc/dsm_registry.c | 198 +++++++++++++++++++++
src/backend/storage/ipc/ipci.c | 3 +
src/backend/storage/ipc/meson.build | 1 +
src/backend/storage/lmgr/lwlock.c | 4 +
src/backend/storage/lmgr/lwlocknames.txt | 1 +
src/backend/utils/activity/wait_event_names.txt | 3 +
src/include/storage/dsm_registry.h | 23 +++
src/include/storage/lwlock.h | 2 +
src/test/modules/Makefile | 1 +
src/test/modules/meson.build | 1 +
src/test/modules/test_dsm_registry/.gitignore | 4 +
src/test/modules/test_dsm_registry/Makefile | 23 +++
.../expected/test_dsm_registry.out | 14 ++
src/test/modules/test_dsm_registry/meson.build | 33 ++++
.../test_dsm_registry/sql/test_dsm_registry.sql | 4 +
.../test_dsm_registry/test_dsm_registry--1.0.sql | 10 ++
.../modules/test_dsm_registry/test_dsm_registry.c | 76 ++++++++
.../test_dsm_registry/test_dsm_registry.control | 4 +
src/tools/pgindent/typedefs.list | 3 +
21 files changed, 455 insertions(+), 3 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: nathan@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Introduce the dynamic shared memory registry.
In-Reply-To: <E1rQvQd-002CYZ-2U@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox