Re: Shared hash table allocations
Heikki Linnakangas <hlinnaka@iki.fi>
Attachments
- v2-0001-Use-ShmemInitStruct-to-allocate-shmem-for-semapho.patch (text/x-patch) patch v2-0001
- v2-0002-Remove-HASH_SEGMENT-option.patch (text/x-patch) patch v2-0002
- v2-0003-Change-the-signature-of-dynahash-s-alloc-function.patch (text/x-patch) patch v2-0003
- v2-0004-Merge-init-and-max-size-options-on-shmem-hash-tab.patch (text/x-patch) patch v2-0004
- v2-0005-Prevent-shared-memory-hash-tables-from-growing-be.patch (text/x-patch) patch v2-0005
- v2-0006-Allocate-all-parts-of-shmem-hash-table-from-a-sin.patch (text/x-patch) patch v2-0006
- v2-0007-Remove-HASH_DIRSIZE-always-use-the-default-algori.patch (text/x-patch) patch v2-0007
- v2-0008-Make-ShmemIndex-visible-in-the-pg_shmem_allocatio.patch (text/x-patch) patch v2-0008
On 28/03/2026 02:14, Tomas Vondra wrote: > * 0002 - +1 to getting rid of HASH_SEGMENT, but I don't see the point of > renaming DEF_SEGSIZE to HASH_SEGSIZE. Isn't that a bit unnecessary? DEF_SEGSIZE stands for "default segsize", but after this commit it's not merely the default, it's the same hard-coded constant for every hash table. That's why it seems prudent to rename it. > * 0003 - I'd probably rename CurrentDynaHashCxt to something that > doesn't seem like a "global" variable, e.g. "dynahashCxt" Renamed it to "hcxt", as that's what the corresponding field in HTAB is called. > * 0004 - seems fine, +1 to get rid of unused pieces To be clear, the init_size/max_size are not completely unused at the moment: the lock manager sets max_size to 2 * init_size, and wait_event.c used constants 16 and 128. The point is that it doesn't give you a very wide range of scalability, and I think it's better to not be flexible in that fashion. I would call it sloppiness rather than flexibility. > * 0005 - seems fine > > * 0006 - Doesn't this completely change the alignment? ShmemHashAlloc > used to call ShmemAllocRaw, which is very careful to use CACHELINEALIGN. > But now ShmemHashAlloc just does MAXALIGN, which ShmemAllocRaw claims is > not enough on modern systems. dynahash.c allocates multiple elements in each alloc() call, so even though ShmemAllocRaw() returns a cacheline-aligned block, the individual elements were not cacheline-aligned before this patch either. See element_alloc() and choose_nelem_alloc(). > * 0007 - this left one comment referencing HASH_DIRSIZE in dynahash.c Fixed - Heikki
Commits
-
Remove HASH_DIRSIZE, always use the default algorithm to select it
- 4953a25b7f3b 19 (unreleased) landed
-
Allocate all parts of shmem hash table from a single contiguous area
- 9fe9ecd516b0 19 (unreleased) landed
-
Prevent shared memory hash tables from growing beyond initial size
- 999e9ebb51c9 19 (unreleased) landed
-
Merge init and max size options on shmem hash tables
- 9ebe1c4f2c7c 19 (unreleased) landed
-
Change default of max_locks_per_transactions to 128
- 79534f90657c 19 (unreleased) landed
-
Make the lock hash tables fixed-sized
- e1ad034809a4 19 (unreleased) landed
-
Remove 10% safety margin from lock manager hash table estimates
- 3e854d2ff1a6 19 (unreleased) landed
-
Remove bogus "safety margin" from predicate.c shmem estimates
- feb03dfecdc9 19 (unreleased) landed
-
Make ShmemIndex visible in the pg_shmem_allocations view
- 1bdbb211bbf3 19 (unreleased) landed
-
Change the signature of dynahash's alloc function
- 7b424e3108e4 19 (unreleased) landed
-
Remove HASH_SEGMENT option
- dde69621c324 19 (unreleased) landed
-
Use ShmemInitStruct to allocate shmem for semaphores
- 40c41dc77306 19 (unreleased) landed