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

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 10 14:15:30 PDT 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:

Now the allocation ring buffer is allocated lazily. I'm thinking that we may not need to support actual resizing which will be complicated according to the current use cases (for example, the address of StackDepot is escaped. Which means we don't have an easy way to invalidate it)

To achieve the goal which wants to have a different ring buffer size for the different processes, instead of resizing the buffer, we can simply delay the ring buffer initialization. So it will be like,

1. Set the ring buffer size before running actual work load
2. Call malloc_set_track_allocation_stacks(true) to initialize the ring buffer

Then we can have the different ring buffer size across processes and it requires the least effort.


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


More information about the llvm-commits mailing list