Common/MemArena: Add function for getting page size

This commit is contained in:
JosJuice
2026-02-01 12:39:32 +01:00
parent 6711d77b99
commit 183e12b055
5 changed files with 37 additions and 0 deletions
+5
View File
@@ -115,6 +115,11 @@ public:
///
void UnmapFromMemoryRegion(void* view, size_t size);
///
/// Return the system's page size or required page alignment, whichever is larger.
///
size_t GetPageSize() const;
private:
#ifdef _WIN32
WindowsMemoryRegion* EnsureSplitRegionForMapping(void* address, size_t size);
+5
View File
@@ -144,6 +144,11 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
NOTICE_LOG_FMT(MEMMAP, "mmap failed");
}
size_t MemArena::GetPageSize() const
{
return sysconf(_SC_PAGESIZE);
}
LazyMemoryRegion::LazyMemoryRegion() = default;
LazyMemoryRegion::~LazyMemoryRegion()
+7
View File
@@ -3,6 +3,8 @@
#include "Common/MemArena.h"
#include <unistd.h>
#include "Common/Assert.h"
#include "Common/Logging/Log.h"
@@ -163,6 +165,11 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
}
}
size_t MemArena::GetPageSize() const
{
return getpagesize();
}
LazyMemoryRegion::LazyMemoryRegion() = default;
LazyMemoryRegion::~LazyMemoryRegion()
+5
View File
@@ -108,6 +108,11 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
NOTICE_LOG_FMT(MEMMAP, "mmap failed");
}
size_t MemArena::GetPageSize() const
{
return sysconf(_SC_PAGESIZE);
}
LazyMemoryRegion::LazyMemoryRegion() = default;
LazyMemoryRegion::~LazyMemoryRegion()
+15
View File
@@ -438,6 +438,21 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
UnmapViewOfFile(view);
}
size_t MemArena::GetPageSize() const
{
SYSTEM_INFO si;
GetSystemInfo(&si);
if (!m_memory_functions.m_address_MapViewOfFile3)
{
// In this case, we can only map pages that are 64K aligned.
// See https://devblogs.microsoft.com/oldnewthing/20031008-00/?p=42223
return std::max<size_t>(si.dwPageSize, 64 * 1024);
}
return si.dwPageSize;
}
LazyMemoryRegion::LazyMemoryRegion()
{
InitWindowsMemoryFunctions(&m_memory_functions);