OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/child_discardable_shared_memory_manager.h" | 5 #include "content/child/child_discardable_shared_memory_manager.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 DCHECK(!free_span->shared_memory()); | 160 DCHECK(!free_span->shared_memory()); |
161 continue; | 161 continue; |
162 } | 162 } |
163 | 163 |
164 free_span->set_is_locked(true); | 164 free_span->set_is_locked(true); |
165 | 165 |
166 // Memory usage is guaranteed to have changed after having removed | 166 // Memory usage is guaranteed to have changed after having removed |
167 // at least one span from the free lists. | 167 // at least one span from the free lists. |
168 MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists()); | 168 MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists()); |
169 | 169 |
170 return base::WrapUnique( | 170 return base::MakeUnique<DiscardableMemoryImpl>(this, std::move(free_span)); |
171 new DiscardableMemoryImpl(this, std::move(free_span))); | |
172 } | 171 } |
173 | 172 |
174 // Release purged memory to free up the address space before we attempt to | 173 // Release purged memory to free up the address space before we attempt to |
175 // allocate more memory. | 174 // allocate more memory. |
176 heap_.ReleasePurgedMemory(); | 175 heap_.ReleasePurgedMemory(); |
177 | 176 |
178 // Make sure crash keys are up to date in case allocation fails. | 177 // Make sure crash keys are up to date in case allocation fails. |
179 if (heap_.GetSize() != heap_size_prior_to_releasing_purged_memory) | 178 if (heap_.GetSize() != heap_size_prior_to_releasing_purged_memory) |
180 MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists()); | 179 MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists()); |
181 | 180 |
(...skipping 21 matching lines...) Expand all Loading... |
203 leftover->shared_memory()->Unlock( | 202 leftover->shared_memory()->Unlock( |
204 leftover->start() * base::GetPageSize() - | 203 leftover->start() * base::GetPageSize() - |
205 reinterpret_cast<size_t>(leftover->shared_memory()->memory()), | 204 reinterpret_cast<size_t>(leftover->shared_memory()->memory()), |
206 leftover->length() * base::GetPageSize()); | 205 leftover->length() * base::GetPageSize()); |
207 leftover->set_is_locked(false); | 206 leftover->set_is_locked(false); |
208 heap_.MergeIntoFreeLists(std::move(leftover)); | 207 heap_.MergeIntoFreeLists(std::move(leftover)); |
209 } | 208 } |
210 | 209 |
211 MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists()); | 210 MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists()); |
212 | 211 |
213 return base::WrapUnique(new DiscardableMemoryImpl(this, std::move(new_span))); | 212 return base::MakeUnique<DiscardableMemoryImpl>(this, std::move(new_span)); |
214 } | 213 } |
215 | 214 |
216 bool ChildDiscardableSharedMemoryManager::OnMemoryDump( | 215 bool ChildDiscardableSharedMemoryManager::OnMemoryDump( |
217 const base::trace_event::MemoryDumpArgs& args, | 216 const base::trace_event::MemoryDumpArgs& args, |
218 base::trace_event::ProcessMemoryDump* pmd) { | 217 base::trace_event::ProcessMemoryDump* pmd) { |
219 base::AutoLock lock(lock_); | 218 base::AutoLock lock(lock_); |
220 if (args.level_of_detail == | 219 if (args.level_of_detail == |
221 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { | 220 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { |
222 base::trace_event::MemoryAllocatorDump* total_dump = | 221 base::trace_event::MemoryAllocatorDump* total_dump = |
223 pmd->CreateAllocatorDump( | 222 pmd->CreateAllocatorDump( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 "discardable-memory-allocated"; | 339 "discardable-memory-allocated"; |
341 base::debug::SetCrashKeyValue(kDiscardableMemoryAllocatedKey, | 340 base::debug::SetCrashKeyValue(kDiscardableMemoryAllocatedKey, |
342 base::Uint64ToString(new_bytes_total)); | 341 base::Uint64ToString(new_bytes_total)); |
343 | 342 |
344 static const char kDiscardableMemoryFreeKey[] = "discardable-memory-free"; | 343 static const char kDiscardableMemoryFreeKey[] = "discardable-memory-free"; |
345 base::debug::SetCrashKeyValue(kDiscardableMemoryFreeKey, | 344 base::debug::SetCrashKeyValue(kDiscardableMemoryFreeKey, |
346 base::Uint64ToString(new_bytes_free)); | 345 base::Uint64ToString(new_bytes_free)); |
347 } | 346 } |
348 | 347 |
349 } // namespace content | 348 } // namespace content |
OLD | NEW |