pgsql: Fix MemoryContextAllocAligned's interaction with Valgrind.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix MemoryContextAllocAligned's interaction with Valgrind.
Date: 2025-08-03 02:00:50
Message-ID: E1uiO1p-000So3-2i@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Discussion: https://postgr.es/m/285483.1746756246@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9e9190154ef204a4e814dcc99f763398f7094667

Modified Files
--------------
src/backend/storage/buffer/localbuf.c | 9 +++---
src/backend/utils/mmgr/alignedalloc.c | 18 ++++++++++++
src/backend/utils/mmgr/mcxt.c | 54 +++++++++++++++++++++--------------
3 files changed, 56 insertions(+), 25 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-08-03 17:01:59 pgsql: Take a little more care in set_backtrace().
Previous Message Fujii Masao 2025-08-03 01:55:01 pgsql: Fix assertion failure in pgbench when handling multiple pipeline