diff options
author | Fangrui Song <i@maskray.me> | 2021-12-30 10:42:28 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2021-12-30 10:42:28 -0800 |
commit | 890e8c8f7e9e448a870224068d6b4181d96a293d (patch) | |
tree | f5c4dc2177dbe583576946b58ff5781e31e47757 /llvm/lib/Support/MemoryBuffer.cpp | |
parent | 25ff448aac63339dc71f92d2e89af672ffdd775b (diff) | |
download | llvm-890e8c8f7e9e448a870224068d6b4181d96a293d.zip llvm-890e8c8f7e9e448a870224068d6b4181d96a293d.tar.gz llvm-890e8c8f7e9e448a870224068d6b4181d96a293d.tar.bz2 |
[Support] Add MemoryBuffer::dontNeedIfMmap
On *NIX systems, this API calls madvise(MADV_DONTNEED) on read-only file mappings.
It should not be used on a writable buffer.
The API is used to implement ld.lld LTO memory saving trick (D116367).
Note: on read-only file mappings, Linux's MADV_DONTNEED semantics match POSIX
POSIX_MADV_DONTNEED and BSD systems' MADV_DONTNEED.
On Windows, VirtualAllocEx MEM_COMMIT/MEM_RESET have similar semantics
but are unfortunately not drop-in replacements. dontNeedIfMmap is currently a no-op.
Reviewed By: aganea
Differential Revision: https://reviews.llvm.org/D116366
Diffstat (limited to 'llvm/lib/Support/MemoryBuffer.cpp')
-rw-r--r-- | llvm/lib/Support/MemoryBuffer.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp index d3fa3c6..345b0d4 100644 --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -220,6 +220,8 @@ public: MemoryBuffer::BufferKind getBufferKind() const override { return MemoryBuffer::MemoryBuffer_MMap; } + + void dontNeedIfMmap() override { MFR.dontNeed(); } }; } // namespace |