https://bugs.webkit.org/show_bug.cgi?id=136592
Reviewed by Gavin Barraclough.
Source/bmalloc:
We do this by tracking "size" and "capacity" in the VM heap.
The VM heap's "capacity" is all the VM we ever allocated.
The VM heap's "size" the subset of VM currently held onto by the
VM heap (and therefore not in use by the regular heap).
Somewhat ironically, reducing the process's memory footprint, increases
the size of the VM heap, since the VM heap holds the pages that are
purely virtual and not physical.
* bmalloc/Heap.cpp:
(bmalloc::Heap::size):
(bmalloc::Heap::capacity):
* bmalloc/Heap.h:
* bmalloc/VMHeap.cpp:
(bmalloc::VMHeap::VMHeap):
(bmalloc::VMHeap::allocateSmallChunk):
(bmalloc::VMHeap::allocateMediumChunk):
(bmalloc::VMHeap::allocateLargeChunk):
* bmalloc/VMHeap.h:
(bmalloc::VMHeap::size):
(bmalloc::VMHeap::capacity):
(bmalloc::VMHeap::allocateSmallPage):
(bmalloc::VMHeap::allocateMediumPage):
(bmalloc::VMHeap::allocateLargeRange):
(bmalloc::VMHeap::deallocateSmallPage):
(bmalloc::VMHeap::deallocateMediumPage):
(bmalloc::VMHeap::deallocateLargeRange):
* bmalloc/bmalloc.h:
(bmalloc::api::heapSize):
(bmalloc::api::heapCapacity):
Source/WTF:
* wtf/FastMalloc.cpp:
(WTF::fastMallocStatistics):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173346
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2014-09-05 Geoffrey Garen <ggaren@apple.com>
+
+ bmalloc should honor the FastMalloc statistics API
+ https://bugs.webkit.org/show_bug.cgi?id=136592
+
+ Reviewed by Gavin Barraclough.
+
+ * wtf/FastMalloc.cpp:
+ (WTF::fastMallocStatistics):
+
2014-09-05 Geoffrey Garen <ggaren@apple.com>
bmalloc should honor the FastMalloc scavenging API
FastMallocStatistics fastMallocStatistics()
{
- FastMallocStatistics statistics = { 0, 0, 0 };
+ FastMallocStatistics statistics;
+ statistics.committedVMBytes = bmalloc::api::heapSize();
+ statistics.reservedVMBytes = bmalloc::api::heapCapacity();
+ statistics.freeListBytes = 0; // bmalloc doesn't really have free lists.
+
return statistics;
}
+2014-09-05 Geoffrey Garen <ggaren@apple.com>
+
+ bmalloc should honor the FastMalloc statistics API
+ https://bugs.webkit.org/show_bug.cgi?id=136592
+
+ Reviewed by Gavin Barraclough.
+
+ We do this by tracking "size" and "capacity" in the VM heap.
+
+ The VM heap's "capacity" is all the VM we ever allocated.
+
+ The VM heap's "size" the subset of VM currently held onto by the
+ VM heap (and therefore not in use by the regular heap).
+
+ Somewhat ironically, reducing the process's memory footprint, increases
+ the size of the VM heap, since the VM heap holds the pages that are
+ purely virtual and not physical.
+
+ * bmalloc/Heap.cpp:
+ (bmalloc::Heap::size):
+ (bmalloc::Heap::capacity):
+ * bmalloc/Heap.h:
+ * bmalloc/VMHeap.cpp:
+ (bmalloc::VMHeap::VMHeap):
+ (bmalloc::VMHeap::allocateSmallChunk):
+ (bmalloc::VMHeap::allocateMediumChunk):
+ (bmalloc::VMHeap::allocateLargeChunk):
+ * bmalloc/VMHeap.h:
+ (bmalloc::VMHeap::size):
+ (bmalloc::VMHeap::capacity):
+ (bmalloc::VMHeap::allocateSmallPage):
+ (bmalloc::VMHeap::allocateMediumPage):
+ (bmalloc::VMHeap::allocateLargeRange):
+ (bmalloc::VMHeap::deallocateSmallPage):
+ (bmalloc::VMHeap::deallocateMediumPage):
+ (bmalloc::VMHeap::deallocateLargeRange):
+ * bmalloc/bmalloc.h:
+ (bmalloc::api::heapSize):
+ (bmalloc::api::heapCapacity):
+
2014-09-02 Geoffrey Garen <ggaren@apple.com>
bmalloc crashes on the EWS bots (due to bad large object allocation)
m_scavenger.run();
}
+size_t Heap::size(std::lock_guard<StaticMutex>&)
+{
+ return m_vmHeap.capacity() - m_vmHeap.size();
+}
+
+size_t Heap::capacity(std::lock_guard<StaticMutex>&)
+{
+ return m_vmHeap.capacity();
+}
+
} // namespace bmalloc
void deallocateXLarge(std::lock_guard<StaticMutex>&, void*);
void scavenge(std::unique_lock<StaticMutex>&, std::chrono::milliseconds sleepDuration);
-
+
+ size_t size(std::lock_guard<StaticMutex>&);
+ size_t capacity(std::lock_guard<StaticMutex>&);
+
private:
~Heap() = delete;
namespace bmalloc {
VMHeap::VMHeap()
+ : m_size(0)
+ , m_capacity(0)
{
}
SmallChunk* chunk = SmallChunk::create();
for (auto* it = chunk->begin(); it != chunk->end(); ++it)
m_smallPages.push(it);
+
+ m_size += smallChunkSize;
+ m_capacity += smallChunkSize;
}
void VMHeap::allocateMediumChunk()
MediumChunk* chunk = MediumChunk::create();
for (auto* it = chunk->begin(); it != chunk->end(); ++it)
m_mediumPages.push(it);
+
+ m_size += mediumChunkSize;
+ m_capacity += mediumChunkSize;
}
Range VMHeap::allocateLargeChunk()
{
LargeChunk* chunk = LargeChunk::create();
Range result = BoundaryTag::init(chunk);
+
+ m_size += largeChunkSize;
+ m_capacity += largeChunkSize;
+
return result;
}
public:
VMHeap();
+ size_t size() { return m_size; }
+ size_t capacity() { return m_capacity; }
+
SmallPage* allocateSmallPage();
MediumPage* allocateMediumPage();
Range allocateLargeRange(size_t);
void allocateSmallChunk();
void allocateMediumChunk();
Range allocateLargeChunk();
-
+
+ size_t m_size;
+ size_t m_capacity;
+
Vector<SmallPage*> m_smallPages;
Vector<MediumPage*> m_mediumPages;
SegregatedFreeList m_largeRanges;
if (!m_smallPages.size())
allocateSmallChunk();
+ m_size -= vmPageSize;
return m_smallPages.pop();
}
if (!m_mediumPages.size())
allocateMediumChunk();
+ m_size -= vmPageSize;
return m_mediumPages.pop();
}
Range range = m_largeRanges.take(size);
if (!range)
range = allocateLargeChunk();
+ m_size -= range.size();
return range;
}
vmDeallocatePhysicalPages(page->begin()->begin(), vmPageSize);
lock.lock();
+ m_size += vmPageSize;
m_smallPages.push(page);
}
vmDeallocatePhysicalPages(page->begin()->begin(), vmPageSize);
lock.lock();
+ m_size += vmPageSize;
m_mediumPages.push(page);
}
beginTag->setHasPhysicalPages(false);
endTag->setHasPhysicalPages(false);
+ m_size += range.size();
m_largeRanges.insert(range);
}
PerProcess<Heap>::get()->scavenge(lock, std::chrono::milliseconds(0));
}
+inline size_t heapSize()
+{
+ std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
+ return PerProcess<Heap>::get()->size(lock);
+}
+
+inline size_t heapCapacity()
+{
+ std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
+ return PerProcess<Heap>::get()->capacity(lock);
+}
+
} // namespace api
} // namespace bmalloc