[compiler-rt] 0f1a92b - [scudo] Deallocate the AllocatorRingBuffer too in unmapTestOnly
Caslyn Tonelli via llvm-commits
llvm-commits at lists.llvm.org
Tue May 16 13:09:50 PDT 2023
Author: Fabio D'Urso
Date: 2023-05-16T20:09:08Z
New Revision: 0f1a92ba308a20dd4c790843191e3b642e90a9f3
URL: https://github.com/llvm/llvm-project/commit/0f1a92ba308a20dd4c790843191e3b642e90a9f3
DIFF: https://github.com/llvm/llvm-project/commit/0f1a92ba308a20dd4c790843191e3b642e90a9f3.diff
LOG: [scudo] Deallocate the AllocatorRingBuffer too in unmapTestOnly
The AllocatorRingBuffer is allocated dynamically when Allocator is
initialized. This patch adds a corresponding deinitialization call in
unmapTestOnly, to avoid running out of virtual memory if the tests are run
a large number of times on memory-constrained platforms.
Reviewed By: Chia-hungDuan
Differential Revision: https://reviews.llvm.org/D149266
Added:
Modified:
compiler-rt/lib/scudo/standalone/combined.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 006605659bfd9..52e2674400fb7 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -178,7 +178,7 @@ class Allocator {
static_cast<uptr>(getFlags()->quarantine_size_kb << 10),
static_cast<uptr>(getFlags()->thread_local_quarantine_size_kb << 10));
- initRingBuffer();
+ mapAndInitializeRingBuffer();
}
// Initialize the embedded GWP-ASan instance. Requires the main allocator to
@@ -228,6 +228,7 @@ class Allocator {
}
void unmapTestOnly() {
+ unmapRingBuffer();
TSDRegistry.unmapTestOnly(this);
Primary.unmapTestOnly();
Secondary.unmapTestOnly();
@@ -1508,17 +1509,16 @@ class Allocator {
&RawRingBuffer[sizeof(AllocationRingBuffer)])[N];
}
- void initRingBuffer() {
+ void mapAndInitializeRingBuffer() {
u32 AllocationRingBufferSize =
static_cast<u32>(getFlags()->allocation_ring_buffer_size);
if (AllocationRingBufferSize < 1)
return;
- MapPlatformData Data = {};
RawRingBuffer = static_cast<char *>(
map(/*Addr=*/nullptr,
roundUp(ringBufferSizeInBytes(AllocationRingBufferSize),
getPageSizeCached()),
- "AllocatorRingBuffer", /*Flags=*/0, &Data));
+ "AllocatorRingBuffer"));
auto *RingBuffer = reinterpret_cast<AllocationRingBuffer *>(RawRingBuffer);
RingBuffer->Size = AllocationRingBufferSize;
static_assert(sizeof(AllocationRingBuffer) %
@@ -1527,6 +1527,11 @@ class Allocator {
"invalid alignment");
}
+ void unmapRingBuffer() {
+ unmap(RawRingBuffer, roundUp(getRingBufferSize(), getPageSizeCached()));
+ RawRingBuffer = nullptr;
+ }
+
static constexpr size_t ringBufferSizeInBytes(u32 AllocationRingBufferSize) {
return sizeof(AllocationRingBuffer) +
AllocationRingBufferSize *
More information about the llvm-commits
mailing list