pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add GetNamedDSA() and GetNamedDSHash().
Date: Wed, 02 Jul 2025 16:51:36 +0000
Message-ID: <E1uX0gK-004Nrd-1b@gemulon.postgresql.org> (raw)

Add GetNamedDSA() and GetNamedDSHash().

Presently, the dynamic shared memory (DSM) registry only provides
GetNamedDSMSegment(), which allocates a fixed-size segment.  To use
the DSM registry for more sophisticated things like dynamic shared
memory areas (DSAs) or a hash table backed by a DSA (dshash), users
need to create a DSM segment that stores various handles and LWLock
tranche IDs and to write fairly complicated initialization code.
Furthermore, there is likely little variation in this
initialization code between libraries.

This commit introduces functions that simplify allocating a DSA or
dshash within the DSM registry.  These functions are very similar
to GetNamedDSMSegment().  Notable differences include the lack of
an initialization callback parameter and the prohibition of calling
the functions more than once for a given entry in each backend
(which should be trivially avoidable in most circumstances).  While
at it, this commit bumps the maximum DSM registry entry name length
from 63 bytes to 127 bytes.

Also note that even though one could presumably detach/destroy the
DSAs and dshashes created in the registry, such use-cases are not
yet well-supported, if for no other reason than the associated DSM
registry entries cannot be removed.  Adding such support is left as
a future exercise.

The test_dsm_registry test module contains tests for the new
functions and also serves as a complete usage example.

Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Florents Tselai <florents.tselai@gmail.com>
Reviewed-by: Rahila Syed <rahilasyed90@gmail.com>
Discussion: https://postgr.es/m/aEC8HGy2tRQjZg_8%40nathan

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fe07100e82b096d3c848cace790d4b4daf0c4131

Modified Files
--------------
src/backend/storage/ipc/dsm_registry.c             | 265 +++++++++++++++++++--
src/backend/utils/mmgr/dsa.c                       |  15 ++
src/include/storage/dsm_registry.h                 |   7 +-
src/include/utils/dsa.h                            |   1 +
.../expected/test_dsm_registry.out                 |  26 +-
.../test_dsm_registry/sql/test_dsm_registry.sql    |   6 +-
.../test_dsm_registry/test_dsm_registry--1.0.sql   |  10 +-
.../modules/test_dsm_registry/test_dsm_registry.c  | 111 +++++++--
src/tools/pgindent/typedefs.list                   |   5 +
9 files changed, 400 insertions(+), 46 deletions(-)



Message-ID: <E1uX0gK-004Nrd-1b@gemulon.postgresql.org>
Permalink:  ../E1uX0gK-004Nrd-1b@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uX0gK-004Nrd-1b@gemulon.postgresql.org

 · 

reply

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: Add GetNamedDSA() and GetNamedDSHash().
  In-Reply-To: <E1uX0gK-004Nrd-1b@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