[BMalloc] No need to delay deallocating chunks based on recent use
authormsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Mar 2019 17:43:29 +0000 (17:43 +0000)
committermsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Mar 2019 17:43:29 +0000 (17:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196121

Reviewed by Mark Lam.

The "used since last scavenge" logic is not needed for small chunks since their memory isn't decommitted directly.
We can deallocate small chunks immediately as that adds them to the LargeRange free list.  That free list employs the
"used since last scavenge" logic before the scavenger decommits the backing memory.

* bmalloc/Chunk.h:
(bmalloc::Chunk::usedSinceLastScavenge): Deleted.
(bmalloc::Chunk::clearUsedSinceLastScavenge): Deleted.
(bmalloc::Chunk::setUsedSinceLastScavenge): Deleted.
* bmalloc/Heap.cpp:
(bmalloc::Heap::scavenge):
(bmalloc::Heap::allocateSmallPage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243389 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/Chunk.h
Source/bmalloc/bmalloc/Heap.cpp

index 13e0636..f943d84 100644 (file)
@@ -1,3 +1,22 @@
+2019-03-21  Michael Saboff  <msaboff@apple.com>
+
+        [BMalloc] No need to delay deallocating chunks based on recent use
+        https://bugs.webkit.org/show_bug.cgi?id=196121
+
+        Reviewed by Mark Lam.
+
+        The "used since last scavenge" logic is not needed for small chunks since their memory isn't decommitted directly.
+        We can deallocate small chunks immediately as that adds them to the LargeRange free list.  That free list employs the
+        "used since last scavenge" logic before the scavenger decommits the backing memory.
+
+        * bmalloc/Chunk.h:
+        (bmalloc::Chunk::usedSinceLastScavenge): Deleted.
+        (bmalloc::Chunk::clearUsedSinceLastScavenge): Deleted.
+        (bmalloc::Chunk::setUsedSinceLastScavenge): Deleted.
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::scavenge):
+        (bmalloc::Heap::allocateSmallPage):
+
 2019-03-21  Brady Eidson  <beidson@apple.com>
 
         Certain WebProcesses should opt-out of the freezer.
index 17ebeb5..31db6f2 100644 (file)
@@ -45,10 +45,6 @@ public:
     void deref() { BASSERT(m_refCount); --m_refCount; }
     unsigned refCount() { return m_refCount; }
 
-    bool usedSinceLastScavenge() { return m_usedSinceLastScavenge; }
-    void clearUsedSinceLastScavenge() { m_usedSinceLastScavenge = false; }
-    void setUsedSinceLastScavenge() { m_usedSinceLastScavenge = true; }
-
     size_t offset(void*);
 
     char* address(size_t offset);
@@ -63,7 +59,6 @@ public:
 
 private:
     size_t m_refCount { };
-    bool m_usedSinceLastScavenge: 1;
     List<SmallPage> m_freePages { };
 
     std::array<SmallLine, chunkSize / smallLineSize> m_lines { };
index 2686634..faee2d5 100644 (file)
@@ -202,18 +202,8 @@ void Heap::scavenge(std::lock_guard<Mutex>& lock, BulkDecommit& decommitter, siz
     }
 
     for (auto& list : m_chunkCache) {
-        for (auto iter = list.begin(); iter != list.end(); ) {
-            Chunk* chunk = *iter;
-            if (chunk->usedSinceLastScavenge()) {
-                chunk->clearUsedSinceLastScavenge();
-                deferredDecommits++;
-                ++iter;
-                continue;
-            }
-            ++iter;
-            list.remove(chunk);
-            deallocateSmallChunk(chunk, &list - &m_chunkCache[0]);
-        }
+        while (!list.isEmpty())
+            deallocateSmallChunk(list.pop(), &list - &m_chunkCache[0]);
     }
 
     for (LargeRange& range : m_largeFree) {
@@ -316,7 +306,6 @@ SmallPage* Heap::allocateSmallPage(std::unique_lock<Mutex>& lock, size_t sizeCla
         Chunk* chunk = m_freePages[pageClass].tail();
 
         chunk->ref();
-        chunk->setUsedSinceLastScavenge();
 
         SmallPage* page = chunk->freePages().pop();
         if (chunk->freePages().isEmpty())