Changeset 167570 in webkit
- Timestamp:
- Apr 20, 2014, 12:33:14 PM (12 years ago)
- Location:
- trunk/Source/bmalloc
- Files:
-
- 10 edited
-
ChangeLog (modified) (1 diff)
-
bmalloc/Allocator.cpp (modified) (1 diff)
-
bmalloc/Allocator.h (modified) (3 diffs)
-
bmalloc/Deallocator.cpp (modified) (3 diffs)
-
bmalloc/Deallocator.h (modified) (3 diffs)
-
bmalloc/Heap.cpp (modified) (2 diffs)
-
bmalloc/Heap.h (modified) (6 diffs)
-
bmalloc/Line.h (modified) (1 diff)
-
bmalloc/Page.h (modified) (3 diffs)
-
bmalloc/Sizes.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/bmalloc/ChangeLog
r167554 r167570 1 2014-04-20 Geoffrey Garen <ggaren@apple.com> 2 3 bmalloc: Segregate pages by objects size 4 https://bugs.webkit.org/show_bug.cgi?id=131909 5 6 Reviewed by Andreas Kling. 7 8 2% reduction in memory-at-end on the Membuster memory_warning benchmarks. 9 10 * bmalloc/Allocator.cpp: 11 (bmalloc::Allocator::allocateSlowCase): 12 * bmalloc/Allocator.h: 13 (bmalloc::Allocator::allocateFastCase): 14 (bmalloc::Allocator::smallAllocatorFor): Use the new shared helper 15 function for size class calculation. 16 17 * bmalloc/Deallocator.cpp: 18 (bmalloc::Deallocator::Deallocator): 19 (bmalloc::Deallocator::scavenge): 20 (bmalloc::Deallocator::deallocateSmallLine): 21 (bmalloc::Deallocator::allocateSmallLine): 22 * bmalloc/Deallocator.h: Keep a cache for every size class, since the 23 cache can't be shared anymore. 24 25 * bmalloc/Heap.cpp: 26 (bmalloc::Heap::allocateSmallLineSlowCase): 27 * bmalloc/Heap.h: 28 (bmalloc::Heap::deallocateSmallLine): Ditto. 29 30 (bmalloc::Heap::allocateSmallLine): Check size class in addition to 31 page refcount when allocating a line because we might have deallocated 32 the page and the recycled it for another size class. 33 34 (bmalloc::Heap::deallocateMediumLine): 35 (bmalloc::Heap::allocateMediumLine): 36 * bmalloc/Line.h: 37 (bmalloc::Line::refCount): 38 * bmalloc/Page.h: 39 (bmalloc::Page::refCount): 40 (bmalloc::Page::smallSizeClass): 41 (bmalloc::Page::setSmallSizeClass): 42 (bmalloc::Page<Traits>::refCount): Deleted. 43 * bmalloc/Sizes.h: 44 (bmalloc::Sizes::smallSizeClassFor): New shared API for computing 45 an index into an array from a size. 46 1 47 2014-04-19 Geoffrey Garen <ggaren@apple.com> 2 48 -
trunk/Source/bmalloc/bmalloc/Allocator.cpp
r167546 r167570 146 146 ) 147 147 if (size <= smallMax) { 148 SmallAllocator& allocator = smallAllocatorFor(size); 148 size_t smallSizeClass = smallSizeClassFor(size); 149 SmallAllocator& allocator = m_smallAllocators[smallSizeClass]; 149 150 log(allocator); 150 allocator.refill(m_deallocator.allocateSmallLine( ));151 allocator.refill(m_deallocator.allocateSmallLine(smallSizeClass)); 151 152 return allocator.allocate(); 152 153 } -
trunk/Source/bmalloc/bmalloc/Allocator.h
r167546 r167570 51 51 52 52 private: 53 SmallAllocator& smallAllocatorFor(size_t);54 53 void* allocateFastCase(SmallAllocator&); 55 54 … … 73 72 }; 74 73 75 inline SmallAllocator& Allocator::smallAllocatorFor(size_t size)76 {77 size_t index = mask((size - 1ul) / alignment, m_smallAllocators.size() - 1);78 return m_smallAllocators[index];79 }80 81 74 inline bool Allocator::allocateFastCase(size_t size, void*& object) 82 75 { … … 84 77 return false; 85 78 86 SmallAllocator& allocator = smallAllocatorFor(size);79 SmallAllocator& allocator = m_smallAllocators[smallSizeClassFor(size)]; 87 80 if (!allocator.canAllocate()) 88 81 return false; -
trunk/Source/bmalloc/bmalloc/Deallocator.cpp
r167546 r167570 41 41 Deallocator::Deallocator() 42 42 : m_objectLog() 43 , m_smallLineCache ()43 , m_smallLineCaches() 44 44 , m_mediumLineCache() 45 45 { … … 58 58 Heap* heap = PerProcess<Heap>::getFastCase(); 59 59 60 while (m_smallLineCache.size()) 61 heap->deallocateSmallLine(lock, m_smallLineCache.pop()); 60 for (auto& smallLineCache : m_smallLineCaches) { 61 while (smallLineCache.size()) 62 heap->deallocateSmallLine(lock, smallLineCache.pop()); 63 } 62 64 while (m_mediumLineCache.size()) 63 65 heap->deallocateMediumLine(lock, m_mediumLineCache.pop()); … … 120 122 void Deallocator::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, SmallLine* line) 121 123 { 122 if (m_smallLineCache.size() == m_smallLineCache.capacity()) 124 SmallLineCache& smallLineCache = m_smallLineCaches[SmallPage::get(line)->smallSizeClass()]; 125 if (smallLineCache.size() == smallLineCache.capacity()) 123 126 return PerProcess<Heap>::getFastCase()->deallocateSmallLine(lock, line); 124 127 125 m_smallLineCache.push(line);128 smallLineCache.push(line); 126 129 } 127 130 128 SmallLine* Deallocator::allocateSmallLine( )131 SmallLine* Deallocator::allocateSmallLine(size_t smallSizeClass) 129 132 { 130 if (!m_smallLineCache.size()) { 133 SmallLineCache& smallLineCache = m_smallLineCaches[smallSizeClass]; 134 if (!smallLineCache.size()) { 131 135 std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex()); 132 136 Heap* heap = PerProcess<Heap>::getFastCase(); 133 137 134 while ( m_smallLineCache.size() != m_smallLineCache.capacity())135 m_smallLineCache.push(heap->allocateSmallLine(lock));138 while (smallLineCache.size() != smallLineCache.capacity()) 139 smallLineCache.push(heap->allocateSmallLine(lock, smallSizeClass)); 136 140 } 137 141 138 return m_smallLineCache.pop();142 return smallLineCache.pop(); 139 143 } 140 144 -
trunk/Source/bmalloc/bmalloc/Deallocator.h
r167546 r167570 46 46 47 47 void deallocateSmallLine(std::lock_guard<StaticMutex>&, SmallLine*); 48 SmallLine* allocateSmallLine( );48 SmallLine* allocateSmallLine(size_t smallSizeClass); 49 49 50 50 void deallocateMediumLine(std::lock_guard<StaticMutex>&, MediumLine*); … … 54 54 55 55 private: 56 typedef FixedVector<SmallLine*, smallLineCacheCapacity> SmallLineCache; 57 typedef FixedVector<MediumLine*, mediumLineCacheCapacity> MediumLineCache; 58 56 59 void deallocateLarge(void*); 57 60 void deallocateXLarge(void*); … … 59 62 60 63 FixedVector<void*, deallocatorLogCapacity> m_objectLog; 61 FixedVector<SmallLine*, smallLineCacheCapacity> m_smallLineCache;62 FixedVector<MediumLine*, mediumLineCacheCapacity>m_mediumLineCache;64 std::array<SmallLineCache, smallMax / alignment> m_smallLineCaches; 65 MediumLineCache m_mediumLineCache; 63 66 }; 64 67 -
trunk/Source/bmalloc/bmalloc/Heap.cpp
r167546 r167570 117 117 } 118 118 119 SmallLine* Heap::allocateSmallLineSlowCase(std::lock_guard<StaticMutex>& lock )119 SmallLine* Heap::allocateSmallLineSlowCase(std::lock_guard<StaticMutex>& lock, size_t smallSizeClass) 120 120 { 121 121 m_isAllocatingPages = true; … … 131 131 132 132 SmallLine* line = page->begin(); 133 Vector<SmallLine*>& smallLines = m_smallLines[smallSizeClass]; 133 134 for (auto it = line + 1; it != page->end(); ++it) 134 m_smallLines.push(it); 135 135 smallLines.push(it); 136 137 BASSERT(!line->refCount(lock)); 138 page->setSmallSizeClass(smallSizeClass); 136 139 page->ref(lock); 137 140 return line; -
trunk/Source/bmalloc/bmalloc/Heap.h
r167546 r167570 50 50 Heap(std::lock_guard<StaticMutex>&); 51 51 52 SmallLine* allocateSmallLine(std::lock_guard<StaticMutex>& );52 SmallLine* allocateSmallLine(std::lock_guard<StaticMutex>&, size_t smallSizeClass); 53 53 void deallocateSmallLine(std::lock_guard<StaticMutex>&, SmallLine*); 54 54 … … 67 67 ~Heap() = delete; 68 68 69 SmallLine* allocateSmallLineSlowCase(std::lock_guard<StaticMutex>& );69 SmallLine* allocateSmallLineSlowCase(std::lock_guard<StaticMutex>&, size_t smallSizeClass); 70 70 MediumLine* allocateMediumLineSlowCase(std::lock_guard<StaticMutex>&); 71 71 … … 83 83 void scavengeLargeRanges(std::unique_lock<StaticMutex>&, std::chrono::milliseconds); 84 84 85 Vector<SmallLine*> m_smallLines;85 std::array<Vector<SmallLine*>, smallMax / alignment> m_smallLines; 86 86 Vector<MediumLine*> m_mediumLines; 87 87 … … 99 99 inline void Heap::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, SmallLine* line) 100 100 { 101 BASSERT(!line->refCount(lock)); 101 102 SmallPage* page = SmallPage::get(line); 102 103 if (page->deref(lock)) { … … 105 106 return; 106 107 } 107 m_smallLines .push(line);108 m_smallLines[page->smallSizeClass()].push(line); 108 109 } 109 110 110 inline SmallLine* Heap::allocateSmallLine(std::lock_guard<StaticMutex>& lock )111 inline SmallLine* Heap::allocateSmallLine(std::lock_guard<StaticMutex>& lock, size_t smallSizeClass) 111 112 { 112 while (m_smallLines.size()) { 113 SmallLine* line = m_smallLines.pop(); 113 Vector<SmallLine*>& smallLines = m_smallLines[smallSizeClass]; 114 while (smallLines.size()) { 115 SmallLine* line = smallLines.pop(); 114 116 SmallPage* page = SmallPage::get(line); 115 if (!page->refCount(lock) ) // The line was promoted to the small pages list.117 if (!page->refCount(lock) || page->smallSizeClass() != smallSizeClass) // The line was promoted to the small pages list. 116 118 continue; 119 BASSERT(!line->refCount(lock)); 117 120 page->ref(lock); 118 121 return line; 119 122 } 120 123 121 return allocateSmallLineSlowCase(lock );124 return allocateSmallLineSlowCase(lock, smallSizeClass); 122 125 } 123 126 124 127 inline void Heap::deallocateMediumLine(std::lock_guard<StaticMutex>& lock, MediumLine* line) 125 128 { 129 BASSERT(!line->refCount(lock)); 126 130 MediumPage* page = MediumPage::get(line); 127 131 if (page->deref(lock)) { … … 140 144 if (!page->refCount(lock)) // The line was promoted to the medium pages list. 141 145 continue; 146 BASSERT(!line->refCount(lock)); 142 147 page->ref(lock); 143 148 return line; -
trunk/Source/bmalloc/bmalloc/Line.h
r167546 r167570 48 48 void concurrentRef(unsigned char = 1); 49 49 bool deref(std::lock_guard<StaticMutex>&, unsigned char = 1); 50 unsigned refCount(std::lock_guard<StaticMutex>&) { return m_refCount; } 50 51 51 52 char* begin(); -
trunk/Source/bmalloc/bmalloc/Page.h
r167540 r167570 48 48 void ref(std::lock_guard<StaticMutex>&); 49 49 bool deref(std::lock_guard<StaticMutex>&); 50 unsigned refCount(std::lock_guard<StaticMutex>&); 50 unsigned refCount(std::lock_guard<StaticMutex>&) { return m_refCount; } 51 52 size_t smallSizeClass() { return m_smallSizeClass; } 53 void setSmallSizeClass(size_t smallSizeClass) { m_smallSizeClass = smallSizeClass; } 51 54 52 55 Line* begin(); … … 55 58 private: 56 59 unsigned char m_refCount; 60 unsigned char m_smallSizeClass; 57 61 }; 58 62 … … 70 74 --m_refCount; 71 75 return !m_refCount; 72 }73 74 template<typename Traits>75 inline unsigned Page<Traits>::refCount(std::lock_guard<StaticMutex>&)76 {77 return m_refCount;78 76 } 79 77 -
trunk/Source/bmalloc/bmalloc/Sizes.h
r167546 r167570 90 90 91 91 static const std::chrono::milliseconds scavengeSleepDuration = std::chrono::milliseconds(512); 92 93 inline size_t smallSizeClassFor(size_t size) 94 { 95 static const size_t smallSizeClassMask = (smallMax / alignment) - 1; 96 return mask((size - 1ul) / alignment, smallSizeClassMask); 97 } 92 98 }; 93 99
Note:
See TracChangeset
for help on using the changeset viewer.