pgsql: Handle ENOENT status when querying NUMA node

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Handle ENOENT status when querying NUMA node
Date: 2026-01-26 23:22:31
Message-ID: E1vkVuh-002rCP-0M@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Handle ENOENT status when querying NUMA node

We've assumed that touching the memory is sufficient for a page to be
located on one of the NUMA nodes. But a page may be moved to a swap
after we touch it, due to memory pressure.

We touch the memory before querying the status, but there is no
guarantee it won't be moved to the swap in the meantime. The touching
happens only on the first call, so later calls are more likely to be
affected. And the batching increases the window too.

It's up to the kernel if/when pages get moved to swap. We have to accept
ENOENT (-2) as a valid result, and handle it without failing. This patch
simply treats it as an unknown node, and returns NULL in the two
affected views (pg_shmem_allocations_numa and pg_buffercache_numa).

Hugepages cannot be swapped out, so this affects only regular pages.

Reported by Christoph Berg, investigation and fix by me. Backpatch to
18, where the two views were introduced.

Reported-by: Christoph Berg <myon(at)debian(dot)org>
Discussion: 18
Backpatch-through: https://postgr.es/m/aTq5Gt_n-oS_QSpL@msg.df7cb.de

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9796c4f5607be5807f2d2ba9bca1bc87af198db3

Modified Files
--------------
contrib/pg_buffercache/pg_buffercache_pages.c | 12 ++++++++--
src/backend/storage/ipc/shmem.c | 32 +++++++++++++++++++++------
2 files changed, 35 insertions(+), 9 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2026-01-26 23:29:01 pgsql: pgindent fix for 3fccbd94cba
Previous Message Tomas Vondra 2026-01-26 23:22:18 pgsql: Handle ENOENT status when querying NUMA node