| 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 "base/memory/discardable_memory_manager.h" | 5 #include "base/memory/discardable_memory_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
| 9 #include "base/containers/mru_cache.h" | 9 #include "base/containers/mru_cache.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 namespace internal { | 14 namespace internal { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // This is admittedly pretty magical. It's approximately enough memory for four | 17 // This is admittedly pretty magical. It's approximately enough memory for eight |
| 18 // 2560x1600 images. | 18 // 2560x1600 images. |
| 19 static const size_t kDefaultMemoryLimit = 64 * 1024 * 1024; | 19 static const size_t kDefaultMemoryLimit = 128 * 1024 * 1024; |
| 20 static const size_t kDefaultBytesToKeepUnderModeratePressure = | 20 static const size_t kDefaultBytesToKeepUnderModeratePressure = 12 * 1024 * 1024; |
| 21 kDefaultMemoryLimit / 4; | |
| 22 | 21 |
| 23 } // namespace | 22 } // namespace |
| 24 | 23 |
| 25 DiscardableMemoryManager::DiscardableMemoryManager() | 24 DiscardableMemoryManager::DiscardableMemoryManager() |
| 26 : allocations_(AllocationMap::NO_AUTO_EVICT), | 25 : allocations_(AllocationMap::NO_AUTO_EVICT), |
| 27 bytes_allocated_(0), | 26 bytes_allocated_(0), |
| 28 memory_limit_(kDefaultMemoryLimit), | 27 memory_limit_(kDefaultMemoryLimit), |
| 29 bytes_to_keep_under_moderate_pressure_( | 28 bytes_to_keep_under_moderate_pressure_( |
| 30 kDefaultBytesToKeepUnderModeratePressure) { | 29 kDefaultBytesToKeepUnderModeratePressure) { |
| 31 BytesAllocatedChanged(); | 30 BytesAllocatedChanged(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { | 216 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { |
| 218 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); | 217 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); |
| 219 } | 218 } |
| 220 | 219 |
| 221 void DiscardableMemoryManager::BytesAllocatedChanged() const { | 220 void DiscardableMemoryManager::BytesAllocatedChanged() const { |
| 222 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); | 221 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); |
| 223 } | 222 } |
| 224 | 223 |
| 225 } // namespace internal | 224 } // namespace internal |
| 226 } // namespace base | 225 } // namespace base |
| OLD | NEW |