Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fdd8937

Browse files
committed
Fix huge_pages on Windows
Since Windows 10 1703, it is additionally necessary to pass a flag called FILE_MAP_LARGE_PAGES to MapViewOfFile() to enable large pages at map time. This flag is ignored on older versions of Windows, where large pages should still be able to work properly without setting it. Note that the flag would be set only for binaries that knew about it at compile-time, which should be more or less all the Windows environments these days. Since 495ed0e, Windows 10 is the minimum version of Windows supported by Postgres, making this change easy to reason about on HEAD. Per discussion, no backpatch is done for the moment. Reported-by: Okano Naoki Author: Thomas Munro Reviewed-by: Tom Lane, Michael Paquier, Julien Rouhaud Discussion: https://postgr.es/m/17448-0a96583a67edb1f7@postgresql.org
1 parent a0b6515 commit fdd8937

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/backend/port/win32_shmem.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ PGSharedMemoryCreate(Size size,
218218
SIZE_T largePageSize = 0;
219219
Size orig_size = size;
220220
DWORD flProtect = PAGE_READWRITE;
221+
DWORD desiredAccess;
221222

222223
ShmemProtectiveRegion = VirtualAlloc(NULL, PROTECTIVE_REGION_SIZE,
223224
MEM_RESERVE, PAGE_NOACCESS);
@@ -355,12 +356,19 @@ PGSharedMemoryCreate(Size size,
355356
if (!CloseHandle(hmap))
356357
elog(LOG, "could not close handle to shared memory: error code %lu", GetLastError());
357358

359+
desiredAccess = FILE_MAP_WRITE | FILE_MAP_READ;
360+
361+
#ifdef FILE_MAP_LARGE_PAGES
362+
/* Set large pages if wanted. */
363+
if ((flProtect & SEC_LARGE_PAGES) != 0)
364+
desiredAccess |= FILE_MAP_LARGE_PAGES;
365+
#endif
358366

359367
/*
360368
* Get a pointer to the new shared memory segment. Map the whole segment
361369
* at once, and let the system decide on the initial address.
362370
*/
363-
memAddress = MapViewOfFileEx(hmap2, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, 0, NULL);
371+
memAddress = MapViewOfFileEx(hmap2, desiredAccess, 0, 0, 0, NULL);
364372
if (!memAddress)
365373
ereport(FATAL,
366374
(errmsg("could not create shared memory segment: error code %lu", GetLastError()),

0 commit comments

Comments
 (0)