From 817a64f323b058b0e0079ec2b76178370a24d82c 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 v20261030 1/2] 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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 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 8d81893b470..2d944e21ab8 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -1390,7 +1390,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;
 }

base-commit: 4f89416c9dbc78da5679d32072315af56fbeb8ed
-- 
2.34.1

