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 <[email protected]> Discussion: https://www.postgresql.org/message-id/[email protected] 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(-)
