| Index: third_party/WebKit/Source/wtf/Partitions.cpp
|
| diff --git a/third_party/WebKit/Source/wtf/Partitions.cpp b/third_party/WebKit/Source/wtf/Partitions.cpp
|
| index 37fa2e41a1e9e0933dc0ee7fc6cb0f422835162e..df10ff4ae279276db482dc801831097577a1f449 100644
|
| --- a/third_party/WebKit/Source/wtf/Partitions.cpp
|
| +++ b/third_party/WebKit/Source/wtf/Partitions.cpp
|
| @@ -36,7 +36,8 @@
|
|
|
| namespace WTF {
|
|
|
| -const char* const Partitions::kAllocatedObjectPoolName = "partition_alloc/allocated_objects";
|
| +const char* const Partitions::kAllocatedObjectPoolName =
|
| + "partition_alloc/allocated_objects";
|
|
|
| SpinLock Partitions::s_initializationLock;
|
| bool Partitions::s_initialized = false;
|
| @@ -47,167 +48,160 @@ SizeSpecificPartitionAllocator<3328> Partitions::m_nodeAllocator;
|
| SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator;
|
| HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr;
|
|
|
| -void Partitions::initialize(HistogramEnumerationFunction histogramEnumeration)
|
| -{
|
| - SpinLock::Guard guard(s_initializationLock);
|
| -
|
| - if (!s_initialized) {
|
| - partitionAllocGlobalInit(&Partitions::handleOutOfMemory);
|
| - m_fastMallocAllocator.init();
|
| - m_bufferAllocator.init();
|
| - m_nodeAllocator.init();
|
| - m_layoutAllocator.init();
|
| - m_histogramEnumeration = histogramEnumeration;
|
| - s_initialized = true;
|
| - }
|
| +void Partitions::initialize(HistogramEnumerationFunction histogramEnumeration) {
|
| + SpinLock::Guard guard(s_initializationLock);
|
| +
|
| + if (!s_initialized) {
|
| + partitionAllocGlobalInit(&Partitions::handleOutOfMemory);
|
| + m_fastMallocAllocator.init();
|
| + m_bufferAllocator.init();
|
| + m_nodeAllocator.init();
|
| + m_layoutAllocator.init();
|
| + m_histogramEnumeration = histogramEnumeration;
|
| + s_initialized = true;
|
| + }
|
| }
|
|
|
| -void Partitions::shutdown()
|
| -{
|
| - SpinLock::Guard guard(s_initializationLock);
|
| -
|
| - // We could ASSERT here for a memory leak within the partition, but it leads
|
| - // to very hard to diagnose ASSERTs, so it's best to leave leak checking for
|
| - // the valgrind and heapcheck bots, which run without partitions.
|
| - if (s_initialized) {
|
| - (void) m_layoutAllocator.shutdown();
|
| - (void) m_nodeAllocator.shutdown();
|
| - (void) m_bufferAllocator.shutdown();
|
| - (void) m_fastMallocAllocator.shutdown();
|
| - }
|
| +void Partitions::shutdown() {
|
| + SpinLock::Guard guard(s_initializationLock);
|
| +
|
| + // We could ASSERT here for a memory leak within the partition, but it leads
|
| + // to very hard to diagnose ASSERTs, so it's best to leave leak checking for
|
| + // the valgrind and heapcheck bots, which run without partitions.
|
| + if (s_initialized) {
|
| + (void)m_layoutAllocator.shutdown();
|
| + (void)m_nodeAllocator.shutdown();
|
| + (void)m_bufferAllocator.shutdown();
|
| + (void)m_fastMallocAllocator.shutdown();
|
| + }
|
| }
|
|
|
| -void Partitions::decommitFreeableMemory()
|
| -{
|
| - RELEASE_ASSERT(isMainThread());
|
| - if (!s_initialized)
|
| - return;
|
| -
|
| - partitionPurgeMemoryGeneric(bufferPartition(), PartitionPurgeDecommitEmptyPages);
|
| - partitionPurgeMemoryGeneric(fastMallocPartition(), PartitionPurgeDecommitEmptyPages);
|
| - partitionPurgeMemory(nodePartition(), PartitionPurgeDecommitEmptyPages);
|
| - partitionPurgeMemory(layoutPartition(), PartitionPurgeDecommitEmptyPages);
|
| +void Partitions::decommitFreeableMemory() {
|
| + RELEASE_ASSERT(isMainThread());
|
| + if (!s_initialized)
|
| + return;
|
| +
|
| + partitionPurgeMemoryGeneric(bufferPartition(),
|
| + PartitionPurgeDecommitEmptyPages);
|
| + partitionPurgeMemoryGeneric(fastMallocPartition(),
|
| + PartitionPurgeDecommitEmptyPages);
|
| + partitionPurgeMemory(nodePartition(), PartitionPurgeDecommitEmptyPages);
|
| + partitionPurgeMemory(layoutPartition(), PartitionPurgeDecommitEmptyPages);
|
| }
|
|
|
| -void Partitions::reportMemoryUsageHistogram()
|
| -{
|
| - static size_t supportedMaxSizeInMB = 4 * 1024;
|
| - static size_t observedMaxSizeInMB = 0;
|
| -
|
| - if (!m_histogramEnumeration)
|
| - return;
|
| - // We only report the memory in the main thread.
|
| - if (!isMainThread())
|
| - return;
|
| - // +1 is for rounding up the sizeInMB.
|
| - size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1;
|
| - if (sizeInMB >= supportedMaxSizeInMB)
|
| - sizeInMB = supportedMaxSizeInMB - 1;
|
| - if (sizeInMB > observedMaxSizeInMB) {
|
| - // Send a UseCounter only when we see the highest memory usage
|
| - // we've ever seen.
|
| - m_histogramEnumeration("PartitionAlloc.CommittedSize", sizeInMB, supportedMaxSizeInMB);
|
| - observedMaxSizeInMB = sizeInMB;
|
| - }
|
| +void Partitions::reportMemoryUsageHistogram() {
|
| + static size_t supportedMaxSizeInMB = 4 * 1024;
|
| + static size_t observedMaxSizeInMB = 0;
|
| +
|
| + if (!m_histogramEnumeration)
|
| + return;
|
| + // We only report the memory in the main thread.
|
| + if (!isMainThread())
|
| + return;
|
| + // +1 is for rounding up the sizeInMB.
|
| + size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1;
|
| + if (sizeInMB >= supportedMaxSizeInMB)
|
| + sizeInMB = supportedMaxSizeInMB - 1;
|
| + if (sizeInMB > observedMaxSizeInMB) {
|
| + // Send a UseCounter only when we see the highest memory usage
|
| + // we've ever seen.
|
| + m_histogramEnumeration("PartitionAlloc.CommittedSize", sizeInMB,
|
| + supportedMaxSizeInMB);
|
| + observedMaxSizeInMB = sizeInMB;
|
| + }
|
| }
|
|
|
| -void Partitions::dumpMemoryStats(bool isLightDump, PartitionStatsDumper* partitionStatsDumper)
|
| -{
|
| - // Object model and rendering partitions are not thread safe and can be
|
| - // accessed only on the main thread.
|
| - ASSERT(isMainThread());
|
| -
|
| - decommitFreeableMemory();
|
| - partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump, partitionStatsDumper);
|
| - partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, partitionStatsDumper);
|
| - partitionDumpStats(nodePartition(), "node", isLightDump, partitionStatsDumper);
|
| - partitionDumpStats(layoutPartition(), "layout", isLightDump, partitionStatsDumper);
|
| +void Partitions::dumpMemoryStats(bool isLightDump,
|
| + PartitionStatsDumper* partitionStatsDumper) {
|
| + // Object model and rendering partitions are not thread safe and can be
|
| + // accessed only on the main thread.
|
| + ASSERT(isMainThread());
|
| +
|
| + decommitFreeableMemory();
|
| + partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump,
|
| + partitionStatsDumper);
|
| + partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump,
|
| + partitionStatsDumper);
|
| + partitionDumpStats(nodePartition(), "node", isLightDump,
|
| + partitionStatsDumper);
|
| + partitionDumpStats(layoutPartition(), "layout", isLightDump,
|
| + partitionStatsDumper);
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsing2G()
|
| -{
|
| - size_t signature = 2UL * 1024 * 1024 * 1024;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsing2G() {
|
| + size_t signature = 2UL * 1024 * 1024 * 1024;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsing1G()
|
| -{
|
| - size_t signature = 1UL * 1024 * 1024 * 1024;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsing1G() {
|
| + size_t signature = 1UL * 1024 * 1024 * 1024;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsing512M()
|
| -{
|
| - size_t signature = 512 * 1024 * 1024;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsing512M() {
|
| + size_t signature = 512 * 1024 * 1024;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsing256M()
|
| -{
|
| - size_t signature = 256 * 1024 * 1024;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsing256M() {
|
| + size_t signature = 256 * 1024 * 1024;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsing128M()
|
| -{
|
| - size_t signature = 128 * 1024 * 1024;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsing128M() {
|
| + size_t signature = 128 * 1024 * 1024;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsing64M()
|
| -{
|
| - size_t signature = 64 * 1024 * 1024;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsing64M() {
|
| + size_t signature = 64 * 1024 * 1024;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsing32M()
|
| -{
|
| - size_t signature = 32 * 1024 * 1024;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsing32M() {
|
| + size_t signature = 32 * 1024 * 1024;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsing16M()
|
| -{
|
| - size_t signature = 16 * 1024 * 1024;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsing16M() {
|
| + size_t signature = 16 * 1024 * 1024;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -static NEVER_INLINE void partitionsOutOfMemoryUsingLessThan16M()
|
| -{
|
| - size_t signature = 16 * 1024 * 1024 - 1;
|
| - base::debug::Alias(&signature);
|
| - IMMEDIATE_CRASH();
|
| +static NEVER_INLINE void partitionsOutOfMemoryUsingLessThan16M() {
|
| + size_t signature = 16 * 1024 * 1024 - 1;
|
| + base::debug::Alias(&signature);
|
| + IMMEDIATE_CRASH();
|
| }
|
|
|
| -void Partitions::handleOutOfMemory()
|
| -{
|
| - volatile size_t totalUsage = totalSizeOfCommittedPages();
|
| -
|
| - if (totalUsage >= 2UL * 1024 * 1024 * 1024)
|
| - partitionsOutOfMemoryUsing2G();
|
| - if (totalUsage >= 1UL * 1024 * 1024 * 1024)
|
| - partitionsOutOfMemoryUsing1G();
|
| - if (totalUsage >= 512 * 1024 * 1024)
|
| - partitionsOutOfMemoryUsing512M();
|
| - if (totalUsage >= 256 * 1024 * 1024)
|
| - partitionsOutOfMemoryUsing256M();
|
| - if (totalUsage >= 128 * 1024 * 1024)
|
| - partitionsOutOfMemoryUsing128M();
|
| - if (totalUsage >= 64 * 1024 * 1024)
|
| - partitionsOutOfMemoryUsing64M();
|
| - if (totalUsage >= 32 * 1024 * 1024)
|
| - partitionsOutOfMemoryUsing32M();
|
| - if (totalUsage >= 16 * 1024 * 1024)
|
| - partitionsOutOfMemoryUsing16M();
|
| - partitionsOutOfMemoryUsingLessThan16M();
|
| +void Partitions::handleOutOfMemory() {
|
| + volatile size_t totalUsage = totalSizeOfCommittedPages();
|
| +
|
| + if (totalUsage >= 2UL * 1024 * 1024 * 1024)
|
| + partitionsOutOfMemoryUsing2G();
|
| + if (totalUsage >= 1UL * 1024 * 1024 * 1024)
|
| + partitionsOutOfMemoryUsing1G();
|
| + if (totalUsage >= 512 * 1024 * 1024)
|
| + partitionsOutOfMemoryUsing512M();
|
| + if (totalUsage >= 256 * 1024 * 1024)
|
| + partitionsOutOfMemoryUsing256M();
|
| + if (totalUsage >= 128 * 1024 * 1024)
|
| + partitionsOutOfMemoryUsing128M();
|
| + if (totalUsage >= 64 * 1024 * 1024)
|
| + partitionsOutOfMemoryUsing64M();
|
| + if (totalUsage >= 32 * 1024 * 1024)
|
| + partitionsOutOfMemoryUsing32M();
|
| + if (totalUsage >= 16 * 1024 * 1024)
|
| + partitionsOutOfMemoryUsing16M();
|
| + partitionsOutOfMemoryUsingLessThan16M();
|
| }
|
|
|
| -} // namespace WTF
|
| +} // namespace WTF
|
|
|