- Revision
- 191558
- Author
- [email protected]
- Date
- 2015-10-26 00:30:14 -0700 (Mon, 26 Oct 2015)
Log Message
Merge r191196 - bmalloc: per-thread cache data structure should be smaller
https://bugs.webkit.org/show_bug.cgi?id=150218
Reviewed by Andreas Kling.
Reduce the number of entries in the range cache because it's really
big, and the bigness only helps in cases of serious fragmentation, and
it only saves us a little bit of lock acquisition time.
* bmalloc/Allocator.cpp:
(bmalloc::Allocator::scavenge):
(bmalloc::Allocator::refillAllocatorSlowCase):
(bmalloc::Allocator::refillAllocator):
(bmalloc::Allocator::allocateLarge):
(bmalloc::Allocator::allocateSlowCase):
(bmalloc::Allocator::allocateBumpRangeSlowCase): Deleted.
(bmalloc::Allocator::allocateBumpRange): Deleted.
* bmalloc/Allocator.h: Pass through the empty allocator and the range
cache when refilling, and refill both. Otherwise, we always immediately
pop the last item in the range cache, wasting that slot of capacity.
* bmalloc/Heap.cpp:
(bmalloc::Heap::allocateSmallBumpRanges):
(bmalloc::Heap::allocateMediumBumpRanges): Account for the fact that
the range cache is no longer big enough to guarantee that it can hold
all the ranges in a page.
(bmalloc::Heap::refillSmallBumpRangeCache): Deleted.
(bmalloc::Heap::refillMediumBumpRangeCache): Deleted.
* bmalloc/Heap.h: Move VMHeap to the end of the object because it
contains a lot of unused / wasted space, and we want to pack our data
together in memory.
* bmalloc/Sizes.h: Make the range cache smaller.
Modified Paths
Diff
Modified: releases/WebKitGTK/webkit-2.10/Source/bmalloc/ChangeLog (191557 => 191558)
--- releases/WebKitGTK/webkit-2.10/Source/bmalloc/ChangeLog 2015-10-26 07:28:25 UTC (rev 191557)
+++ releases/WebKitGTK/webkit-2.10/Source/bmalloc/ChangeLog 2015-10-26 07:30:14 UTC (rev 191558)
@@ -1,3 +1,41 @@
+2015-10-15 Geoffrey Garen <[email protected]>
+
+ bmalloc: per-thread cache data structure should be smaller
+ https://bugs.webkit.org/show_bug.cgi?id=150218
+
+ Reviewed by Andreas Kling.
+
+ Reduce the number of entries in the range cache because it's really
+ big, and the bigness only helps in cases of serious fragmentation, and
+ it only saves us a little bit of lock acquisition time.
+
+ * bmalloc/Allocator.cpp:
+ (bmalloc::Allocator::scavenge):
+ (bmalloc::Allocator::refillAllocatorSlowCase):
+ (bmalloc::Allocator::refillAllocator):
+ (bmalloc::Allocator::allocateLarge):
+ (bmalloc::Allocator::allocateSlowCase):
+ (bmalloc::Allocator::allocateBumpRangeSlowCase): Deleted.
+ (bmalloc::Allocator::allocateBumpRange): Deleted.
+ * bmalloc/Allocator.h: Pass through the empty allocator and the range
+ cache when refilling, and refill both. Otherwise, we always immediately
+ pop the last item in the range cache, wasting that slot of capacity.
+
+ * bmalloc/Heap.cpp:
+ (bmalloc::Heap::allocateSmallBumpRanges):
+ (bmalloc::Heap::allocateMediumBumpRanges): Account for the fact that
+ the range cache is no longer big enough to guarantee that it can hold
+ all the ranges in a page.
+
+ (bmalloc::Heap::refillSmallBumpRangeCache): Deleted.
+ (bmalloc::Heap::refillMediumBumpRangeCache): Deleted.
+
+ * bmalloc/Heap.h: Move VMHeap to the end of the object because it
+ contains a lot of unused / wasted space, and we want to pack our data
+ together in memory.
+
+ * bmalloc/Sizes.h: Make the range cache smaller.
+
2015-10-13 Chris Dumez <[email protected]>
Avoid useless copies in range-loops that are using 'auto'
Modified: releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Allocator.cpp (191557 => 191558)
--- releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Allocator.cpp 2015-10-26 07:28:25 UTC (rev 191557)
+++ releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Allocator.cpp 2015-10-26 07:30:14 UTC (rev 191558)
@@ -203,25 +203,23 @@
}
}
-NO_INLINE BumpRange Allocator::allocateBumpRangeSlowCase(size_t sizeClass)
+NO_INLINE void Allocator::refillAllocatorSlowCase(BumpAllocator& allocator, size_t sizeClass)
{
BumpRangeCache& bumpRangeCache = m_bumpRangeCaches[sizeClass];
std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
if (sizeClass <= bmalloc::sizeClass(smallMax))
- PerProcess<Heap>::getFastCase()->refillSmallBumpRangeCache(lock, sizeClass, bumpRangeCache);
+ PerProcess<Heap>::getFastCase()->allocateSmallBumpRanges(lock, sizeClass, allocator, bumpRangeCache);
else
- PerProcess<Heap>::getFastCase()->refillMediumBumpRangeCache(lock, sizeClass, bumpRangeCache);
-
- return bumpRangeCache.pop();
+ PerProcess<Heap>::getFastCase()->allocateMediumBumpRanges(lock, sizeClass, allocator, bumpRangeCache);
}
-INLINE BumpRange Allocator::allocateBumpRange(size_t sizeClass)
+INLINE void Allocator::refillAllocator(BumpAllocator& allocator, size_t sizeClass)
{
BumpRangeCache& bumpRangeCache = m_bumpRangeCaches[sizeClass];
if (!bumpRangeCache.size())
- return allocateBumpRangeSlowCase(sizeClass);
- return bumpRangeCache.pop();
+ return refillAllocatorSlowCase(allocator, sizeClass);
+ return allocator.refill(bumpRangeCache.pop());
}
NO_INLINE void* Allocator::allocateLarge(size_t size)
@@ -246,7 +244,7 @@
if (size <= mediumMax) {
size_t sizeClass = bmalloc::sizeClass(size);
BumpAllocator& allocator = m_bumpAllocators[sizeClass];
- allocator.refill(allocateBumpRange(sizeClass));
+ refillAllocator(allocator, sizeClass);
return allocator.allocate();
}
Modified: releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Allocator.h (191557 => 191558)
--- releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Allocator.h 2015-10-26 07:28:25 UTC (rev 191557)
+++ releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Allocator.h 2015-10-26 07:30:14 UTC (rev 191558)
@@ -56,8 +56,8 @@
void* allocateLarge(size_t);
void* allocateXLarge(size_t);
- BumpRange allocateBumpRange(size_t sizeClass);
- BumpRange allocateBumpRangeSlowCase(size_t sizeClass);
+ void refillAllocator(BumpAllocator&, size_t sizeClass);
+ void refillAllocatorSlowCase(BumpAllocator&, size_t sizeClass);
std::array<BumpAllocator, mediumMax / alignment> m_bumpAllocators;
std::array<BumpRangeCache, mediumMax / alignment> m_bumpRangeCaches;
Modified: releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Heap.cpp (191557 => 191558)
--- releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Heap.cpp 2015-10-26 07:28:25 UTC (rev 191557)
+++ releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Heap.cpp 2015-10-26 07:30:14 UTC (rev 191558)
@@ -24,6 +24,7 @@
*/
#include "Heap.h"
+#include "BumpAllocator.h"
#include "LargeChunk.h"
#include "LargeObject.h"
#include "Line.h"
@@ -119,7 +120,7 @@
}
}
-void Heap::refillSmallBumpRangeCache(std::lock_guard<StaticMutex>& lock, size_t sizeClass, BumpRangeCache& rangeCache)
+void Heap::allocateSmallBumpRanges(std::lock_guard<StaticMutex>& lock, size_t sizeClass, BumpAllocator& allocator, BumpRangeCache& rangeCache)
{
BASSERT(!rangeCache.size());
SmallPage* page = allocateSmallPage(lock, sizeClass);
@@ -135,6 +136,12 @@
if (lines[lineNumber].refCount(lock))
continue;
+ // In a fragmented page, some free ranges might not fit in the cache.
+ if (rangeCache.size() == rangeCache.capacity()) {
+ m_smallPagesWithFreeLines[sizeClass].push(page);
+ return;
+ }
+
LineMetadata& lineMetadata = m_smallLineMetadata[sizeClass][lineNumber];
char* begin = lines[lineNumber].begin() + lineMetadata.startOffset;
unsigned short objectCount = lineMetadata.objectCount;
@@ -152,11 +159,14 @@
page->ref(lock);
}
- rangeCache.push({ begin, objectCount });
+ if (!allocator.canAllocate())
+ allocator.refill({ begin, objectCount });
+ else
+ rangeCache.push({ begin, objectCount });
}
}
-void Heap::refillMediumBumpRangeCache(std::lock_guard<StaticMutex>& lock, size_t sizeClass, BumpRangeCache& rangeCache)
+void Heap::allocateMediumBumpRanges(std::lock_guard<StaticMutex>& lock, size_t sizeClass, BumpAllocator& allocator, BumpRangeCache& rangeCache)
{
MediumPage* page = allocateMediumPage(lock, sizeClass);
BASSERT(!rangeCache.size());
@@ -172,6 +182,12 @@
if (lines[lineNumber].refCount(lock))
continue;
+ // In a fragmented page, some free ranges might not fit in the cache.
+ if (rangeCache.size() == rangeCache.capacity()) {
+ m_mediumPagesWithFreeLines[sizeClass].push(page);
+ return;
+ }
+
LineMetadata& lineMetadata = m_mediumLineMetadata[sizeClass][lineNumber];
char* begin = lines[lineNumber].begin() + lineMetadata.startOffset;
unsigned short objectCount = lineMetadata.objectCount;
@@ -189,7 +205,10 @@
page->ref(lock);
}
- rangeCache.push({ begin, objectCount });
+ if (!allocator.canAllocate())
+ allocator.refill({ begin, objectCount });
+ else
+ rangeCache.push({ begin, objectCount });
}
}
Modified: releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Heap.h (191557 => 191558)
--- releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Heap.h 2015-10-26 07:28:25 UTC (rev 191557)
+++ releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Heap.h 2015-10-26 07:30:14 UTC (rev 191558)
@@ -45,6 +45,7 @@
namespace bmalloc {
class BeginTag;
+class BumpAllocator;
class EndTag;
class Heap {
@@ -53,10 +54,10 @@
Environment& environment() { return m_environment; }
- void refillSmallBumpRangeCache(std::lock_guard<StaticMutex>&, size_t sizeClass, BumpRangeCache&);
+ void allocateSmallBumpRanges(std::lock_guard<StaticMutex>&, size_t sizeClass, BumpAllocator&, BumpRangeCache&);
void derefSmallLine(std::lock_guard<StaticMutex>&, SmallLine*);
- void refillMediumBumpRangeCache(std::lock_guard<StaticMutex>&, size_t sizeClass, BumpRangeCache&);
+ void allocateMediumBumpRanges(std::lock_guard<StaticMutex>&, size_t sizeClass, BumpAllocator&, BumpRangeCache&);
void derefMediumLine(std::lock_guard<StaticMutex>&, MediumLine*);
void* allocateLarge(std::lock_guard<StaticMutex>&, size_t);
@@ -108,11 +109,11 @@
Vector<Range> m_xLargeObjects;
bool m_isAllocatingPages;
+ AsyncTask<Heap, decltype(&Heap::concurrentScavenge)> m_scavenger;
Environment m_environment;
VMHeap m_vmHeap;
- AsyncTask<Heap, decltype(&Heap::concurrentScavenge)> m_scavenger;
};
inline void Heap::derefSmallLine(std::lock_guard<StaticMutex>& lock, SmallLine* line)
Modified: releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Sizes.h (191557 => 191558)
--- releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Sizes.h 2015-10-26 07:28:25 UTC (rev 191557)
+++ releases/WebKitGTK/webkit-2.10/Source/bmalloc/bmalloc/Sizes.h 2015-10-26 07:30:14 UTC (rev 191558)
@@ -93,7 +93,7 @@
static const uintptr_t smallOrMediumSmallTypeMask = smallType ^ mediumType; // Only valid if object is known to be small or medium.
static const size_t deallocatorLogCapacity = 256;
- static const size_t bumpRangeCacheCapacity = vmPageSize / smallLineSize / 2;
+ static const size_t bumpRangeCacheCapacity = 3;
static const std::chrono::milliseconds scavengeSleepDuration = std::chrono::milliseconds(512);