[PATCH] D69050: make BumpPtrAllocator's slab size growth speed configurable

Luboš Luňák via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 09:32:08 PDT 2019


llunak created this revision.
llunak added a reviewer: chandlerc.
llunak added a project: LLVM.
Herald added subscribers: llvm-commits, kristina.

The default of doubling the slab size only each 128 slabs seems very
conservative, at least for some use cases. If the allocator gets
asked for memory totalling 10MiB, it'll allocate 128*4096=0.5MiB
memory before it finally doubles the slab size, then will
allocate 128*8192=1MiB before doubling again, etc. A pathological
case is lldb's ConstString class, which uses a hashmap with 256
allocators, which means that when debugging a huge C++ project
the allocators will do thousands and thousands of small allocations
before they finally find out they need to allocate large amounts
of memory. See https://reviews.llvm.org/D68549 .


Repository:
  rL LLVM

https://reviews.llvm.org/D69050

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===================================================================
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -137,10 +137,10 @@
 /// object, which wraps malloc, to allocate memory, but it can be changed to
 /// use a custom allocator.
 template <typename AllocatorT = MallocAllocator, size_t SlabSize = 4096,
-          size_t SizeThreshold = SlabSize>
+          size_t SizeThreshold = SlabSize, size_t SlabSizeGrowCount = 128>
 class BumpPtrAllocatorImpl
-    : public AllocatorBase<
-          BumpPtrAllocatorImpl<AllocatorT, SlabSize, SizeThreshold>> {
+    : public AllocatorBase<BumpPtrAllocatorImpl<
+          AllocatorT, SlabSize, SizeThreshold, SlabSizeGrowCount>> {
 public:
   static_assert(SizeThreshold <= SlabSize,
                 "The SizeThreshold must be at most the SlabSize to ensure "
@@ -391,10 +391,11 @@
 
   static size_t computeSlabSize(unsigned SlabIdx) {
     // Scale the actual allocated slab size based on the number of slabs
-    // allocated. Every 128 slabs allocated, we double the allocated size to
-    // reduce allocation frequency, but saturate at multiplying the slab size by
-    // 2^30.
-    return SlabSize * ((size_t)1 << std::min<size_t>(30, SlabIdx / 128));
+    // allocated. Every SlabSizeGrowCount slabs allocated, we double the
+    // allocated size to reduce allocation frequency, but saturate at
+    // multiplying the slab size by 2^30.
+    return SlabSize *
+           ((size_t)1 << std::min<size_t>(30, SlabIdx / SlabSizeGrowCount));
   }
 
   /// Allocate a new slab and move the bump pointers over into the new


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69050.225242.patch
Type: text/x-patch
Size: 1667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191016/86544379/attachment.bin>


More information about the llvm-commits mailing list