Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: third_party/WebKit/Source/wtf/allocator/Partitions.cpp

Issue 2518253002: Move Partition Allocator into Chromium base. (Closed)
Patch Set: Rebase and resolve conflict. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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);
174 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage";
haraken 2016/12/08 08:43:55 Remove.
palmer 2016/12/08 22:29:58 Done.
171 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage (error:" 175 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage (error:"
172 << getAllocPageErrorCode() << ")"; 176 << getAllocPageErrorCode() << ")";
173 } 177 }
174 178
175 void Partitions::handleOutOfMemory() { 179 void Partitions::handleOutOfMemory() {
176 volatile size_t totalUsage = totalSizeOfCommittedPages(); 180 volatile size_t totalUsage = totalSizeOfCommittedPages();
177 uint32_t allocPageErrorCode = getAllocPageErrorCode(); 181 uint32_t allocPageErrorCode = getAllocPageErrorCode();
178 base::debug::Alias(&allocPageErrorCode); 182 base::debug::Alias(&allocPageErrorCode);
179 183
180 if (totalUsage >= 2UL * 1024 * 1024 * 1024) 184 if (totalUsage >= 2UL * 1024 * 1024 * 1024)
181 partitionsOutOfMemoryUsing2G(); 185 partitionsOutOfMemoryUsing2G();
182 if (totalUsage >= 1UL * 1024 * 1024 * 1024) 186 if (totalUsage >= 1UL * 1024 * 1024 * 1024)
183 partitionsOutOfMemoryUsing1G(); 187 partitionsOutOfMemoryUsing1G();
184 if (totalUsage >= 512 * 1024 * 1024) 188 if (totalUsage >= 512 * 1024 * 1024)
185 partitionsOutOfMemoryUsing512M(); 189 partitionsOutOfMemoryUsing512M();
186 if (totalUsage >= 256 * 1024 * 1024) 190 if (totalUsage >= 256 * 1024 * 1024)
187 partitionsOutOfMemoryUsing256M(); 191 partitionsOutOfMemoryUsing256M();
188 if (totalUsage >= 128 * 1024 * 1024) 192 if (totalUsage >= 128 * 1024 * 1024)
189 partitionsOutOfMemoryUsing128M(); 193 partitionsOutOfMemoryUsing128M();
190 if (totalUsage >= 64 * 1024 * 1024) 194 if (totalUsage >= 64 * 1024 * 1024)
191 partitionsOutOfMemoryUsing64M(); 195 partitionsOutOfMemoryUsing64M();
192 if (totalUsage >= 32 * 1024 * 1024) 196 if (totalUsage >= 32 * 1024 * 1024)
193 partitionsOutOfMemoryUsing32M(); 197 partitionsOutOfMemoryUsing32M();
194 if (totalUsage >= 16 * 1024 * 1024) 198 if (totalUsage >= 16 * 1024 * 1024)
195 partitionsOutOfMemoryUsing16M(); 199 partitionsOutOfMemoryUsing16M();
196 partitionsOutOfMemoryUsingLessThan16M(); 200 partitionsOutOfMemoryUsingLessThan16M();
197 } 201 }
198 202
199 } // namespace WTF 203 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698