| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "wtf/allocator/Partitions.h" | 31 #include "wtf/allocator/Partitions.h" |
| 32 | 32 |
| 33 #include "base/allocator/partition_allocator/page_allocator.h" |
| 33 #include "base/debug/alias.h" | 34 #include "base/debug/alias.h" |
| 34 #include "wtf/allocator/PartitionAllocator.h" | 35 #include "wtf/allocator/PartitionAllocator.h" |
| 35 | 36 |
| 36 namespace WTF { | 37 namespace WTF { |
| 37 | 38 |
| 38 const char* const Partitions::kAllocatedObjectPoolName = | 39 const char* const Partitions::kAllocatedObjectPoolName = |
| 39 "partition_alloc/allocated_objects"; | 40 "partition_alloc/allocated_objects"; |
| 40 | 41 |
| 41 SpinLock Partitions::s_initializationLock; | 42 base::subtle::SpinLock Partitions::s_initializationLock; |
| 42 bool Partitions::s_initialized = false; | 43 bool Partitions::s_initialized = false; |
| 43 | 44 |
| 44 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; | 45 base::PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; |
| 45 PartitionAllocatorGeneric Partitions::m_bufferAllocator; | 46 base::PartitionAllocatorGeneric Partitions::m_bufferAllocator; |
| 46 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; | 47 base::SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; |
| 47 Partitions::ReportPartitionAllocSizeFunction Partitions::m_reportSizeFunction = | 48 Partitions::ReportPartitionAllocSizeFunction Partitions::m_reportSizeFunction = |
| 48 nullptr; | 49 nullptr; |
| 49 | 50 |
| 50 void Partitions::initialize( | 51 void Partitions::initialize( |
| 51 ReportPartitionAllocSizeFunction reportSizeFunction) { | 52 ReportPartitionAllocSizeFunction reportSizeFunction) { |
| 52 SpinLock::Guard guard(s_initializationLock); | 53 base::subtle::SpinLock::Guard guard(s_initializationLock); |
| 53 | 54 |
| 54 if (!s_initialized) { | 55 if (!s_initialized) { |
| 55 partitionAllocGlobalInit(&Partitions::handleOutOfMemory); | 56 base::partitionAllocGlobalInit(&Partitions::handleOutOfMemory); |
| 56 m_fastMallocAllocator.init(); | 57 m_fastMallocAllocator.init(); |
| 57 m_bufferAllocator.init(); | 58 m_bufferAllocator.init(); |
| 58 m_layoutAllocator.init(); | 59 m_layoutAllocator.init(); |
| 59 m_reportSizeFunction = reportSizeFunction; | 60 m_reportSizeFunction = reportSizeFunction; |
| 60 s_initialized = true; | 61 s_initialized = true; |
| 61 } | 62 } |
| 62 } | 63 } |
| 63 | 64 |
| 64 void Partitions::shutdown() { | 65 void Partitions::shutdown() { |
| 65 SpinLock::Guard guard(s_initializationLock); | 66 base::subtle::SpinLock::Guard guard(s_initializationLock); |
| 66 | 67 |
| 67 // We could ASSERT here for a memory leak within the partition, but it leads | 68 // We could ASSERT here for a memory leak within the partition, but it leads |
| 68 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for | 69 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for |
| 69 // the valgrind and heapcheck bots, which run without partitions. | 70 // the valgrind and heapcheck bots, which run without partitions. |
| 70 if (s_initialized) { | 71 if (s_initialized) { |
| 71 (void)m_layoutAllocator.shutdown(); | 72 (void)m_layoutAllocator.shutdown(); |
| 72 (void)m_bufferAllocator.shutdown(); | 73 (void)m_bufferAllocator.shutdown(); |
| 73 (void)m_fastMallocAllocator.shutdown(); | 74 (void)m_fastMallocAllocator.shutdown(); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 void Partitions::decommitFreeableMemory() { | 78 void Partitions::decommitFreeableMemory() { |
| 78 RELEASE_ASSERT(isMainThread()); | 79 RELEASE_ASSERT(isMainThread()); |
| 79 if (!s_initialized) | 80 if (!s_initialized) |
| 80 return; | 81 return; |
| 81 | 82 |
| 82 partitionPurgeMemoryGeneric(bufferPartition(), | 83 partitionPurgeMemoryGeneric(bufferPartition(), |
| 83 PartitionPurgeDecommitEmptyPages); | 84 base::PartitionPurgeDecommitEmptyPages); |
| 84 partitionPurgeMemoryGeneric(fastMallocPartition(), | 85 partitionPurgeMemoryGeneric(fastMallocPartition(), |
| 85 PartitionPurgeDecommitEmptyPages); | 86 base::PartitionPurgeDecommitEmptyPages); |
| 86 partitionPurgeMemory(layoutPartition(), PartitionPurgeDecommitEmptyPages); | 87 partitionPurgeMemory(layoutPartition(), |
| 88 base::PartitionPurgeDecommitEmptyPages); |
| 87 } | 89 } |
| 88 | 90 |
| 89 void Partitions::reportMemoryUsageHistogram() { | 91 void Partitions::reportMemoryUsageHistogram() { |
| 90 static size_t observedMaxSizeInMB = 0; | 92 static size_t observedMaxSizeInMB = 0; |
| 91 | 93 |
| 92 if (!m_reportSizeFunction) | 94 if (!m_reportSizeFunction) |
| 93 return; | 95 return; |
| 94 // We only report the memory in the main thread. | 96 // We only report the memory in the main thread. |
| 95 if (!isMainThread()) | 97 if (!isMainThread()) |
| 96 return; | 98 return; |
| 97 // +1 is for rounding up the sizeInMB. | 99 // +1 is for rounding up the sizeInMB. |
| 98 size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1; | 100 size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1; |
| 99 if (sizeInMB > observedMaxSizeInMB) { | 101 if (sizeInMB > observedMaxSizeInMB) { |
| 100 m_reportSizeFunction(sizeInMB); | 102 m_reportSizeFunction(sizeInMB); |
| 101 observedMaxSizeInMB = sizeInMB; | 103 observedMaxSizeInMB = sizeInMB; |
| 102 } | 104 } |
| 103 } | 105 } |
| 104 | 106 |
| 105 void Partitions::dumpMemoryStats(bool isLightDump, | 107 void Partitions::dumpMemoryStats( |
| 106 PartitionStatsDumper* partitionStatsDumper) { | 108 bool isLightDump, |
| 109 base::PartitionStatsDumper* partitionStatsDumper) { |
| 107 // Object model and rendering partitions are not thread safe and can be | 110 // Object model and rendering partitions are not thread safe and can be |
| 108 // accessed only on the main thread. | 111 // accessed only on the main thread. |
| 109 ASSERT(isMainThread()); | 112 ASSERT(isMainThread()); |
| 110 | 113 |
| 111 decommitFreeableMemory(); | 114 decommitFreeableMemory(); |
| 112 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump, | 115 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump, |
| 113 partitionStatsDumper); | 116 partitionStatsDumper); |
| 114 partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, | 117 partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, |
| 115 partitionStatsDumper); | 118 partitionStatsDumper); |
| 116 partitionDumpStats(layoutPartition(), "layout", isLightDump, | 119 partitionDumpStats(layoutPartition(), "layout", isLightDump, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 164 |
| 162 static NEVER_INLINE void partitionsOutOfMemoryUsing16M() { | 165 static NEVER_INLINE void partitionsOutOfMemoryUsing16M() { |
| 163 size_t signature = 16 * 1024 * 1024; | 166 size_t signature = 16 * 1024 * 1024; |
| 164 base::debug::Alias(&signature); | 167 base::debug::Alias(&signature); |
| 165 OOM_CRASH(); | 168 OOM_CRASH(); |
| 166 } | 169 } |
| 167 | 170 |
| 168 static NEVER_INLINE void partitionsOutOfMemoryUsingLessThan16M() { | 171 static NEVER_INLINE void partitionsOutOfMemoryUsingLessThan16M() { |
| 169 size_t signature = 16 * 1024 * 1024 - 1; | 172 size_t signature = 16 * 1024 * 1024 - 1; |
| 170 base::debug::Alias(&signature); | 173 base::debug::Alias(&signature); |
| 171 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage (error:" | 174 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage"; |
| 172 << getAllocPageErrorCode() << ")"; | 175 // TODO(palmer): Restore this later: |
| 176 // DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage (error:" |
| 177 // << base::getAllocPageErrorCode() << ")"; |
| 173 } | 178 } |
| 174 | 179 |
| 175 void Partitions::handleOutOfMemory() { | 180 void Partitions::handleOutOfMemory() { |
| 176 volatile size_t totalUsage = totalSizeOfCommittedPages(); | 181 volatile size_t totalUsage = totalSizeOfCommittedPages(); |
| 177 uint32_t allocPageErrorCode = getAllocPageErrorCode(); | 182 // TODO(palmer): Restore this later: |
| 178 base::debug::Alias(&allocPageErrorCode); | 183 // uint32_t allocPageErrorCode = base::getAllocPageErrorCode(); |
| 184 // base::debug::Alias(&allocPageErrorCode); |
| 179 | 185 |
| 180 if (totalUsage >= 2UL * 1024 * 1024 * 1024) | 186 if (totalUsage >= 2UL * 1024 * 1024 * 1024) |
| 181 partitionsOutOfMemoryUsing2G(); | 187 partitionsOutOfMemoryUsing2G(); |
| 182 if (totalUsage >= 1UL * 1024 * 1024 * 1024) | 188 if (totalUsage >= 1UL * 1024 * 1024 * 1024) |
| 183 partitionsOutOfMemoryUsing1G(); | 189 partitionsOutOfMemoryUsing1G(); |
| 184 if (totalUsage >= 512 * 1024 * 1024) | 190 if (totalUsage >= 512 * 1024 * 1024) |
| 185 partitionsOutOfMemoryUsing512M(); | 191 partitionsOutOfMemoryUsing512M(); |
| 186 if (totalUsage >= 256 * 1024 * 1024) | 192 if (totalUsage >= 256 * 1024 * 1024) |
| 187 partitionsOutOfMemoryUsing256M(); | 193 partitionsOutOfMemoryUsing256M(); |
| 188 if (totalUsage >= 128 * 1024 * 1024) | 194 if (totalUsage >= 128 * 1024 * 1024) |
| 189 partitionsOutOfMemoryUsing128M(); | 195 partitionsOutOfMemoryUsing128M(); |
| 190 if (totalUsage >= 64 * 1024 * 1024) | 196 if (totalUsage >= 64 * 1024 * 1024) |
| 191 partitionsOutOfMemoryUsing64M(); | 197 partitionsOutOfMemoryUsing64M(); |
| 192 if (totalUsage >= 32 * 1024 * 1024) | 198 if (totalUsage >= 32 * 1024 * 1024) |
| 193 partitionsOutOfMemoryUsing32M(); | 199 partitionsOutOfMemoryUsing32M(); |
| 194 if (totalUsage >= 16 * 1024 * 1024) | 200 if (totalUsage >= 16 * 1024 * 1024) |
| 195 partitionsOutOfMemoryUsing16M(); | 201 partitionsOutOfMemoryUsing16M(); |
| 196 partitionsOutOfMemoryUsingLessThan16M(); | 202 partitionsOutOfMemoryUsingLessThan16M(); |
| 197 } | 203 } |
| 198 | 204 |
| 199 } // namespace WTF | 205 } // namespace WTF |
| OLD | NEW |