1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

Silence valgrind about pg_numa_touch_mem_if_required

When querying NUMA status of pages in shared memory, we need to touch
the memory first to get valid results. This may trigger valgrind
reports, because some of the memory (e.g. unpinned buffers) may be
marked as noaccess.

Solved by adding a valgrind suppresion. An alternative would be to
adjust the access/noaccess status before touching the memory, but that
seems far too invasive. It would require all those places to have
detailed knowledge of what the shared memory stores.

The pg_numa_touch_mem_if_required() macro is replaced with a function.
Macros are invisible to suppressions, so it'd have to suppress reports
for the caller - e.g. pg_get_shmem_allocations_numa(). So we'd suppress
reports for the whole function, and that seems to heavy-handed. It might
easily hide other valid issues.

Reviewed-by: Christoph Berg <myon@debian.org>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/aEtDozLmtZddARdB@msg.df7cb.de
Backpatch-through: 18
This commit is contained in:
Tomas Vondra
2025-07-01 12:32:23 +02:00
parent 953050236a
commit 81f287dc92
4 changed files with 23 additions and 8 deletions

View File

@ -320,7 +320,6 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)
uint64 os_page_count; uint64 os_page_count;
int pages_per_buffer; int pages_per_buffer;
int max_entries; int max_entries;
volatile uint64 touch pg_attribute_unused();
char *startptr, char *startptr,
*endptr; *endptr;
@ -375,7 +374,7 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)
/* Only need to touch memory once per backend process lifetime */ /* Only need to touch memory once per backend process lifetime */
if (firstNumaTouch) if (firstNumaTouch)
pg_numa_touch_mem_if_required(touch, ptr); pg_numa_touch_mem_if_required(ptr);
} }
Assert(idx == os_page_count); Assert(idx == os_page_count);

View File

@ -679,12 +679,10 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS)
*/ */
for (i = 0; i < shm_ent_page_count; i++) for (i = 0; i < shm_ent_page_count; i++)
{ {
volatile uint64 touch pg_attribute_unused();
page_ptrs[i] = startptr + (i * os_page_size); page_ptrs[i] = startptr + (i * os_page_size);
if (firstNumaTouch) if (firstNumaTouch)
pg_numa_touch_mem_if_required(touch, page_ptrs[i]); pg_numa_touch_mem_if_required(page_ptrs[i]);
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
} }

View File

@ -24,12 +24,16 @@ extern PGDLLIMPORT int pg_numa_get_max_node(void);
* This is required on Linux, before pg_numa_query_pages() as we * This is required on Linux, before pg_numa_query_pages() as we
* need to page-fault before move_pages(2) syscall returns valid results. * need to page-fault before move_pages(2) syscall returns valid results.
*/ */
#define pg_numa_touch_mem_if_required(ro_volatile_var, ptr) \ static inline void
ro_volatile_var = *(volatile uint64 *) ptr pg_numa_touch_mem_if_required(void *ptr)
{
volatile uint64 touch pg_attribute_unused();
touch = *(volatile uint64 *) ptr;
}
#else #else
#define pg_numa_touch_mem_if_required(ro_volatile_var, ptr) \ #define pg_numa_touch_mem_if_required(ptr) \
do {} while(0) do {} while(0)
#endif #endif

View File

@ -180,3 +180,17 @@
Memcheck:Cond Memcheck:Cond
fun:PyObject_Realloc fun:PyObject_Realloc
} }
# NUMA introspection requires touching memory first, and some of it may
# be marked as noacess (e.g. unpinned buffers). So just ignore that.
{
pg_numa_touch_mem_if_required
Memcheck:Addr4
fun:pg_numa_touch_mem_if_required
}
{
pg_numa_touch_mem_if_required
Memcheck:Addr8
fun:pg_numa_touch_mem_if_required
}