postgresql/contrib/pg_buffercache
Tomas Vondra 3fccbd94cb 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@debian.org>
Discussion: 18
Backpatch-through: https://postgr.es/m/aTq5Gt_n-oS_QSpL@msg.df7cb.de
2026-01-27 00:21:40 +01:00
..
expected pg_buffercache: Add pg_buffercache_mark_dirty{,_relation,_all}() 2025-11-28 09:04:04 +09:00
sql pg_buffercache: Add pg_buffercache_mark_dirty{,_relation,_all}() 2025-11-28 09:04:04 +09:00
.gitignore Add regression test coverage for contrib/pg_buffercache. 2022-07-30 15:33:44 -04:00
Makefile pg_buffercache: Add pg_buffercache_os_pages 2025-11-24 14:29:15 +09:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_buffercache--1.0--1.1.sql Add pinning_backends column to the pg_buffercache extension. 2014-08-22 00:28:37 +02:00
pg_buffercache--1.1--1.2.sql Update pg_buffercache extension for parallel query. 2016-06-09 17:18:12 -04:00
pg_buffercache--1.2--1.3.sql Default monitoring roles 2017-03-30 14:18:53 -04:00
pg_buffercache--1.2.sql Update pg_buffercache extension for parallel query. 2016-06-09 17:18:12 -04:00
pg_buffercache--1.3--1.4.sql Add pg_buffercache_usage_counts() to contrib/pg_buffercache. 2023-04-07 14:25:53 -04:00
pg_buffercache--1.4--1.5.sql Add pg_buffercache_evict() function for testing. 2024-04-08 16:23:40 +12:00
pg_buffercache--1.5--1.6.sql pg_buffercache: Change page_num type to bigint 2025-04-08 12:38:42 +02:00
pg_buffercache--1.6--1.7.sql pg_buffercache: Add pg_buffercache_mark_dirty{,_relation,_all}() 2025-11-28 09:04:04 +09:00
pg_buffercache.control pg_buffercache: Add pg_buffercache_os_pages 2025-11-24 14:29:15 +09:00
pg_buffercache_pages.c Handle ENOENT status when querying NUMA node 2026-01-27 00:21:40 +01:00