Allocate all parts of shmem hash table from a single contiguous area
Heikki Linnakangas <heikki.linnakangas@iki.fi>
Author:
Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2026-04-03T23:40:25Z
Releases:
19 (unreleased)
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
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/storage/ipc/shmem.c | modified | +77 −29 |
| src/backend/utils/hash/dynahash.c | modified | +32 −44 |
| src/include/utils/hsearch.h | modified | +1 −2 |
| src/tools/pgindent/typedefs.list | modified | +1 −0 |
Discussion
- Shared hash table allocations 16 messages · 2026-03-27 → 2026-04-03