Skip to content

Commit 81f287d

Browse files
committed
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
1 parent 9530502 commit 81f287d

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

contrib/pg_buffercache/pg_buffercache_pages.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)
320320
uint64 os_page_count;
321321
int pages_per_buffer;
322322
int max_entries;
323-
volatile uint64 touch pg_attribute_unused();
324323
char *startptr,
325324
*endptr;
326325

@@ -375,7 +374,7 @@ pg_buffercache_numa_pages(PG_FUNCTION_ARGS)
375374

376375
/* Only need to touch memory once per backend process lifetime */
377376
if (firstNumaTouch)
378-
pg_numa_touch_mem_if_required(touch, ptr);
377+
pg_numa_touch_mem_if_required(ptr);
379378
}
380379

381380
Assert(idx == os_page_count);

src/backend/storage/ipc/shmem.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,10 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS)
679679
*/
680680
for (i = 0; i < shm_ent_page_count; i++)
681681
{
682-
volatile uint64 touch pg_attribute_unused();
683-
684682
page_ptrs[i] = startptr + (i * os_page_size);
685683

686684
if (firstNumaTouch)
687-
pg_numa_touch_mem_if_required(touch, page_ptrs[i]);
685+
pg_numa_touch_mem_if_required(page_ptrs[i]);
688686

689687
CHECK_FOR_INTERRUPTS();
690688
}

src/include/port/pg_numa.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ extern PGDLLIMPORT int pg_numa_get_max_node(void);
2424
* This is required on Linux, before pg_numa_query_pages() as we
2525
* need to page-fault before move_pages(2) syscall returns valid results.
2626
*/
27-
#define pg_numa_touch_mem_if_required(ro_volatile_var, ptr) \
28-
ro_volatile_var = *(volatile uint64 *) ptr
27+
static inline void
28+
pg_numa_touch_mem_if_required(void *ptr)
29+
{
30+
volatile uint64 touch pg_attribute_unused();
31+
touch = *(volatile uint64 *) ptr;
32+
}
2933

3034
#else
3135

32-
#define pg_numa_touch_mem_if_required(ro_volatile_var, ptr) \
36+
#define pg_numa_touch_mem_if_required(ptr) \
3337
do {} while(0)
3438

3539
#endif

src/tools/valgrind.supp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,17 @@
180180
Memcheck:Cond
181181
fun:PyObject_Realloc
182182
}
183+
184+
# NUMA introspection requires touching memory first, and some of it may
185+
# be marked as noacess (e.g. unpinned buffers). So just ignore that.
186+
{
187+
pg_numa_touch_mem_if_required
188+
Memcheck:Addr4
189+
fun:pg_numa_touch_mem_if_required
190+
}
191+
192+
{
193+
pg_numa_touch_mem_if_required
194+
Memcheck:Addr8
195+
fun:pg_numa_touch_mem_if_required
196+
}

0 commit comments

Comments
 (0)