summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>2019-02-28 02:47:34 +0000
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>2019-02-28 02:47:34 +0000
commitb05ba93578dd366f7cd1a5181470566cd523528a (patch)
tree9a1ff7aa07b565df260e7a2cfdec0316b21d69f3 /llvm/unittests
parentd4b4e17d2c70c8d498ad33422cf847d659b5b0cf (diff)
downloadbcm5719-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/unittests')
-rw-r--r--llvm/unittests/Support/MemoryTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/unittests/Support/MemoryTest.cpp b/llvm/unittests/Support/MemoryTest.cpp
index 473a0da97c8..33cc3edb815 100644
--- a/llvm/unittests/Support/MemoryTest.cpp
+++ b/llvm/unittests/Support/MemoryTest.cpp
@@ -105,6 +105,22 @@ TEST_P(MappedMemoryTest, AllocAndRelease) {
EXPECT_FALSE(Memory::releaseMappedMemory(M1));
}
+TEST_P(MappedMemoryTest, AllocAndReleaseHuge) {
+ CHECK_UNSUPPORTED();
+ std::error_code EC;
+ MemoryBlock M1 = Memory::allocateMappedMemory(
+ sizeof(int), nullptr, Flags | Memory::MF_HUGE_HINT, EC);
+ EXPECT_EQ(std::error_code(), EC);
+
+ // Test large/huge memory pages. In the worst case, 4kb pages should be
+ // returned, if large pages aren't available.
+
+ EXPECT_NE((void *)nullptr, M1.base());
+ EXPECT_LE(sizeof(int), M1.size());
+
+ EXPECT_FALSE(Memory::releaseMappedMemory(M1));
+}
+
TEST_P(MappedMemoryTest, MultipleAllocAndRelease) {
CHECK_UNSUPPORTED();
std::error_code EC;
OpenPOWER on IntegriCloud