| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 base::PartitionAllocatorGeneric Partitions::m_bufferAllocator; | 46 base::PartitionAllocatorGeneric Partitions::m_bufferAllocator; |
| 47 base::SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; | 47 base::SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; |
| 48 Partitions::ReportPartitionAllocSizeFunction Partitions::m_reportSizeFunction = | 48 Partitions::ReportPartitionAllocSizeFunction Partitions::m_reportSizeFunction = |
| 49 nullptr; | 49 nullptr; |
| 50 | 50 |
| 51 void Partitions::initialize( | 51 void Partitions::initialize( |
| 52 ReportPartitionAllocSizeFunction reportSizeFunction) { | 52 ReportPartitionAllocSizeFunction reportSizeFunction) { |
| 53 base::subtle::SpinLock::Guard guard(s_initializationLock); | 53 base::subtle::SpinLock::Guard guard(s_initializationLock); |
| 54 | 54 |
| 55 if (!s_initialized) { | 55 if (!s_initialized) { |
| 56 base::partitionAllocGlobalInit(&Partitions::handleOutOfMemory); | 56 base::PartitionAllocGlobalInit(&Partitions::handleOutOfMemory); |
| 57 m_fastMallocAllocator.init(); | 57 m_fastMallocAllocator.init(); |
| 58 m_bufferAllocator.init(); | 58 m_bufferAllocator.init(); |
| 59 m_layoutAllocator.init(); | 59 m_layoutAllocator.init(); |
| 60 m_reportSizeFunction = reportSizeFunction; | 60 m_reportSizeFunction = reportSizeFunction; |
| 61 s_initialized = true; | 61 s_initialized = true; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void Partitions::shutdown() { | 65 void Partitions::shutdown() { |
| 66 base::subtle::SpinLock::Guard guard(s_initializationLock); | 66 base::subtle::SpinLock::Guard guard(s_initializationLock); |
| 67 | 67 |
| 68 // 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 |
| 69 // 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 |
| 70 // the valgrind and heapcheck bots, which run without partitions. | 70 // the valgrind and heapcheck bots, which run without partitions. |
| 71 if (s_initialized) { | 71 if (s_initialized) { |
| 72 (void)m_layoutAllocator.shutdown(); | 72 (void)m_layoutAllocator.shutdown(); |
| 73 (void)m_bufferAllocator.shutdown(); | 73 (void)m_bufferAllocator.shutdown(); |
| 74 (void)m_fastMallocAllocator.shutdown(); | 74 (void)m_fastMallocAllocator.shutdown(); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 void Partitions::decommitFreeableMemory() { | 78 void Partitions::decommitFreeableMemory() { |
| 79 RELEASE_ASSERT(isMainThread()); | 79 RELEASE_ASSERT(isMainThread()); |
| 80 if (!s_initialized) | 80 if (!s_initialized) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 partitionPurgeMemoryGeneric(bufferPartition(), | 83 PartitionPurgeMemoryGeneric(bufferPartition(), |
| 84 base::PartitionPurgeDecommitEmptyPages); | 84 base::PartitionPurgeDecommitEmptyPages); |
| 85 partitionPurgeMemoryGeneric(fastMallocPartition(), | 85 PartitionPurgeMemoryGeneric(fastMallocPartition(), |
| 86 base::PartitionPurgeDecommitEmptyPages); | 86 base::PartitionPurgeDecommitEmptyPages); |
| 87 partitionPurgeMemory(layoutPartition(), | 87 PartitionPurgeMemory(layoutPartition(), |
| 88 base::PartitionPurgeDecommitEmptyPages); | 88 base::PartitionPurgeDecommitEmptyPages); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void Partitions::reportMemoryUsageHistogram() { | 91 void Partitions::reportMemoryUsageHistogram() { |
| 92 static size_t observedMaxSizeInMB = 0; | 92 static size_t observedMaxSizeInMB = 0; |
| 93 | 93 |
| 94 if (!m_reportSizeFunction) | 94 if (!m_reportSizeFunction) |
| 95 return; | 95 return; |
| 96 // We only report the memory in the main thread. | 96 // We only report the memory in the main thread. |
| 97 if (!isMainThread()) | 97 if (!isMainThread()) |
| 98 return; | 98 return; |
| 99 // +1 is for rounding up the sizeInMB. | 99 // +1 is for rounding up the sizeInMB. |
| 100 size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1; | 100 size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1; |
| 101 if (sizeInMB > observedMaxSizeInMB) { | 101 if (sizeInMB > observedMaxSizeInMB) { |
| 102 m_reportSizeFunction(sizeInMB); | 102 m_reportSizeFunction(sizeInMB); |
| 103 observedMaxSizeInMB = sizeInMB; | 103 observedMaxSizeInMB = sizeInMB; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 void Partitions::dumpMemoryStats( | 107 void Partitions::dumpMemoryStats( |
| 108 bool isLightDump, | 108 bool isLightDump, |
| 109 base::PartitionStatsDumper* partitionStatsDumper) { | 109 base::PartitionStatsDumper* partitionStatsDumper) { |
| 110 // 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 |
| 111 // accessed only on the main thread. | 111 // accessed only on the main thread. |
| 112 DCHECK(isMainThread()); | 112 DCHECK(isMainThread()); |
| 113 | 113 |
| 114 decommitFreeableMemory(); | 114 decommitFreeableMemory(); |
| 115 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump, | 115 PartitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump, |
| 116 partitionStatsDumper); | 116 partitionStatsDumper); |
| 117 partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, | 117 PartitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, |
| 118 partitionStatsDumper); | 118 partitionStatsDumper); |
| 119 partitionDumpStats(layoutPartition(), "layout", isLightDump, | 119 PartitionDumpStats(layoutPartition(), "layout", isLightDump, |
| 120 partitionStatsDumper); | 120 partitionStatsDumper); |
| 121 } | 121 } |
| 122 | 122 |
| 123 static NEVER_INLINE void partitionsOutOfMemoryUsing2G() { | 123 static NEVER_INLINE void partitionsOutOfMemoryUsing2G() { |
| 124 size_t signature = 2UL * 1024 * 1024 * 1024; | 124 size_t signature = 2UL * 1024 * 1024 * 1024; |
| 125 base::debug::Alias(&signature); | 125 base::debug::Alias(&signature); |
| 126 OOM_CRASH(); | 126 OOM_CRASH(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 static NEVER_INLINE void partitionsOutOfMemoryUsing1G() { | 129 static NEVER_INLINE void partitionsOutOfMemoryUsing1G() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 static NEVER_INLINE void partitionsOutOfMemoryUsing16M() { | 165 static NEVER_INLINE void partitionsOutOfMemoryUsing16M() { |
| 166 size_t signature = 16 * 1024 * 1024; | 166 size_t signature = 16 * 1024 * 1024; |
| 167 base::debug::Alias(&signature); | 167 base::debug::Alias(&signature); |
| 168 OOM_CRASH(); | 168 OOM_CRASH(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 static NEVER_INLINE void partitionsOutOfMemoryUsingLessThan16M() { | 171 static NEVER_INLINE void partitionsOutOfMemoryUsingLessThan16M() { |
| 172 size_t signature = 16 * 1024 * 1024 - 1; | 172 size_t signature = 16 * 1024 * 1024 - 1; |
| 173 base::debug::Alias(&signature); | 173 base::debug::Alias(&signature); |
| 174 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage (error:" | 174 DLOG(FATAL) << "ParitionAlloc: out of memory with < 16M usage (error:" |
| 175 << getAllocPageErrorCode() << ")"; | 175 << GetAllocPageErrorCode() << ")"; |
| 176 } | 176 } |
| 177 | 177 |
| 178 void Partitions::handleOutOfMemory() { | 178 void Partitions::handleOutOfMemory() { |
| 179 volatile size_t totalUsage = totalSizeOfCommittedPages(); | 179 volatile size_t totalUsage = totalSizeOfCommittedPages(); |
| 180 uint32_t allocPageErrorCode = getAllocPageErrorCode(); | 180 uint32_t allocPageErrorCode = GetAllocPageErrorCode(); |
| 181 base::debug::Alias(&allocPageErrorCode); | 181 base::debug::Alias(&allocPageErrorCode); |
| 182 | 182 |
| 183 if (totalUsage >= 2UL * 1024 * 1024 * 1024) | 183 if (totalUsage >= 2UL * 1024 * 1024 * 1024) |
| 184 partitionsOutOfMemoryUsing2G(); | 184 partitionsOutOfMemoryUsing2G(); |
| 185 if (totalUsage >= 1UL * 1024 * 1024 * 1024) | 185 if (totalUsage >= 1UL * 1024 * 1024 * 1024) |
| 186 partitionsOutOfMemoryUsing1G(); | 186 partitionsOutOfMemoryUsing1G(); |
| 187 if (totalUsage >= 512 * 1024 * 1024) | 187 if (totalUsage >= 512 * 1024 * 1024) |
| 188 partitionsOutOfMemoryUsing512M(); | 188 partitionsOutOfMemoryUsing512M(); |
| 189 if (totalUsage >= 256 * 1024 * 1024) | 189 if (totalUsage >= 256 * 1024 * 1024) |
| 190 partitionsOutOfMemoryUsing256M(); | 190 partitionsOutOfMemoryUsing256M(); |
| 191 if (totalUsage >= 128 * 1024 * 1024) | 191 if (totalUsage >= 128 * 1024 * 1024) |
| 192 partitionsOutOfMemoryUsing128M(); | 192 partitionsOutOfMemoryUsing128M(); |
| 193 if (totalUsage >= 64 * 1024 * 1024) | 193 if (totalUsage >= 64 * 1024 * 1024) |
| 194 partitionsOutOfMemoryUsing64M(); | 194 partitionsOutOfMemoryUsing64M(); |
| 195 if (totalUsage >= 32 * 1024 * 1024) | 195 if (totalUsage >= 32 * 1024 * 1024) |
| 196 partitionsOutOfMemoryUsing32M(); | 196 partitionsOutOfMemoryUsing32M(); |
| 197 if (totalUsage >= 16 * 1024 * 1024) | 197 if (totalUsage >= 16 * 1024 * 1024) |
| 198 partitionsOutOfMemoryUsing16M(); | 198 partitionsOutOfMemoryUsing16M(); |
| 199 partitionsOutOfMemoryUsingLessThan16M(); | 199 partitionsOutOfMemoryUsingLessThan16M(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 } // namespace WTF | 202 } // namespace WTF |
| OLD | NEW |