bmalloc: extra large allocations could be more efficient
authormsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Dec 2015 21:44:51 +0000 (21:44 +0000)
committermsaboff@apple.com <msaboff@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Dec 2015 21:44:51 +0000 (21:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151817

Reviewed by Geoffrey Garen.

Reduced the super chunk size from 4MB to 2MB.

Added path to reallocate() of an extra large object to see if we can extend the allocation.

* bmalloc/Allocator.cpp:
(bmalloc::Allocator::reallocate):
* bmalloc/SegregatedFreeList.h:
* bmalloc/Sizes.h:
* bmalloc/VMAllocate.h:
(bmalloc::tryVMAllocate):
(bmalloc::tryVMExtend):
(bmalloc::vmAllocate):

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

Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc/Allocator.cpp
Source/bmalloc/bmalloc/SegregatedFreeList.h
Source/bmalloc/bmalloc/Sizes.h
Source/bmalloc/bmalloc/VMAllocate.h

index e24526b..2280250 100644 (file)
@@ -1,3 +1,23 @@
+2015-12-03  Michael Saboff  <msaboff@apple.com>
+
+        bmalloc: extra large allocations could be more efficient
+        https://bugs.webkit.org/show_bug.cgi?id=151817
+
+        Reviewed by Geoffrey Garen.
+
+        Reduced the super chunk size from 4MB to 2MB.
+
+        Added path to reallocate() of an extra large object to see if we can extend the allocation.
+
+        * bmalloc/Allocator.cpp:
+        (bmalloc::Allocator::reallocate):
+        * bmalloc/SegregatedFreeList.h:
+        * bmalloc/Sizes.h:
+        * bmalloc/VMAllocate.h:
+        (bmalloc::tryVMAllocate):
+        (bmalloc::tryVMExtend):
+        (bmalloc::vmAllocate):
+
 2015-11-11  Akos Kiss  <akiss@inf.u-szeged.hu>
 
         bmalloc: Add libdl dependency
index 04a9bf0..cef4e99 100644 (file)
@@ -162,6 +162,11 @@ void* Allocator::reallocate(void* object, size_t newSize)
         Range& range = PerProcess<Heap>::getFastCase()->findXLarge(lock, object);
         oldSize = range.size();
 
+        newSize = roundUpToMultipleOf<xLargeAlignment>(newSize);
+
+        if (newSize == oldSize)
+            return object;
+
         if (newSize < oldSize && newSize > largeMax) {
             newSize = roundUpToMultipleOf<xLargeAlignment>(newSize);
             if (oldSize - newSize >= xLargeAlignment) {
@@ -173,6 +178,17 @@ void* Allocator::reallocate(void* object, size_t newSize)
             }
             return object;
         }
+
+        if (newSize > oldSize) {
+            lock.unlock();
+            bool wasExtended = tryVMExtend(object, oldSize, newSize);
+            lock.lock();
+
+            if (wasExtended) {
+                range = Range(object, newSize);
+                return object;
+            }
+        }
         break;
     }
     }
index f4b4939..7bc5441 100644 (file)
@@ -60,7 +60,7 @@ private:
     FreeList& select(size_t);
 
     Owner m_owner;
-    std::array<FreeList, 16> m_freeLists;
+    std::array<FreeList, 15> m_freeLists;
 };
 
 } // namespace bmalloc
index f026bb4..cb569dc 100644 (file)
@@ -53,7 +53,7 @@ namespace Sizes {
 #endif
     static const size_t vmPageMask = ~(vmPageSize - 1);
     
-    static const size_t superChunkSize = 4 * MB;
+    static const size_t superChunkSize = 2 * MB;
 
     static const size_t smallMax = 256;
     static const size_t smallLineSize = 256;
index d9d0a9c..7e698c2 100644 (file)
@@ -82,6 +82,29 @@ inline void* tryVMAllocate(size_t vmSize)
     return result;
 }
 
+inline bool tryVMExtend(void* p, size_t vmOldSize, size_t vmNewSize)
+{
+    vmValidate(vmOldSize);
+    vmValidate(vmNewSize);
+    
+    BASSERT(vmOldSize < vmNewSize);
+
+    void* nextAddress = static_cast<char*>(p) + vmOldSize;
+    size_t extentionSize = vmNewSize - vmOldSize;
+
+    void* result = mmap(nextAddress, extentionSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, BMALLOC_VM_TAG, 0);
+
+    if (result == MAP_FAILED)
+        return false;
+
+    if (result != nextAddress) {
+        munmap(result, extentionSize);
+        return false;
+    }
+    
+    return true;
+}
+
 inline void* vmAllocate(size_t vmSize)
 {
     void* result = tryVMAllocate(vmSize);