Changeset 241789 in webkit
- Timestamp:
- Feb 19, 2019 5:51:50 PM (5 years ago)
- Location:
- trunk/Source/bmalloc
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/bmalloc/ChangeLog
r241581 r241789 1 2019-02-19 Yusuke Suzuki <ysuzuki@apple.com> 2 3 [bmalloc] bmalloc::Cache should not be instantiated if we are using system malloc 4 https://bugs.webkit.org/show_bug.cgi?id=194811 5 6 Reviewed by Mark Lam. 7 8 bmalloc::Cache is very large. It is 13KB. Since it exists per HeapKind, it takes 40KB. 9 But this is meaningless if we are under the system malloc mode by using "Malloc=1". We 10 found that it continues using so much dirty memory region even under the system malloc mode. 11 This patch avoids instantiation of bmalloc::Cache under the system malloc mode. 12 13 * bmalloc/Allocator.cpp: 14 (bmalloc::Allocator::Allocator): 15 (bmalloc::Allocator::tryAllocate): 16 (bmalloc::Allocator::allocateImpl): 17 (bmalloc::Allocator::reallocateImpl): 18 (bmalloc::Allocator::allocateSlowCase): 19 Allocator is a per Cache object. So we no longer need to keep m_debugHeap. If debug heap is enabled, 20 Allocator is never created. 21 22 * bmalloc/Allocator.h: 23 * bmalloc/Cache.cpp: 24 (bmalloc::debugHeap): 25 (bmalloc::Cache::Cache): 26 (bmalloc::Cache::tryAllocateSlowCaseNullCache): 27 (bmalloc::Cache::allocateSlowCaseNullCache): 28 (bmalloc::Cache::deallocateSlowCaseNullCache): 29 (bmalloc::Cache::tryReallocateSlowCaseNullCache): 30 (bmalloc::Cache::reallocateSlowCaseNullCache): 31 * bmalloc/Cache.h: 32 (bmalloc::Cache::tryAllocate): 33 (bmalloc::Cache::tryReallocate): 34 If the debug heap mode is enabled, we keep Cache::getFast() returning nullptr. And in the slow path case, we use debugHeap. 35 This makes bmalloc fast path fast, while we avoid Cache instantiation. 36 37 * bmalloc/Deallocator.cpp: 38 (bmalloc::Deallocator::Deallocator): 39 (bmalloc::Deallocator::scavenge): 40 (bmalloc::Deallocator::deallocateSlowCase): 41 * bmalloc/Deallocator.h: 42 Ditto for Deallocator. 43 1 44 2019-02-15 Yusuke Suzuki <ysuzuki@apple.com> 2 45 -
trunk/Source/bmalloc/bmalloc/Allocator.cpp
r237577 r241789 28 28 #include "Chunk.h" 29 29 #include "Deallocator.h" 30 #include " DebugHeap.h"30 #include "Environment.h" 31 31 #include "Heap.h" 32 32 #include "PerProcess.h" … … 39 39 Allocator::Allocator(Heap& heap, Deallocator& deallocator) 40 40 : m_heap(heap) 41 , m_debugHeap(heap.debugHeap())42 41 , m_deallocator(deallocator) 43 42 { 43 BASSERT(!PerProcess<Environment>::get()->isDebugHeapEnabled()); 44 44 for (size_t sizeClass = 0; sizeClass < sizeClassCount; ++sizeClass) 45 45 m_bumpAllocators[sizeClass].init(objectSize(sizeClass)); … … 53 53 void* Allocator::tryAllocate(size_t size) 54 54 { 55 if (m_debugHeap)56 return m_debugHeap->malloc(size);57 58 55 if (size <= smallMax) 59 56 return allocate(size); … … 78 75 { 79 76 BASSERT(isPowerOfTwo(alignment)); 80 81 if (m_debugHeap)82 return m_debugHeap->memalign(alignment, size, crashOnFailure);83 77 84 78 if (!size) … … 108 102 void* Allocator::reallocateImpl(void* object, size_t newSize, bool crashOnFailure) 109 103 { 110 if (m_debugHeap)111 return m_debugHeap->realloc(object, newSize, crashOnFailure);112 113 104 size_t oldSize = 0; 114 105 switch (objectType(m_heap.kind(), object)) { … … 201 192 void* Allocator::allocateSlowCase(size_t size) 202 193 { 203 if (m_debugHeap)204 return m_debugHeap->malloc(size);205 206 194 if (size <= maskSizeClassMax) { 207 195 size_t sizeClass = bmalloc::maskSizeClass(size); -
trunk/Source/bmalloc/bmalloc/Allocator.h
r237577 r241789 34 34 35 35 class Deallocator; 36 class DebugHeap;37 36 class Heap; 38 37 … … 70 69 71 70 Heap& m_heap; 72 DebugHeap* m_debugHeap;73 71 Deallocator& m_deallocator; 74 72 }; -
trunk/Source/bmalloc/bmalloc/Cache.cpp
r223239 r241789 26 26 #include "BInline.h" 27 27 #include "Cache.h" 28 #include "DebugHeap.h" 29 #include "Environment.h" 28 30 #include "Heap.h" 29 31 #include "PerProcess.h" 30 32 31 33 namespace bmalloc { 34 35 static DebugHeap* debugHeapCache { nullptr }; 32 36 33 37 void Cache::scavenge(HeapKind heapKind) … … 43 47 } 44 48 49 static BINLINE DebugHeap* debugHeap() 50 { 51 if (debugHeapCache) 52 return debugHeapCache; 53 if (PerProcess<Environment>::get()->isDebugHeapEnabled()) { 54 debugHeapCache = PerProcess<DebugHeap>::get(); 55 return debugHeapCache; 56 } 57 return nullptr; 58 } 59 45 60 Cache::Cache(HeapKind heapKind) 46 61 : m_deallocator(PerProcess<PerHeapKind<Heap>>::get()->at(heapKind)) 47 62 , m_allocator(PerProcess<PerHeapKind<Heap>>::get()->at(heapKind), m_deallocator) 48 63 { 64 BASSERT(!PerProcess<Environment>::get()->isDebugHeapEnabled()); 49 65 } 50 66 51 67 BNO_INLINE void* Cache::tryAllocateSlowCaseNullCache(HeapKind heapKind, size_t size) 52 68 { 69 // FIXME: DebugHeap does not have tryAllocate feature. 70 // https://bugs.webkit.org/show_bug.cgi?id=194837 71 if (auto* heap = debugHeap()) 72 return heap->malloc(size); 53 73 return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryAllocate(size); 54 74 } … … 56 76 BNO_INLINE void* Cache::allocateSlowCaseNullCache(HeapKind heapKind, size_t size) 57 77 { 78 if (auto* heap = debugHeap()) 79 return heap->malloc(size); 58 80 return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().allocate(size); 81 } 82 83 BNO_INLINE void* Cache::tryAllocateSlowCaseNullCache(HeapKind heapKind, size_t alignment, size_t size) 84 { 85 if (auto* heap = debugHeap()) { 86 constexpr bool crashOnFailure = false; 87 return heap->memalign(alignment, size, crashOnFailure); 88 } 89 return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryAllocate(alignment, size); 59 90 } 60 91 61 92 BNO_INLINE void* Cache::allocateSlowCaseNullCache(HeapKind heapKind, size_t alignment, size_t size) 62 93 { 94 if (auto* heap = debugHeap()) { 95 constexpr bool crashOnFailure = true; 96 return heap->memalign(alignment, size, crashOnFailure); 97 } 63 98 return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().allocate(alignment, size); 64 99 } … … 66 101 BNO_INLINE void Cache::deallocateSlowCaseNullCache(HeapKind heapKind, void* object) 67 102 { 103 if (auto* heap = debugHeap()) { 104 heap->free(object); 105 return; 106 } 68 107 PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).deallocator().deallocate(object); 108 } 109 110 BNO_INLINE void* Cache::tryReallocateSlowCaseNullCache(HeapKind heapKind, void* object, size_t newSize) 111 { 112 if (auto* heap = debugHeap()) { 113 constexpr bool crashOnFailure = false; 114 return heap->realloc(object, newSize, crashOnFailure); 115 } 116 return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().tryReallocate(object, newSize); 69 117 } 70 118 71 119 BNO_INLINE void* Cache::reallocateSlowCaseNullCache(HeapKind heapKind, void* object, size_t newSize) 72 120 { 121 if (auto* heap = debugHeap()) { 122 constexpr bool crashOnFailure = true; 123 return heap->realloc(object, newSize, crashOnFailure); 124 } 73 125 return PerThread<PerHeapKind<Cache>>::getSlowCase()->at(mapToActiveHeapKind(heapKind)).allocator().reallocate(object, newSize); 74 126 } -
trunk/Source/bmalloc/bmalloc/Cache.h
r237577 r241789 57 57 BEXPORT static void* tryAllocateSlowCaseNullCache(HeapKind, size_t); 58 58 BEXPORT static void* allocateSlowCaseNullCache(HeapKind, size_t); 59 BEXPORT static void* tryAllocateSlowCaseNullCache(HeapKind, size_t alignment, size_t); 59 60 BEXPORT static void* allocateSlowCaseNullCache(HeapKind, size_t alignment, size_t); 60 61 BEXPORT static void deallocateSlowCaseNullCache(HeapKind, void*); 62 BEXPORT static void* tryReallocateSlowCaseNullCache(HeapKind, void*, size_t); 61 63 BEXPORT static void* reallocateSlowCaseNullCache(HeapKind, void*, size_t); 62 64 … … 85 87 PerHeapKind<Cache>* caches = PerThread<PerHeapKind<Cache>>::getFastCase(); 86 88 if (!caches) 87 return allocateSlowCaseNullCache(heapKind, alignment, size);89 return tryAllocateSlowCaseNullCache(heapKind, alignment, size); 88 90 return caches->at(mapToActiveHeapKindAfterEnsuringGigacage(heapKind)).allocator().tryAllocate(alignment, size); 89 91 } … … 109 111 PerHeapKind<Cache>* caches = PerThread<PerHeapKind<Cache>>::getFastCase(); 110 112 if (!caches) 111 return reallocateSlowCaseNullCache(heapKind, object, newSize);113 return tryReallocateSlowCaseNullCache(heapKind, object, newSize); 112 114 return caches->at(mapToActiveHeapKindAfterEnsuringGigacage(heapKind)).allocator().tryReallocate(object, newSize); 113 115 } -
trunk/Source/bmalloc/bmalloc/Deallocator.cpp
r231403 r241789 28 28 #include "Chunk.h" 29 29 #include "Deallocator.h" 30 #include " DebugHeap.h"30 #include "Environment.h" 31 31 #include "Heap.h" 32 32 #include "Object.h" … … 40 40 Deallocator::Deallocator(Heap& heap) 41 41 : m_heap(heap) 42 , m_debugHeap(heap.debugHeap())43 42 { 44 if (m_debugHeap) { 45 // Fill the object log in order to disable the fast path. 46 while (m_objectLog.size() != m_objectLog.capacity()) 47 m_objectLog.push(nullptr); 48 } 43 BASSERT(!PerProcess<Environment>::get()->isDebugHeapEnabled()); 49 44 } 50 45 … … 56 51 void Deallocator::scavenge() 57 52 { 58 if (m_debugHeap)59 return;60 61 53 std::unique_lock<Mutex> lock(Heap::mutex()); 62 54 … … 74 66 void Deallocator::deallocateSlowCase(void* object) 75 67 { 76 if (m_debugHeap)77 return m_debugHeap->free(object);78 79 68 if (!object) 80 69 return; -
trunk/Source/bmalloc/bmalloc/Deallocator.h
r230501 r241789 34 34 namespace bmalloc { 35 35 36 class DebugHeap;37 36 class Heap; 38 37 class Mutex; … … 59 58 FixedVector<void*, deallocatorLogCapacity> m_objectLog; 60 59 LineCache m_lineCache; // The Heap removes items from this cache. 61 DebugHeap* m_debugHeap;62 60 }; 63 61
Note: See TracChangeset
for help on using the changeset viewer.