From d209c5ebc6d71bf00835c2e43279466db104fa52 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Fri, 30 Oct 2026 15:50:36 +0530
Subject: [PATCH v20261203 03/10] pg_get_shmem_pagesize() on Windows

pg_get_shmem_pagesize() calls GetHugePageSize() when huge pages are in
use. On Windows, however, GetHugePageSize() is a compatibility stub that
returns zero, so the accessor returns zero rather than the large-page
size.

Use GetLargePageMinimum() instead on Windows when large pages are in
use. Leave ordinary-page handling and the GetHugePageSize() stub
unchanged, preserving existing shared_memory_size_in_huge_pages
reporting.

The only current caller of pg_get_shmem_pagesize() is the NUMA shared
memory reporting function, which rejects unsupported platforms before
calling this accessor. Thus, the faulty path is not currently reached by
that caller on Windows. But this may change in future, hence fixing
proactively. No backporting required since the bug does not impact
anything.

Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: TBD
Discussion: https://postgr.es/m/<message-id-TBD>
---
 src/backend/storage/ipc/shmem.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index 497c0189cf0..88e23e1d03f 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -1392,7 +1392,11 @@ pg_get_shmem_pagesize(void)
 	Assert(huge_pages_status != HUGE_PAGES_UNKNOWN);
 
 	if (huge_pages_status == HUGE_PAGES_ON)
+#ifdef WIN32
+		os_page_size = GetLargePageMinimum();
+#else
 		GetHugePageSize(&os_page_size, NULL);
+#endif
 
 	return os_page_size;
 }
-- 
2.34.1

