From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allocate all parts of shmem hash table from a single contiguous
Date: Fri, 03 Apr 2026 23:57:54 +0000
Message-ID: <E1w8oOf-002pS5-19@gemulon.postgresql.org> (raw)
Allocate all parts of shmem hash table from a single contiguous area
Previously, the shared header (HASHHDR) and the directory were
allocated by the caller, and passed to hash_create(), while the actual
elements were allocated separately with ShmemAlloc(). After this
commit, all the memory needed by the header, the directory, and all
the elements is allocated using a single ShmemInitStruct() call, and
the different parts are carved out of that allocation. This way the
ShmemIndex entries (and thus pg_shmem_allocations) reflect the size of
the whole hash table, rather than just the directories.
Commit f5930f9a98 attempted this earlier, but it had to be reverted.
The new strategy is to let dynahash.c perform all the allocations with
the alloc function, but have the alloc function carve out the parts
from the one larger allocation. The shared header and the directory
are now also allocated with alloc calls, instead of passing the area
for those directly from the caller.
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Discussion: https://www.postgresql.org/message-id/01ab1d41-3eda-4705-8bbd-af898f5007f1@iki.fi
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/9fe9ecd516b09434df59d6e7396d508f9c4477c8
Modified Files
--------------
src/backend/storage/ipc/shmem.c | 106 +++++++++++++++++++++++++++-----------
src/backend/utils/hash/dynahash.c | 76 ++++++++++++---------------
src/include/utils/hsearch.h | 3 +-
src/tools/pgindent/typedefs.list | 1 +
4 files changed, 111 insertions(+), 75 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: heikki.linnakangas@iki.fi, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Allocate all parts of shmem hash table from a single contiguous
In-Reply-To: <E1w8oOf-002pS5-19@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