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

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

Issue 2518253002: Move Partition Allocator into Chromium base. (Closed)
Patch Set: Move OOM_CRASH into its own, more specific header. Fixes Windows build. 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (totalUsage >= 64 * 1024 * 1024) 193 if (totalUsage >= 64 * 1024 * 1024)
191 partitionsOutOfMemoryUsing64M(); 194 partitionsOutOfMemoryUsing64M();
192 if (totalUsage >= 32 * 1024 * 1024) 195 if (totalUsage >= 32 * 1024 * 1024)
193 partitionsOutOfMemoryUsing32M(); 196 partitionsOutOfMemoryUsing32M();
194 if (totalUsage >= 16 * 1024 * 1024) 197 if (totalUsage >= 16 * 1024 * 1024)
195 partitionsOutOfMemoryUsing16M(); 198 partitionsOutOfMemoryUsing16M();
196 partitionsOutOfMemoryUsingLessThan16M(); 199 partitionsOutOfMemoryUsingLessThan16M();
197 } 200 }
198 201
199 } // namespace WTF 202 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698