bmalloc: Don't use a whole page for metadata
[WebKit-https.git] / Source / bmalloc / bmalloc / VMHeap.h
index 7fb8cf806428a38de047e1ac9247410f81f5db7b..abc8c625e22d2e21275027964d467d40a633ffb0 100644 (file)
@@ -51,17 +51,23 @@ public:
     VMHeap();
 
     SmallPage* allocateSmallPage(std::lock_guard<StaticMutex>&);
     VMHeap();
 
     SmallPage* allocateSmallPage(std::lock_guard<StaticMutex>&);
-    LargeObject allocateLargeObject(size_t);
-    LargeObject allocateLargeObject(size_t, size_t, size_t);
+    LargeObject allocateLargeObject(std::lock_guard<StaticMutex>&, size_t);
+    LargeObject allocateLargeObject(std::lock_guard<StaticMutex>&, size_t, size_t, size_t);
 
     void deallocateSmallPage(std::unique_lock<StaticMutex>&, SmallPage*);
     void deallocateLargeObject(std::unique_lock<StaticMutex>&, LargeObject);
 
     void deallocateSmallPage(std::unique_lock<StaticMutex>&, SmallPage*);
     void deallocateLargeObject(std::unique_lock<StaticMutex>&, LargeObject);
-
+    
 private:
 private:
-    void grow();
+    void allocateSmallChunk(std::lock_guard<StaticMutex>&);
+    void allocateLargeChunk(std::lock_guard<StaticMutex>&);
+    void allocateSuperChunk(std::lock_guard<StaticMutex>&);
 
     Vector<SmallPage*> m_smallPages;
     SegregatedFreeList m_largeObjects;
 
     Vector<SmallPage*> m_smallPages;
     SegregatedFreeList m_largeObjects;
+
+    Vector<SuperChunk*> m_smallChunks;
+    Vector<SuperChunk*> m_largeChunks;
+
 #if BOS(DARWIN)
     Zone m_zone;
 #endif
 #if BOS(DARWIN)
     Zone m_zone;
 #endif
@@ -70,19 +76,18 @@ private:
 inline SmallPage* VMHeap::allocateSmallPage(std::lock_guard<StaticMutex>& lock)
 {
     if (!m_smallPages.size())
 inline SmallPage* VMHeap::allocateSmallPage(std::lock_guard<StaticMutex>& lock)
 {
     if (!m_smallPages.size())
-        grow();
+        allocateSmallChunk(lock);
 
     SmallPage* page = m_smallPages.pop();
 
     SmallPage* page = m_smallPages.pop();
-    page->setHasFreeLines(lock, true);
     vmAllocatePhysicalPages(page->begin()->begin(), vmPageSize);
     return page;
 }
 
     vmAllocatePhysicalPages(page->begin()->begin(), vmPageSize);
     return page;
 }
 
-inline LargeObject VMHeap::allocateLargeObject(size_t size)
+inline LargeObject VMHeap::allocateLargeObject(std::lock_guard<StaticMutex>& lock, size_t size)
 {
     LargeObject largeObject = m_largeObjects.take(size);
     if (!largeObject) {
 {
     LargeObject largeObject = m_largeObjects.take(size);
     if (!largeObject) {
-        grow();
+        allocateLargeChunk(lock);
         largeObject = m_largeObjects.take(size);
         BASSERT(largeObject);
     }
         largeObject = m_largeObjects.take(size);
         BASSERT(largeObject);
     }
@@ -90,11 +95,11 @@ inline LargeObject VMHeap::allocateLargeObject(size_t size)
     return largeObject;
 }
 
     return largeObject;
 }
 
-inline LargeObject VMHeap::allocateLargeObject(size_t alignment, size_t size, size_t unalignedSize)
+inline LargeObject VMHeap::allocateLargeObject(std::lock_guard<StaticMutex>& lock, size_t alignment, size_t size, size_t unalignedSize)
 {
     LargeObject largeObject = m_largeObjects.take(alignment, size, unalignedSize);
     if (!largeObject) {
 {
     LargeObject largeObject = m_largeObjects.take(alignment, size, unalignedSize);
     if (!largeObject) {
-        grow();
+        allocateLargeChunk(lock);
         largeObject = m_largeObjects.take(alignment, size, unalignedSize);
         BASSERT(largeObject);
     }
         largeObject = m_largeObjects.take(alignment, size, unalignedSize);
         BASSERT(largeObject);
     }