Re: Better shared data structure management and resizable shared data structures

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, chaturvedipalak1911(at)gmail(dot)com
Subject: Re: Better shared data structure management and resizable shared data structures
Date: 2026-04-04 00:49:25
Message-ID: 470e7ebe-0971-49f6-8e46-9b8f6395f88b@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 02/04/2026 09:58, Ashutosh Bapat wrote:
> On Wed, Apr 1, 2026 at 11:47 PM Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote:
>>> + /*
>>> + * Extra space to reserve in the shared memory segment, but it's not part
>>> + * of the struct itself. This is used for shared memory hash tables that
>>> + * can grow beyond the initial size when more buckets are allocated.
>>> + */
>>> + size_t extra_size;
>>>
>>> When we introduce resizable structures (where even the hash table
>>> directly itself could be resizable), we will introduce a new field
>>> max_size which is easy to get confused with extra_size. Maybe we can
>>> rename extra_size to something like "auxilliary_size" to mean size of
>>> the auxiliary parts of the structure which are not part of the main
>>> struct itself.
>>>
>>> + /*
>>> + * max_size is the estimated maximum number of hashtable entries. This is
>>> + * not a hard limit, but the access efficiency will degrade if it is
>>> + * exceeded substantially (since it's used to compute directory size and
>>> + * the hash table buckets will get overfull).
>>> + */
>>> + size_t max_size;
>>> +
>>> + /*
>>> + * init_size is the number of hashtable entries to preallocate. For a
>>> + * table whose maximum size is certain, this should be equal to max_size;
>>> + * that ensures that no run-time out-of-shared-memory failures can occur.
>>> + */
>>> + size_t init_size;
>>>
>>> Everytime I look at these two fields, I question whether those are the
>>> number of entries (i.e. size of the hash table) or number of bytes
>>> (size of the memory). I know it's the former, but it indicates that
>>> something needs to be changed here, like changing the names to have
>>> _entries instead of _size, or changing the type to int64 or some such.
>>> Renaming to _entries would conflict with dynahash APIs since they use
>>> _size, so maybe the latter?
>>
>> I hear you, but I didn't change these yet. If we go with the patches
>> from the "Shared hash table allocations" thread, max_size and init_size
>> will be merged into one. I'll try to settle that thread before making
>> changes here.
>
> Will review those patches next.

Those are now committed, and here's a new version rebased over those
changes. The hash options is now called 'nelems', and the 'extra_size'
in ShmemStructOpts is gone.

Plus a bunch of other fixes and cleanups. I also reordered and
re-grouped the patches a little, into more logical increments I hope.

- Heikki

Attachment Content-Type Size
0001-refactor-Move-ShmemInitHash-to-separate-file.patch text/x-patch 11.0 KB
0002-Introduce-a-new-mechanism-for-registering-shared-mem.patch text/x-patch 59.1 KB
0003-Add-test-module-to-test-after-startup-shmem-allocati.patch text/x-patch 10.2 KB
0004-Convert-pg_stat_statements-to-use-the-new-interface.patch text/x-patch 11.4 KB
0005-Introduce-registry-of-built-in-subsystems.patch text/x-patch 7.3 KB
0006-Convert-lwlock.c-to-use-the-new-interface.patch text/x-patch 6.5 KB
0007-Use-the-new-mechanism-in-a-few-core-subsystems.patch text/x-patch 47.2 KB
0008-refactor-predicate.c-inline-SerialInit-to-the-caller.patch text/x-patch 3.6 KB
0009-refactor-predicate.c-Move-all-the-initialization-tog.patch text/x-patch 8.3 KB
0010-Convert-SLRUs-to-use-the-new-interface.patch text/x-patch 84.7 KB
0011-Convert-AIO-to-the-new-interface.patch text/x-patch 31.3 KB
0012-Add-option-for-aligning-shmem-allocations.patch text/x-patch 3.9 KB
0013-Convert-buffer-manager-to-the-new-API.patch text/x-patch 16.0 KB
0014-Convert-all-remaining-subsystems-to-use-the-new-API.patch text/x-patch 113.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2026-04-04 01:07:04 Re: pg_waldump: support decoding of WAL inside tarfile
Previous Message Heikki Linnakangas 2026-04-04 00:45:18 Re: Better shared data structure management and resizable shared data structures