diff options
| author | Alexandre Ganea <alexandre.ganea@ubisoft.com> | 2019-02-28 02:47:34 +0000 |
|---|---|---|
| committer | Alexandre Ganea <alexandre.ganea@ubisoft.com> | 2019-02-28 02:47:34 +0000 |
| commit | b05ba93578dd366f7cd1a5181470566cd523528a (patch) | |
| tree | 9a1ff7aa07b565df260e7a2cfdec0316b21d69f3 /llvm/lib/Support/Unix | |
| parent | d4b4e17d2c70c8d498ad33422cf847d659b5b0cf (diff) | |
| download | bcm5719-llvm-b05ba93578dd366f7cd1a5181470566cd523528a.tar.gz bcm5719-llvm-b05ba93578dd366f7cd1a5181470566cd523528a.zip | |
[Memory] Add basic support for large/huge memory pages
This patch introduces Memory::MF_HUGE_HINT which indicates that allocateMappedMemory() shall return a pointer to a large memory page.
However the flag is a hint because we're not guaranteed in any way that we will get back a large memory page. There are several restrictions:
- Large/huge memory pages aren't enabled by default on modern OSes (Windows 10 and Linux at least), and should be manually enabled/reserved.
- Once enabled, it should be kept in mind that large pages are physical only, they can't be swapped.
- Memory fragmentation can affect the availability of large pages, especially after running the OS for a long time and/or running along many other applications.
Memory::allocateMappedMemory() will fallback to 4KB pages if it can't allocate 2MB large pages (if Memory::MF_HUGE_HINT is provided)
Currently, Memory::MF_HUGE_HINT only works on Windows. The hint will be ignored on Linux, 4KB pages will always be returned.
Differential Revision: https://reviews.llvm.org/D58718
llvm-svn: 355065
Diffstat (limited to 'llvm/lib/Support/Unix')
| -rw-r--r-- | llvm/lib/Support/Unix/Memory.inc | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc index 3c4d324a8bb..3473b488384 100644 --- a/llvm/lib/Support/Unix/Memory.inc +++ b/llvm/lib/Support/Unix/Memory.inc @@ -45,7 +45,7 @@ extern "C" void __clear_cache(void *, void*); namespace { int getPosixProtectionFlags(unsigned Flags) { - switch (Flags) { + switch (Flags & llvm::sys::Memory::MF_RWE_MASK) { case llvm::sys::Memory::MF_READ: return PROT_READ; case llvm::sys::Memory::MF_WRITE: @@ -114,6 +114,7 @@ Memory::allocateMappedMemory(size_t NumBytes, if (Start && Start % PageSize) Start += PageSize - Start % PageSize; + // FIXME: Handle huge page requests (MF_HUGE_HINT). void *Addr = ::mmap(reinterpret_cast<void *>(Start), NumBytes, Protect, MMFlags, fd, 0); if (Addr == MAP_FAILED) { |

