From a78429202b9ed515a2566170d0a47b816bb3767e Mon Sep 17 00:00:00 2001 From: tevador Date: Mon, 6 May 2019 18:18:52 +0200 Subject: [PATCH] Query for LargePageMinimum on Windows --- src/virtual_memory.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/virtual_memory.cpp b/src/virtual_memory.cpp index f524bef..d958942 100644 --- a/src/virtual_memory.cpp +++ b/src/virtual_memory.cpp @@ -88,7 +88,7 @@ void* allocExecutableMemory(std::size_t bytes) { return mem; } -constexpr std::size_t align(std::size_t pos, uint32_t align) { +constexpr std::size_t align(std::size_t pos, std::size_t align) { return ((pos - 1) / align + 1) * align; } @@ -96,7 +96,11 @@ void* allocLargePagesMemory(std::size_t bytes) { void* mem; #ifdef _WIN32 setPrivilege("SeLockMemoryPrivilege", 1); - mem = VirtualAlloc(NULL, align(bytes, 2 * 1024 * 1024), MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE); + auto pageMinimum = GetLargePageMinimum(); + if (pageMinimum > 0) + mem = VirtualAlloc(NULL, align(bytes, pageMinimum), MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE); + else + throw std::runtime_error("allocLargePagesMemory - Large pages are not supported"); if (mem == nullptr) throw std::runtime_error(getErrorMessage("allocLargePagesMemory - VirtualAlloc")); #else