[compiler-rt] [scudo] Allow to resize allocation ring buffer (PR #82683)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 5 14:28:28 PST 2024


================
@@ -1594,12 +1600,33 @@ class Allocator {
     RB->StackDepotSize = StackDepotSize;
     RB->RawStackDepotMap = DepotMap;
 
-    atomic_store(&RingBufferAddress, reinterpret_cast<uptr>(RB),
-                 memory_order_release);
+    swapOutRingBuffer(RB);
     static_assert(sizeof(AllocationRingBuffer) %
                           alignof(typename AllocationRingBuffer::Entry) ==
                       0,
                   "invalid alignment");
+    return true;
+  }
+
+  void swapOutRingBuffer(AllocationRingBuffer *NewRB) {
+    // To allow resizeRingBuffer to be called in a multi-threaded context by apps,
+    // we do not actually unmap, but only madvise(DONTNEED) the pages. That way,
+    // straggler threads will not crash.
----------------
ChiaHungDuan wrote:

This is weird. We are leaking memory because we never unmap the old AllocationRingBuffer (and we just leak the old mapping).

I think the right way to do this is that we need to *disable* the AllocationRingBuffer (Like how we disable the allocator) and do all the transition works (map new buffer, copy the content, .etc)

https://github.com/llvm/llvm-project/pull/82683


More information about the llvm-commits mailing list