[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
This commit is contained in:
Chandler Carruth
2014-04-14 03:55:11 +00:00
parent 1b1e4e27e1
commit cb7ead25c2
4 changed files with 161 additions and 149 deletions

View File

@ -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) {