[Memory] Add basic support for large/huge memory pages
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>
Thu, 28 Feb 2019 02:47:34 +0000 (02:47 +0000)
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>
Thu, 28 Feb 2019 02:47:34 +0000 (02:47 +0000)
commitb05ba93578dd366f7cd1a5181470566cd523528a
tree9a1ff7aa07b565df260e7a2cfdec0316b21d69f3
parentd4b4e17d2c70c8d498ad33422cf847d659b5b0cf
[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
llvm/include/llvm/Support/Memory.h
llvm/lib/Support/Unix/Memory.inc
llvm/lib/Support/Windows/Memory.inc
llvm/unittests/Support/MemoryTest.cpp