Changeset 180953 in webkit
- Timestamp:
- Mar 3, 2015 1:47:49 PM (9 years ago)
- Location:
- trunk/Source/bmalloc
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/bmalloc/ChangeLog
r180908 r180953 1 2015-03-03 Geoffrey Garen <ggaren@apple.com> 2 3 bmalloc: Miscellaneous cleanup 4 https://bugs.webkit.org/show_bug.cgi?id=142231 5 6 Reviewed by Andreas Kling. 7 8 No performance change -- maybe a tiny reduction in memory use. 9 10 * bmalloc/Heap.cpp: Moved the sleep function into StaticMutex, since 11 it's a helper for working with mutexes. 12 13 (bmalloc::Heap::scavenge): Make sure to wait before we start any 14 scavenging, since individual scavenging functions now always scavenge 15 at least one page before waiting themselves. 16 17 (bmalloc::Heap::scavengeSmallPages): 18 (bmalloc::Heap::scavengeMediumPages): 19 (bmalloc::Heap::scavengeLargeObjects): Use the new wait helper to 20 simplify this code. Also, we now require our caller to wait until at 21 least one deallocation is desirable. This simplifies our loop. 22 23 (bmalloc::Heap::allocateSmallPage): 24 (bmalloc::Heap::allocateMediumPage): 25 (bmalloc::Heap::allocateXLarge): 26 (bmalloc::Heap::allocateLarge): Don't freak out any time the heap does 27 an allocation. Only consider the heap to be growing if it actually needs 28 to allocate new VM. This allows us to shrink the heap back down from a 29 high water mark more reliably even if heap activity continues. 30 31 (bmalloc::sleep): Deleted. 32 (bmalloc::Heap::scavengeLargeRanges): Renamed to match our use of 33 "LargeObject". 34 35 * bmalloc/Heap.h: 36 37 * bmalloc/LargeObject.h: 38 (bmalloc::LargeObject::operator bool): Added to simplify a while loop. 39 40 * bmalloc/StaticMutex.h: 41 (bmalloc::sleep): 42 (bmalloc::waitUntilFalse): New helper for waiting until a condition 43 becomes reliably false. 44 45 * bmalloc/Vector.h: 46 (bmalloc::Vector<T>::~Vector): Oops! Don't deallocate the null pointer. 47 We don't actually run any Vector destructors, but an iteration of this 48 patch did, and then crashed. So, let's fix that. 49 1 50 2015-03-02 Geoffrey Garen <ggaren@apple.com> 2 51 -
trunk/Source/bmalloc/bmalloc/Heap.cpp
r180797 r180953 36 36 namespace bmalloc { 37 37 38 static inline void sleep(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds duration)39 {40 if (duration == std::chrono::milliseconds(0))41 return;42 43 lock.unlock();44 std::this_thread::sleep_for(duration);45 lock.lock();46 }47 48 38 Heap::Heap(std::lock_guard<StaticMutex>&) 49 39 : m_largeObjects(Owner::Heap) … … 94 84 scavenge(lock, scavengeSleepDuration); 95 85 } 96 86 97 87 void Heap::scavenge(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration) 98 88 { 89 waitUntilFalse(lock, sleepDuration, m_isAllocatingPages); 90 99 91 scavengeSmallPages(lock, sleepDuration); 100 92 scavengeMediumPages(lock, sleepDuration); 101 scavengeLarge Ranges(lock, sleepDuration);93 scavengeLargeObjects(lock, sleepDuration); 102 94 103 95 sleep(lock, sleepDuration); … … 106 98 void Heap::scavengeSmallPages(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration) 107 99 { 108 while (1) { 109 if (m_isAllocatingPages) { 110 m_isAllocatingPages = false; 111 112 sleep(lock, sleepDuration); 113 continue; 114 } 115 116 if (!m_smallPages.size()) 117 return; 100 while (m_smallPages.size()) { 118 101 m_vmHeap.deallocateSmallPage(lock, m_smallPages.pop()); 102 waitUntilFalse(lock, sleepDuration, m_isAllocatingPages); 119 103 } 120 104 } … … 122 106 void Heap::scavengeMediumPages(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration) 123 107 { 124 while (1) { 125 if (m_isAllocatingPages) { 126 m_isAllocatingPages = false; 127 128 sleep(lock, sleepDuration); 129 continue; 130 } 131 132 if (!m_mediumPages.size()) 133 return; 108 while (m_mediumPages.size()) { 134 109 m_vmHeap.deallocateMediumPage(lock, m_mediumPages.pop()); 135 } 136 } 137 138 void Heap::scavengeLargeRanges(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration) 139 { 140 while (1) { 141 if (m_isAllocatingPages) { 142 m_isAllocatingPages = false; 143 144 sleep(lock, sleepDuration); 145 continue; 146 } 147 148 LargeObject largeObject = m_largeObjects.takeGreedy(); 149 if (!largeObject) 150 return; 110 waitUntilFalse(lock, sleepDuration, m_isAllocatingPages); 111 } 112 } 113 114 void Heap::scavengeLargeObjects(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration) 115 { 116 while (LargeObject largeObject = m_largeObjects.takeGreedy()) { 151 117 m_vmHeap.deallocateLargeObject(lock, largeObject); 118 waitUntilFalse(lock, sleepDuration, m_isAllocatingPages); 152 119 } 153 120 } … … 236 203 return page; 237 204 } 238 239 m_isAllocatingPages = true;240 205 241 206 SmallPage* page = [this, sizeClass]() { 242 207 if (m_smallPages.size()) 243 208 return m_smallPages.pop(); 209 210 m_isAllocatingPages = true; 244 211 return m_vmHeap.allocateSmallPage(); 245 212 }(); … … 258 225 return page; 259 226 } 260 261 m_isAllocatingPages = true;262 227 263 228 MediumPage* page = [this, sizeClass]() { 264 229 if (m_mediumPages.size()) 265 230 return m_mediumPages.pop(); 231 232 m_isAllocatingPages = true; 266 233 return m_vmHeap.allocateMediumPage(); 267 234 }(); … … 321 288 BASSERT(size == roundUpToMultipleOf<xLargeAlignment>(size)); 322 289 323 m_isAllocatingPages = true;324 325 290 void* result = vmAllocate(alignment, size); 326 291 m_xLargeObjects.push(Range(result, size)); … … 380 345 BASSERT(size == roundUpToMultipleOf<largeAlignment>(size)); 381 346 382 m_isAllocatingPages = true;383 384 347 LargeObject largeObject = m_largeObjects.take(size); 385 if (!largeObject) 348 if (!largeObject) { 349 m_isAllocatingPages = true; 386 350 largeObject = m_vmHeap.allocateLargeObject(size); 351 } 387 352 388 353 return allocateLarge(lock, largeObject, size); … … 401 366 BASSERT(isPowerOfTwo(alignment)); 402 367 403 m_isAllocatingPages = true;404 405 368 LargeObject largeObject = m_largeObjects.take(alignment, size, unalignedSize); 406 if (!largeObject) 369 if (!largeObject) { 370 m_isAllocatingPages = true; 407 371 largeObject = m_vmHeap.allocateLargeObject(alignment, size, unalignedSize); 372 } 408 373 409 374 size_t alignmentMask = alignment - 1; -
trunk/Source/bmalloc/bmalloc/Heap.h
r180797 r180953 93 93 void scavengeSmallPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds); 94 94 void scavengeMediumPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds); 95 void scavengeLarge Ranges(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);95 void scavengeLargeObjects(std::unique_lock<StaticMutex>&, std::chrono::milliseconds); 96 96 97 97 std::array<std::array<LineMetadata, SmallPage::lineCount>, smallMax / alignment> m_smallLineMetadata; -
trunk/Source/bmalloc/bmalloc/LargeObject.h
r180797 r180953 44 44 LargeObject(DoNotValidateTag, void*); 45 45 46 operator bool() { return !!*this; } 46 47 bool operator!() { return !m_object; } 47 48 -
trunk/Source/bmalloc/bmalloc/StaticMutex.h
r177181 r180953 29 29 #include "BAssert.h" 30 30 #include <atomic> 31 #include <mutex> 32 #include <thread> 31 33 32 34 // A fast replacement for std::mutex, for use in static storage. … … 52 54 std::atomic_flag m_flag; 53 55 }; 56 57 static inline void sleep( 58 std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds duration) 59 { 60 if (duration == std::chrono::milliseconds(0)) 61 return; 62 63 lock.unlock(); 64 std::this_thread::sleep_for(duration); 65 lock.lock(); 66 } 67 68 static inline void waitUntilFalse( 69 std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration, 70 bool& condition) 71 { 72 while (condition) { 73 condition = false; 74 sleep(lock, sleepDuration); 75 } 76 } 54 77 55 78 inline void StaticMutex::init() -
trunk/Source/bmalloc/bmalloc/Vector.h
r179923 r180953 89 89 Vector<T>::~Vector() 90 90 { 91 vmDeallocate(m_buffer, vmSize(m_capacity * sizeof(T))); 91 if (m_buffer) 92 vmDeallocate(m_buffer, vmSize(m_capacity * sizeof(T))); 92 93 } 93 94
Note: See TracChangeset
for help on using the changeset viewer.