summaryrefslogtreecommitdiff
path: root/lib/Support/Allocator.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-04-14 03:55:11 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-04-14 03:55:11 +0000
commitcb7ead25c29b8897435e466d785ec766adc7afe5 (patch)
treec0528c73a738197625b0d581c0081f303e474975 /lib/Support/Allocator.cpp
parent1b1e4e27e146ff4969767d32184ebb28b0bb3514 (diff)
downloadllvm-cb7ead25c29b8897435e466d785ec766adc7afe5.tar.gz
llvm-cb7ead25c29b8897435e466d785ec766adc7afe5.tar.bz2
llvm-cb7ead25c29b8897435e466d785ec766adc7afe5.tar.xz
[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
Diffstat (limited to 'lib/Support/Allocator.cpp')
-rw-r--r--lib/Support/Allocator.cpp27
1 files changed, 5 insertions, 22 deletions
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) {