[PATCH] D58718: [Memory] Add basic support for large/huge memory pages

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 27 08:00:18 PST 2019


aganea created this revision.
aganea added reviewers: rnk, zturner, lhames.
Herald added a subscriber: kristina.
Herald added a project: LLVM.

This adds `Memory::MF_HUGE_HINT` which indicates that `allocateMappedMemory()` shall return a pointer to a large memory pages. However the flag is merly 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.

`allocateMappedMemory()` will fallback to 4KB pages if it can't allocate 2MB large pages (when `Memory::MF_HUGE_HINT` is provided)

Currently, this patch implements `Memory::MF_HUGE_HINT` only on Windows. The hint will be ignored on Linux, and 4KB pages will always be returned. Unfortunately I don't have a Linux box at hand, and WSL does not seem to support <https://github.com/Microsoft/WSL/issues/3796> huge pages at the moment.

Also, testing on the build system is a bit tricky. I've added a unit test to exercise the codepath, although I can't ensure the OS will return a large/huge memory page. The test would be too fragile otherwise and could fail occasionally.


Repository:
  rL LLVM

https://reviews.llvm.org/D58718

Files:
  include/llvm/Support/Memory.h
  lib/Support/Windows/Memory.inc
  unittests/Support/MemoryTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58718.188532.patch
Type: text/x-patch
Size: 4423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190227/a72e1b40/attachment.bin>


More information about the llvm-commits mailing list