1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-18 02:02:55 +03:00

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
This commit is contained in:
Tom Lane
2025-08-02 18:31:39 -04:00
parent bb049a79d3
commit 9e9190154e
3 changed files with 56 additions and 25 deletions

View File

@@ -932,10 +932,11 @@ GetLocalBufferStorage(void)
num_bufs = Min(num_bufs, MaxAllocSize / BLCKSZ);
/* Buffers should be I/O aligned. */
cur_block = (char *)
TYPEALIGN(PG_IO_ALIGN_SIZE,
MemoryContextAlloc(LocalBufferContext,
num_bufs * BLCKSZ + PG_IO_ALIGN_SIZE));
cur_block = MemoryContextAllocAligned(LocalBufferContext,
num_bufs * BLCKSZ,
PG_IO_ALIGN_SIZE,
0);
next_buf_in_block = 0;
num_bufs_in_block = num_bufs;
}