Hi Peter,
While reading v4, I noticed a small thing in _mdfd_getseg() and
dsm_impl_mmap(). The new zero buffers there are const locals:
const PGIOAlignedBlock zerobuf = {0};
alignas(MAXIMUM_ALIGNOF) const char zbuffer[ZBUFFER_SIZE] = {0};
So each time that code runs, 8 kB is filled on the stack. With GCC 15,
_mdfd_getseg() copies an 8 kB zero block into a stack frame of about
20 kB, and dsm_impl_mmap() clears 8 kB.
The buffers are never written, so they could be static, as in
pg_pwrite_zeros():
static const PGIOAlignedBlock zbuffer = {0};
Then nothing is copied or cleared, and the stack frame of
_mdfd_getseg() drops to a few hundred bytes. Because the buffers are
read-only, they need no thread_local. So I think the concern upthread
about function-level statics does not apply here.
I tested this on top of v4, with 6-block segments and
dynamic_shared_memory_type = mmap. The regression tests pass. A hash
index spread over 217 segments also works, before and after crash
recovery.
Regards,
Linden
On Wed, Oct 28, 2026 04:11 PM, Rui Zhao <[email protected]> wrote:
> Hi Peter,
>
> Thanks very much for replacing allocations that were only needed for
> alignment. I reviewed v4 and did not find any substantive issues.
>
> I checked the alignment, and it is fine:
> on x86-64 Linux, I get MAXIMUM_ALIGNOF = 8 and alignof(max_align_t) = 16.
> However, alignof(ControlFileData) is also 8,
> so MAXIMUM_ALIGNOF is sufficient for the buffer in pg_resetwal's
> read_controlfile().
>
> The core regression suite and the pg_resetwal and pg_waldump tests passed.
>
> Regards,
> Rui
>
>
>