Title: [252621] trunk/Source/bmalloc
Revision
252621
Author
[email protected]
Date
2019-11-18 19:29:12 -0800 (Mon, 18 Nov 2019)

Log Message

[bmalloc] Some chunks have unused region in the tail of its memory block.
https://bugs.webkit.org/show_bug.cgi?id=204286

Reviewed by Yusuke Suzuki.

When chunk is initialized, some amount of memory are not used and be kept untouched until its end.
This patch tries to decommit those region at the end of initialization.

For instance, think about the case that the pageClass is 5. Then pageSize is 24k. With this pageSize,
a chunk can hold 42 pages and its size is 24k * 42 = 1008k which is smaller than chunkSize = 1024k.
Here is the complete result:

        page    page    page
        class   size    count   remainings
        ----------------------------------
        0       4kB     256     0
        1       8kB     128     0
        2       12kB    85      4kB
        3       16kB    64      0
        4       20kB    51      4kB
        5       24kB    42      16kB
        6       28kB    36      16kB
        7       32kB    32      0
        8       36kB    28      16kB
        9       40kB    25      24kB
        10      44kB    23      12kB
        11      48kB    21      16kB
        12      52kB    19      36kB
        13      56kB    18      16kB
        14      60kB    17      4kB
        15      64kB    16      0

Tested on Mac testmem and result is almost same or in error margin.

        Before:                                 After:
        end score:           8.5425 MB          end score:           8.5127 MB
        peak score:          8.7997 MB          peak score:          8.7884 MB
        total memory score:  8.6702 MB          total memory score:  8.6495 MB
        time score:          668.19 ms          time score:          666.27 ms

* bmalloc/Chunk.h:
(bmalloc::Chunk::metadataSize):
(bmalloc::forEachPage):
* bmalloc/Heap.cpp:
(bmalloc::Heap::allocateSmallChunk):

Modified Paths

Diff

Modified: trunk/Source/bmalloc/ChangeLog (252620 => 252621)


--- trunk/Source/bmalloc/ChangeLog	2019-11-19 03:16:44 UTC (rev 252620)
+++ trunk/Source/bmalloc/ChangeLog	2019-11-19 03:29:12 UTC (rev 252621)
@@ -1,3 +1,51 @@
+2019-11-18  Basuke Suzuki  <[email protected]>
+
+        [bmalloc] Some chunks have unused region in the tail of its memory block.
+        https://bugs.webkit.org/show_bug.cgi?id=204286
+
+        Reviewed by Yusuke Suzuki.
+
+        When chunk is initialized, some amount of memory are not used and be kept untouched until its end.
+        This patch tries to decommit those region at the end of initialization.
+
+        For instance, think about the case that the pageClass is 5. Then pageSize is 24k. With this pageSize,
+        a chunk can hold 42 pages and its size is 24k * 42 = 1008k which is smaller than chunkSize = 1024k.
+        Here is the complete result:
+
+                page    page    page
+                class   size    count   remainings
+                ----------------------------------
+                0       4kB     256     0
+                1       8kB     128     0
+                2       12kB    85      4kB
+                3       16kB    64      0
+                4       20kB    51      4kB
+                5       24kB    42      16kB
+                6       28kB    36      16kB
+                7       32kB    32      0
+                8       36kB    28      16kB
+                9       40kB    25      24kB
+                10      44kB    23      12kB
+                11      48kB    21      16kB
+                12      52kB    19      36kB
+                13      56kB    18      16kB
+                14      60kB    17      4kB
+                15      64kB    16      0
+
+        Tested on Mac testmem and result is almost same or in error margin.
+
+                Before:                                 After:
+                end score:           8.5425 MB          end score:           8.5127 MB
+                peak score:          8.7997 MB          peak score:          8.7884 MB
+                total memory score:  8.6702 MB          total memory score:  8.6495 MB
+                time score:          668.19 ms          time score:          666.27 ms
+
+        * bmalloc/Chunk.h:
+        (bmalloc::Chunk::metadataSize):
+        (bmalloc::forEachPage):
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::allocateSmallChunk):
+
 2019-11-15  Basuke Suzuki  <[email protected]>
 
         [bmalloc] The tracking of freeableMemory of Heap doesn't count Chunk's metadata size.

Modified: trunk/Source/bmalloc/bmalloc/Chunk.h (252620 => 252621)


--- trunk/Source/bmalloc/bmalloc/Chunk.h	2019-11-19 03:16:44 UTC (rev 252620)
+++ trunk/Source/bmalloc/bmalloc/Chunk.h	2019-11-19 03:29:12 UTC (rev 252621)
@@ -38,6 +38,7 @@
 class Chunk : public ListNode<Chunk> {
 public:
     static Chunk* get(void*);
+    static size_t metadataSize(size_t pageSize);
 
     Chunk(size_t pageSize);
     
@@ -73,13 +74,16 @@
     }
 };
 
-template<typename Function> void forEachPage(Chunk* chunk, size_t pageSize, Function function)
+inline size_t Chunk::metadataSize(size_t pageSize)
 {
     // We align to at least the page size so we can service aligned allocations
     // at equal and smaller powers of two, and also so we can vmDeallocatePhysicalPages().
-    size_t metadataSize = roundUpToMultipleOfNonPowerOfTwo(pageSize, sizeof(Chunk));
+    return roundUpToMultipleOfNonPowerOfTwo(pageSize, sizeof(Chunk));
+}
 
-    Object begin(chunk, metadataSize);
+template<typename Function> void forEachPage(Chunk* chunk, size_t pageSize, Function function)
+{
+    Object begin(chunk, Chunk::metadataSize(pageSize));
     Object end(chunk, chunkSize);
 
     for (auto it = begin; it + pageSize <= end; it = it + pageSize)

Modified: trunk/Source/bmalloc/bmalloc/Heap.cpp (252620 => 252621)


--- trunk/Source/bmalloc/bmalloc/Heap.cpp	2019-11-19 03:16:44 UTC (rev 252620)
+++ trunk/Source/bmalloc/bmalloc/Heap.cpp	2019-11-19 03:29:12 UTC (rev 252621)
@@ -286,7 +286,11 @@
         });
 
         m_freeableMemory += accountedInFreeable;
-        
+
+        auto decommitSize = chunkSize - Chunk::metadataSize(pageSize) - accountedInFreeable;
+        if (decommitSize > 0)
+            vmDeallocatePhysicalPagesSloppy(Chunk::get(chunk)->address(chunkSize - decommitSize), decommitSize);
+
         m_scavenger->schedule(0);
 
         return chunk;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to