[llvm-branch-commits] [Support] Increase the standard bump allocator slab size (PR #241235)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 11 03:25:46 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Pengcheng Wang (wangpc-pp)

<details>
<summary>Changes</summary>

Increase the standard allocator slab size from 4 KiB to 16 KiB.

This amortizes malloc and free calls across LLVM and Clang arenas.

Capacity-sensitive tests keep using an explicit 4 KiB allocator.

Three interleaved CTMark pairs reduce total compile time by 0.418%.

The workload geomean is reduced by 0.384%.

Assisted-by: TRAE CLI (GPT-6)


---
Full diff: https://github.com/llvm/llvm-project/pull/241235.diff


2 Files Affected:

- (modified) llvm/include/llvm/Support/Allocator.h (+2-3) 
- (modified) llvm/unittests/Support/AllocatorTest.cpp (+10-7) 


``````````diff
diff --git a/llvm/include/llvm/Support/Allocator.h b/llvm/include/llvm/Support/Allocator.h
index 646c814f4e1f7..1ea8df6d30d76 100644
--- a/llvm/include/llvm/Support/Allocator.h
+++ b/llvm/include/llvm/Support/Allocator.h
@@ -386,9 +386,8 @@ class BumpPtrAllocatorImpl
   template <typename T> friend class SpecificBumpPtrAllocator;
 };
 
-/// The standard BumpPtrAllocator which just uses the default template
-/// parameters.
-using BumpPtrAllocator = BumpPtrAllocatorImpl<>;
+/// The standard BumpPtrAllocator uses 16 KiB slabs to amortize allocations.
+using BumpPtrAllocator = BumpPtrAllocatorImpl<MallocAllocator, 16384>;
 
 /// A BumpPtrAllocator that allows only elements of a specific type to be
 /// allocated.
diff --git a/llvm/unittests/Support/AllocatorTest.cpp b/llvm/unittests/Support/AllocatorTest.cpp
index f6682e57fd3d7..aaead986a65b4 100644
--- a/llvm/unittests/Support/AllocatorTest.cpp
+++ b/llvm/unittests/Support/AllocatorTest.cpp
@@ -15,6 +15,8 @@ using namespace llvm;
 
 namespace {
 
+using SmallBumpPtrAllocator = BumpPtrAllocatorImpl<MallocAllocator, 4096>;
+
 TEST(AllocatorTest, Basics) {
   BumpPtrAllocator Alloc;
   int *a = (int*)Alloc.Allocate(sizeof(int), alignof(int));
@@ -29,6 +31,7 @@ TEST(AllocatorTest, Basics) {
   EXPECT_EQ(2, b[9]);
   EXPECT_EQ(3, *c);
   EXPECT_EQ(1U, Alloc.GetNumSlabs());
+  EXPECT_EQ(16384U, Alloc.getTotalMemory());
 
   BumpPtrAllocator Alloc2 = std::move(Alloc);
   EXPECT_EQ(0U, Alloc.GetNumSlabs());
@@ -48,7 +51,7 @@ TEST(AllocatorTest, Basics) {
 
 // Allocate enough bytes to create three slabs.
 TEST(AllocatorTest, ThreeSlabs) {
-  BumpPtrAllocator Alloc;
+  SmallBumpPtrAllocator Alloc;
   Alloc.Allocate(3000, 1);
   EXPECT_EQ(1U, Alloc.GetNumSlabs());
   Alloc.Allocate(3000, 1);
@@ -60,7 +63,7 @@ TEST(AllocatorTest, ThreeSlabs) {
 // Allocate enough bytes to create two slabs, reset the allocator, and do it
 // again.
 TEST(AllocatorTest, TestReset) {
-  BumpPtrAllocator Alloc;
+  SmallBumpPtrAllocator Alloc;
 
   // Allocate something larger than the SizeThreshold=4096.
   (void)Alloc.Allocate(5000, 1);
@@ -156,7 +159,7 @@ TEST(AllocatorTest, TestZero) {
 // Test allocating just over the slab size.  This tests a bug where before the
 // allocator incorrectly calculated the buffer end pointer.
 TEST(AllocatorTest, TestOverflow) {
-  BumpPtrAllocator Alloc;
+  SmallBumpPtrAllocator Alloc;
 
   // Fill the slab right up until the end pointer.
   Alloc.Allocate(4096, 1);
@@ -169,7 +172,7 @@ TEST(AllocatorTest, TestOverflow) {
 
 // Test allocating with a size larger than the initial slab size.
 TEST(AllocatorTest, TestSmallSlabSize) {
-  BumpPtrAllocator Alloc;
+  SmallBumpPtrAllocator Alloc;
 
   Alloc.Allocate(8000, 1);
   EXPECT_EQ(1U, Alloc.GetNumSlabs());
@@ -177,7 +180,7 @@ TEST(AllocatorTest, TestSmallSlabSize) {
 
 // Test requesting alignment that goes past the end of the current slab.
 TEST(AllocatorTest, TestAlignmentPastSlab) {
-  BumpPtrAllocator Alloc;
+  SmallBumpPtrAllocator Alloc;
   Alloc.Allocate(4095, 1);
 
   // Aligning the current slab pointer is likely to move it past the end of the
@@ -237,7 +240,7 @@ TEST(AllocatorTest, TestSlowerSlabGrowthDelay) {
 }
 
 TEST(AllocatorTest, TestIdentifyObject) {
-  BumpPtrAllocator Alloc;
+  SmallBumpPtrAllocator Alloc;
 
   uint64_t *a = (uint64_t *)Alloc.Allocate(sizeof(uint64_t), alignof(uint64_t));
   std::optional<int64_t> maybe_a_belongs = Alloc.identifyObject(a);
@@ -248,7 +251,7 @@ TEST(AllocatorTest, TestIdentifyObject) {
   std::optional<int64_t> maybe_b_belongs = Alloc.identifyObject(b);
   EXPECT_FALSE(maybe_b_belongs);
 
-  // The default slab size is 4096 (or 512 uint64_t values). Custom slabs are
+  // The test slab size is 4096 (or 512 uint64_t values). Custom slabs are
   // allocated when the requested size is larger than the slab size.
   uint64_t *c =
       (uint64_t *)Alloc.Allocate(sizeof(uint64_t) * 1024, alignof(uint64_t));

``````````

</details>


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


More information about the llvm-branch-commits mailing list