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

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 5 14:45:48 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.
----------------
fmayer wrote:

We don't leak the memory, we DONTNEED it so the kernel releases the actual memory.   We only leak a few pages in the case where other threads touch the pages after we unmapped it. We do leak the mapping, that is correct.

We would need to lock protect all the lock-free operations in order to disable and re-enable and make sure no thread currently has operations in progress.

In the case where we know we are single-threaded, we can unmap the buffers afterwards. This is to support the case where apps want to change the buffer (I forwarded you an email on why they might want that).

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


More information about the llvm-commits mailing list