Fix MemoryContextAllocAligned's interaction with Valgrind.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 2 Aug 2025 22:31:39 +0000 (18:31 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 3 Aug 2025 01:59:46 +0000 (21:59 -0400)
commit9e9190154ef204a4e814dcc99f763398f7094667
treecdaba84f20fb04e0bb67ac56abee2e0a78dc820f
parentbb049a79d3447e97c0d4fa220600c423c4474bf9
Fix MemoryContextAllocAligned's interaction with Valgrind.

Arrange that only the "aligned chunk" part of the allocated space is
included in a Valgrind vchunk.  This suppresses complaints about that
vchunk being possibly lost because PG is retaining only pointers to
the aligned chunk.  Also make sure that trailing wasted space is
marked NOACCESS.

As a tiny performance improvement, arrange that MCXT_ALLOC_ZERO zeroes
only the returned "aligned chunk", not the wasted padding space.

In passing, fix GetLocalBufferStorage to use MemoryContextAllocAligned
instead of rolling its own implementation, which was equally broken
according to Valgrind.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/285483.1746756246@sss.pgh.pa.us
src/backend/storage/buffer/localbuf.c
src/backend/utils/mmgr/alignedalloc.c
src/backend/utils/mmgr/mcxt.c