[llvm-commits] [llvm] r115151 - /llvm/trunk/lib/Support/Allocator.cpp

Chris Lattner clattner at apple.com
Thu Sep 30 09:34:43 PDT 2010


On Sep 30, 2010, at 9:18 AM, Benjamin Kramer wrote:

> Author: d0k
> Date: Thu Sep 30 11:18:28 2010
> New Revision: 115151
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=115151&view=rev
> Log:
> Grow BumpPtrAllocator's slab size dynamically if we allocated many slabs. This
> reduces the amount of malloc calls and may reduce memory overhead.

Wow, awesome!

-Chris

> 
> Some numbers:
> ASTContext stats, clang -cc1 -disable-free -fsyntax-only Cocoa_h.m
> without dynamic growth                          |  with dynamic growth
> Number of memory regions: 3158                  |  Number of memory regions: 432
> Bytes used: 12333185                            |  Bytes used: 12333185
> Bytes allocated: 12935168                       |  Bytes allocated: 12800000
> Bytes wasted: 601983 (includes alignment, etc)  |  Bytes wasted: 466815 (includes alignment, etc)
> 
> ASTContext stats, clang -cc1 -disable-free -fsyntax-only on clang's ASTReader.cpp
> without dynamic growth                          |  with dynamic growth
> Number of memory regions: 10987                 |  Number of memory regions: 551
> Bytes used: 42910356                            |  Bytes used: 42910356
> Bytes allocated: 45002752                       |  Bytes allocated: 44711936
> Bytes wasted: 2092396 (includes alignment, etc) |  Bytes wasted: 1801580 (includes alignment, etc)
> 
> Modified:
>    llvm/trunk/lib/Support/Allocator.cpp
> 
> Modified: llvm/trunk/lib/Support/Allocator.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Allocator.cpp?rev=115151&r1=115150&r2=115151&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Allocator.cpp (original)
> +++ llvm/trunk/lib/Support/Allocator.cpp Thu Sep 30 11:18:28 2010
> @@ -44,6 +44,12 @@
> /// StartNewSlab - Allocate a new slab and move the bump pointers over into
> /// the new slab.  Modifies CurPtr and End.
> void BumpPtrAllocator::StartNewSlab() {
> +  // If we allocated a big number of slabs already it's likely that we're going
> +  // to allocate more. Increase slab size to reduce mallocs and possibly memory
> +  // overhead. The factors are chosen conservatively to avoid overallocation.
> +  if (BytesAllocated >= SlabSize * 128)
> +    SlabSize *= 2;
> +
>   MemSlab *NewSlab = Allocator.Allocate(SlabSize);
>   NewSlab->NextPtr = CurSlab;
>   CurSlab = NewSlab;
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list