| OLD | NEW |
| 1 /* | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 * | 3 // found in the LICENSE file. |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | 4 |
| 31 #include "wtf/allocator/Partitions.h" | 5 #include "base/allocator/partition_allocator/partitions.h" |
| 32 | 6 |
| 7 #include "base/allocator/partition_allocator/partition_allocator.h" |
| 8 #include "base/compiler_specific.h" |
| 33 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 34 #include "wtf/allocator/PartitionAllocator.h" | |
| 35 | 10 |
| 36 namespace WTF { | 11 namespace base { |
| 37 | 12 |
| 38 const char* const Partitions::kAllocatedObjectPoolName = | 13 const char* const Partitions::kAllocatedObjectPoolName = |
| 39 "partition_alloc/allocated_objects"; | 14 "partition_alloc/allocated_objects"; |
| 40 | 15 |
| 41 SpinLock Partitions::s_initializationLock; | 16 subtle::SpinLock Partitions::s_initializationLock; |
| 42 bool Partitions::s_initialized = false; | 17 bool Partitions::s_initialized = false; |
| 43 | 18 |
| 44 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; | 19 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; |
| 45 PartitionAllocatorGeneric Partitions::m_bufferAllocator; | 20 PartitionAllocatorGeneric Partitions::m_bufferAllocator; |
| 46 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; | 21 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; |
| 47 Partitions::ReportPartitionAllocSizeFunction Partitions::m_reportSizeFunction = | 22 Partitions::ReportPartitionAllocSizeFunction Partitions::m_reportSizeFunction = |
| 48 nullptr; | 23 nullptr; |
| 49 | 24 |
| 50 void Partitions::initialize( | 25 void Partitions::initialize( |
| 51 ReportPartitionAllocSizeFunction reportSizeFunction) { | 26 ReportPartitionAllocSizeFunction reportSizeFunction) { |
| 52 SpinLock::Guard guard(s_initializationLock); | 27 subtle::SpinLock::Guard guard(s_initializationLock); |
| 53 | 28 |
| 54 if (!s_initialized) { | 29 if (!s_initialized) { |
| 55 partitionAllocGlobalInit(&Partitions::handleOutOfMemory); | 30 partitionAllocGlobalInit(&Partitions::handleOutOfMemory); |
| 56 m_fastMallocAllocator.init(); | 31 m_fastMallocAllocator.init(); |
| 57 m_bufferAllocator.init(); | 32 m_bufferAllocator.init(); |
| 58 m_layoutAllocator.init(); | 33 m_layoutAllocator.init(); |
| 59 m_reportSizeFunction = reportSizeFunction; | 34 m_reportSizeFunction = reportSizeFunction; |
| 60 s_initialized = true; | 35 s_initialized = true; |
| 61 } | 36 } |
| 62 } | 37 } |
| 63 | 38 |
| 64 void Partitions::shutdown() { | 39 void Partitions::shutdown() { |
| 65 SpinLock::Guard guard(s_initializationLock); | 40 subtle::SpinLock::Guard guard(s_initializationLock); |
| 66 | 41 |
| 67 // We could ASSERT here for a memory leak within the partition, but it leads | 42 // We could DCHECK 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 | 43 // to very hard to diagnose DCHECK, so it's best to leave leak checking for |
| 69 // the valgrind and heapcheck bots, which run without partitions. | 44 // the valgrind and heapcheck bots, which run without partitions. |
| 70 if (s_initialized) { | 45 if (s_initialized) { |
| 71 (void)m_layoutAllocator.shutdown(); | 46 (void)m_layoutAllocator.shutdown(); |
| 72 (void)m_bufferAllocator.shutdown(); | 47 (void)m_bufferAllocator.shutdown(); |
| 73 (void)m_fastMallocAllocator.shutdown(); | 48 (void)m_fastMallocAllocator.shutdown(); |
| 74 } | 49 } |
| 75 } | 50 } |
| 76 | 51 |
| 77 void Partitions::decommitFreeableMemory() { | 52 void Partitions::decommitFreeableMemory() { |
| 78 RELEASE_ASSERT(isMainThread()); | 53 CHECK(isMainThread()); |
| 79 if (!s_initialized) | 54 if (!s_initialized) |
| 80 return; | 55 return; |
| 81 | 56 |
| 82 partitionPurgeMemoryGeneric(bufferPartition(), | 57 partitionPurgeMemoryGeneric(bufferPartition(), |
| 83 PartitionPurgeDecommitEmptyPages); | 58 PartitionPurgeDecommitEmptyPages); |
| 84 partitionPurgeMemoryGeneric(fastMallocPartition(), | 59 partitionPurgeMemoryGeneric(fastMallocPartition(), |
| 85 PartitionPurgeDecommitEmptyPages); | 60 PartitionPurgeDecommitEmptyPages); |
| 86 partitionPurgeMemory(layoutPartition(), PartitionPurgeDecommitEmptyPages); | 61 partitionPurgeMemory(layoutPartition(), PartitionPurgeDecommitEmptyPages); |
| 87 } | 62 } |
| 88 | 63 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 99 if (sizeInMB > observedMaxSizeInMB) { | 74 if (sizeInMB > observedMaxSizeInMB) { |
| 100 m_reportSizeFunction(sizeInMB); | 75 m_reportSizeFunction(sizeInMB); |
| 101 observedMaxSizeInMB = sizeInMB; | 76 observedMaxSizeInMB = sizeInMB; |
| 102 } | 77 } |
| 103 } | 78 } |
| 104 | 79 |
| 105 void Partitions::dumpMemoryStats(bool isLightDump, | 80 void Partitions::dumpMemoryStats(bool isLightDump, |
| 106 PartitionStatsDumper* partitionStatsDumper) { | 81 PartitionStatsDumper* partitionStatsDumper) { |
| 107 // Object model and rendering partitions are not thread safe and can be | 82 // Object model and rendering partitions are not thread safe and can be |
| 108 // accessed only on the main thread. | 83 // accessed only on the main thread. |
| 109 ASSERT(isMainThread()); | 84 DCHECK(isMainThread()); |
| 110 | 85 |
| 111 decommitFreeableMemory(); | 86 decommitFreeableMemory(); |
| 112 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump, | 87 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump, |
| 113 partitionStatsDumper); | 88 partitionStatsDumper); |
| 114 partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, | 89 partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, |
| 115 partitionStatsDumper); | 90 partitionStatsDumper); |
| 116 partitionDumpStats(layoutPartition(), "layout", isLightDump, | 91 partitionDumpStats(layoutPartition(), "layout", isLightDump, |
| 117 partitionStatsDumper); | 92 partitionStatsDumper); |
| 118 } | 93 } |
| 119 | 94 |
| 120 static NEVER_INLINE void partitionsOutOfMemoryUsing2G() { | 95 static NOINLINE void partitionsOutOfMemoryUsing2G() { |
| 121 size_t signature = 2UL * 1024 * 1024 * 1024; | 96 size_t signature = 2UL * 1024 * 1024 * 1024; |
| 122 base::debug::Alias(&signature); | 97 base::debug::Alias(&signature); |
| 123 OOM_CRASH(); | 98 OOM_CRASH(); |
| 124 } | 99 } |
| 125 | 100 |
| 126 static NEVER_INLINE void partitionsOutOfMemoryUsing1G() { | 101 static NOINLINE void partitionsOutOfMemoryUsing1G() { |
| 127 size_t signature = 1UL * 1024 * 1024 * 1024; | 102 size_t signature = 1UL * 1024 * 1024 * 1024; |
| 128 base::debug::Alias(&signature); | 103 base::debug::Alias(&signature); |
| 129 OOM_CRASH(); | 104 OOM_CRASH(); |
| 130 } | 105 } |
| 131 | 106 |
| 132 static NEVER_INLINE void partitionsOutOfMemoryUsing512M() { | 107 static NOINLINE void partitionsOutOfMemoryUsing512M() { |
| 133 size_t signature = 512 * 1024 * 1024; | 108 size_t signature = 512 * 1024 * 1024; |
| 134 base::debug::Alias(&signature); | 109 base::debug::Alias(&signature); |
| 135 OOM_CRASH(); | 110 OOM_CRASH(); |
| 136 } | 111 } |
| 137 | 112 |
| 138 static NEVER_INLINE void partitionsOutOfMemoryUsing256M() { | 113 static NOINLINE void partitionsOutOfMemoryUsing256M() { |
| 139 size_t signature = 256 * 1024 * 1024; | 114 size_t signature = 256 * 1024 * 1024; |
| 140 base::debug::Alias(&signature); | 115 base::debug::Alias(&signature); |
| 141 OOM_CRASH(); | 116 OOM_CRASH(); |
| 142 } | 117 } |
| 143 | 118 |
| 144 static NEVER_INLINE void partitionsOutOfMemoryUsing128M() { | 119 static NOINLINE void partitionsOutOfMemoryUsing128M() { |
| 145 size_t signature = 128 * 1024 * 1024; | 120 size_t signature = 128 * 1024 * 1024; |
| 146 base::debug::Alias(&signature); | 121 base::debug::Alias(&signature); |
| 147 OOM_CRASH(); | 122 OOM_CRASH(); |
| 148 } | 123 } |
| 149 | 124 |
| 150 static NEVER_INLINE void partitionsOutOfMemoryUsing64M() { | 125 static NOINLINE void partitionsOutOfMemoryUsing64M() { |
| 151 size_t signature = 64 * 1024 * 1024; | 126 size_t signature = 64 * 1024 * 1024; |
| 152 base::debug::Alias(&signature); | 127 base::debug::Alias(&signature); |
| 153 OOM_CRASH(); | 128 OOM_CRASH(); |
| 154 } | 129 } |
| 155 | 130 |
| 156 static NEVER_INLINE void partitionsOutOfMemoryUsing32M() { | 131 static NOINLINE void partitionsOutOfMemoryUsing32M() { |
| 157 size_t signature = 32 * 1024 * 1024; | 132 size_t signature = 32 * 1024 * 1024; |
| 158 base::debug::Alias(&signature); | 133 base::debug::Alias(&signature); |
| 159 OOM_CRASH(); | 134 OOM_CRASH(); |
| 160 } | 135 } |
| 161 | 136 |
| 162 static NEVER_INLINE void partitionsOutOfMemoryUsing16M() { | 137 static NOINLINE void partitionsOutOfMemoryUsing16M() { |
| 163 size_t signature = 16 * 1024 * 1024; | 138 size_t signature = 16 * 1024 * 1024; |
| 164 base::debug::Alias(&signature); | 139 base::debug::Alias(&signature); |
| 165 OOM_CRASH(); | 140 OOM_CRASH(); |
| 166 } | 141 } |
| 167 | 142 |
| 168 static NEVER_INLINE void partitionsOutOfMemoryUsingLessThan16M() { | 143 static NOINLINE void partitionsOutOfMemoryUsingLessThan16M() { |
| 169 size_t signature = 16 * 1024 * 1024 - 1; | 144 size_t signature = 16 * 1024 * 1024 - 1; |
| 170 base::debug::Alias(&signature); | 145 base::debug::Alias(&signature); |
| 171 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage (error:" | 146 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage (error:" |
| 172 << getAllocPageErrorCode() << ")"; | 147 << getAllocPageErrorCode() << ")"; |
| 173 } | 148 } |
| 174 | 149 |
| 175 void Partitions::handleOutOfMemory() { | 150 void Partitions::handleOutOfMemory() { |
| 176 volatile size_t totalUsage = totalSizeOfCommittedPages(); | 151 volatile size_t totalUsage = totalSizeOfCommittedPages(); |
| 177 uint32_t allocPageErrorCode = getAllocPageErrorCode(); | 152 uint32_t allocPageErrorCode = getAllocPageErrorCode(); |
| 178 base::debug::Alias(&allocPageErrorCode); | 153 base::debug::Alias(&allocPageErrorCode); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 189 partitionsOutOfMemoryUsing128M(); | 164 partitionsOutOfMemoryUsing128M(); |
| 190 if (totalUsage >= 64 * 1024 * 1024) | 165 if (totalUsage >= 64 * 1024 * 1024) |
| 191 partitionsOutOfMemoryUsing64M(); | 166 partitionsOutOfMemoryUsing64M(); |
| 192 if (totalUsage >= 32 * 1024 * 1024) | 167 if (totalUsage >= 32 * 1024 * 1024) |
| 193 partitionsOutOfMemoryUsing32M(); | 168 partitionsOutOfMemoryUsing32M(); |
| 194 if (totalUsage >= 16 * 1024 * 1024) | 169 if (totalUsage >= 16 * 1024 * 1024) |
| 195 partitionsOutOfMemoryUsing16M(); | 170 partitionsOutOfMemoryUsing16M(); |
| 196 partitionsOutOfMemoryUsingLessThan16M(); | 171 partitionsOutOfMemoryUsingLessThan16M(); |
| 197 } | 172 } |
| 198 | 173 |
| 199 } // namespace WTF | 174 } // namespace base |
| OLD | NEW |