From cb7ead25c29b8897435e466d785ec766adc7afe5 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 14 Apr 2014 03:55:11 +0000 Subject: [Allocator] Switch the BumpPtrAllocator to use a vector of pointers to slabs rather than embedding a singly linked list in the slabs themselves. This has a few advantages: - Better utilization of the slab's memory by not wasting 16-bytes at the front. - Simpler allocation strategy by not having a struct packed at the front. - Avoids paging every allocated slab in just to traverse them for deallocating or dumping stats. The latter is the really nice part. Folks have complained from time to time bitterly that tearing down a BumpPtrAllocator, even if it doesn't run any destructors, pages in all of the memory allocated. Now it won't. =] Also resolves a FIXME with the scaling of the slab sizes. The scaling now disregards specially sized slabs for allocations larger than the threshold. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206147 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Allocator.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'lib/Support/Allocator.cpp') diff --git a/lib/Support/Allocator.cpp b/lib/Support/Allocator.cpp index da1bf3e18c..9d9873981e 100644 --- a/lib/Support/Allocator.cpp +++ b/lib/Support/Allocator.cpp @@ -25,25 +25,16 @@ SlabAllocator::~SlabAllocator() { } MallocSlabAllocator::~MallocSlabAllocator() { } -MemSlab *MallocSlabAllocator::Allocate(size_t Size) { - MemSlab *Slab = (MemSlab*)Allocator.Allocate(Size, 0); - Slab->Size = Size; - Slab->NextPtr = nullptr; - return Slab; +void *MallocSlabAllocator::Allocate(size_t Size) { + return Allocator.Allocate(Size, 0); } -void MallocSlabAllocator::Deallocate(MemSlab *Slab) { +void MallocSlabAllocator::Deallocate(void *Slab, size_t Size) { Allocator.Deallocate(Slab); } -void BumpPtrAllocatorBase::PrintStats() const { - unsigned NumSlabs = 0; - size_t TotalMemory = 0; - for (MemSlab *Slab = CurSlab; Slab; Slab = Slab->NextPtr) { - TotalMemory += Slab->Size; - ++NumSlabs; - } - +void printBumpPtrAllocatorStats(unsigned NumSlabs, size_t BytesAllocated, + size_t TotalMemory) { errs() << "\nNumber of memory regions: " << NumSlabs << '\n' << "Bytes used: " << BytesAllocated << '\n' << "Bytes allocated: " << TotalMemory << '\n' @@ -51,14 +42,6 @@ void BumpPtrAllocatorBase::PrintStats() const { << " (includes alignment, etc)\n"; } -size_t BumpPtrAllocatorBase::getTotalMemory() const { - size_t TotalMemory = 0; - for (MemSlab *Slab = CurSlab; Slab; Slab = Slab->NextPtr) { - TotalMemory += Slab->Size; - } - return TotalMemory; -} - void PrintRecyclerStats(size_t Size, size_t Align, size_t FreeListSize) { -- cgit v1.2.3