From baf3e7ed938bed9d16bdaae8ab1e798c7da20a52 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Sat, 26 Mar 2022 22:44:02 +1300 Subject: [PATCH] Fix huge_pages on current Windows. Since Windows 10 1703, it's necessary to pass a flag to MapViewOfFile() to enable large pages at map time. Back-patch to 11 where huge_pages for Windows landed. Reported-by: Okano Naoki Discussion: https://postgr.es/m/17448-0a96583a67edb1f7%40postgresql.org --- src/backend/port/win32_shmem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/port/win32_shmem.c b/src/backend/port/win32_shmem.c index 6cf69411db..1664784891 100644 --- a/src/backend/port/win32_shmem.c +++ b/src/backend/port/win32_shmem.c @@ -216,6 +216,7 @@ PGSharedMemoryCreate(Size size, SIZE_T largePageSize = 0; Size orig_size = size; DWORD flProtect = PAGE_READWRITE; + DWORD desiredAccess; ShmemProtectiveRegion = VirtualAlloc(NULL, PROTECTIVE_REGION_SIZE, MEM_RESERVE, PAGE_NOACCESS); @@ -353,12 +354,17 @@ retry: if (!CloseHandle(hmap)) elog(LOG, "could not close handle to shared memory: error code %lu", GetLastError()); + desiredAccess = FILE_MAP_WRITE | FILE_MAP_READ; +#ifdef FILE_MAP_LARGE_PAGES + if (flProtect & SEC_LARGE_PAGES) + desiredAccess |= FILE_MAP_LARGE_PAGES; +#endif /* * Get a pointer to the new shared memory segment. Map the whole segment * at once, and let the system decide on the initial address. */ - memAddress = MapViewOfFileEx(hmap2, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, 0, NULL); + memAddress = MapViewOfFileEx(hmap2, desiredAccess, 0, 0, 0, NULL); if (!memAddress) ereport(FATAL, (errmsg("could not create shared memory segment: error code %lu", GetLastError()), -- 2.30.2