From 690904468235f7093214e1323714d14b8a22a6ca Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@vondra.me>
Date: Fri, 27 Jun 2025 16:42:43 +0200
Subject: [PATCH v2 3/3] Add CHECK_FOR_INTERRUPTS into pg_numa_query_pages

Querying the NUMA status can be quite time consuming, especially with
large shared buffers. 8cc139bec34a simply called numa_move_pages(),
which meant we have to wait for the syscall to complete.

But with the chunking, introduced to work around the do_pages_stat()
bug, we can do CHECK_FOR_INTERRUPTS() after each chunk, to allow users
aborting the execution.

Reviewed-by: Christoph Berg <myon@debian.org>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/aEtDozLmtZddARdB@msg.df7cb.de
---
 src/port/pg_numa.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/port/pg_numa.c b/src/port/pg_numa.c
index d5935207d0a..c65f22020ea 100644
--- a/src/port/pg_numa.c
+++ b/src/port/pg_numa.c
@@ -16,6 +16,7 @@
 #include "c.h"
 #include <unistd.h>
 
+#include "miscadmin.h"
 #include "port/pg_numa.h"
 
 /*
@@ -76,6 +77,8 @@ pg_numa_query_pages(int pid, unsigned long count, void **pages, int *status)
 		unsigned long count_chunk = Min(count - next,
 										NUMA_QUERY_CHUNK_SIZE);
 
+		CHECK_FOR_INTERRUPTS();
+
 		/*
 		 * Bail out if any of the chunks errors out (ret<0). We ignore
 		 * (ret>0) which is used to return number of nonmigrated pages,
-- 
2.49.0

