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 { | |
16 | 15 |
17 // This is admittedly pretty magical. It's approximately enough memory for eight | 16 DiscardableMemoryManager::DiscardableMemoryManager( |
18 // 2560x1600 images. | 17 size_t memory_limit, |
19 static const size_t kDefaultMemoryLimit = 128 * 1024 * 1024; | 18 size_t bytes_to_keep_under_moderate_pressure) |
20 static const size_t kDefaultBytesToKeepUnderModeratePressure = 12 * 1024 * 1024; | |
21 | |
22 } // namespace | |
23 | |
24 DiscardableMemoryManager::DiscardableMemoryManager() | |
25 : allocations_(AllocationMap::NO_AUTO_EVICT), | 19 : allocations_(AllocationMap::NO_AUTO_EVICT), |
26 bytes_allocated_(0), | 20 bytes_allocated_(0), |
27 memory_limit_(kDefaultMemoryLimit), | 21 memory_limit_(memory_limit), |
28 bytes_to_keep_under_moderate_pressure_( | 22 bytes_to_keep_under_moderate_pressure_( |
29 kDefaultBytesToKeepUnderModeratePressure) { | 23 bytes_to_keep_under_moderate_pressure) { |
30 BytesAllocatedChanged(); | 24 BytesAllocatedChanged(); |
31 } | 25 } |
32 | 26 |
33 DiscardableMemoryManager::~DiscardableMemoryManager() { | 27 DiscardableMemoryManager::~DiscardableMemoryManager() { |
34 DCHECK(allocations_.empty()); | 28 DCHECK(allocations_.empty()); |
35 DCHECK_EQ(0u, bytes_allocated_); | 29 DCHECK_EQ(0u, bytes_allocated_); |
36 } | 30 } |
37 | 31 |
38 void DiscardableMemoryManager::RegisterMemoryPressureListener() { | 32 void DiscardableMemoryManager::RegisterMemoryPressureListener() { |
39 AutoLock lock(lock_); | 33 AutoLock lock(lock_); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { | 210 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { |
217 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); | 211 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); |
218 } | 212 } |
219 | 213 |
220 void DiscardableMemoryManager::BytesAllocatedChanged() const { | 214 void DiscardableMemoryManager::BytesAllocatedChanged() const { |
221 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); | 215 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); |
222 } | 216 } |
223 | 217 |
224 } // namespace internal | 218 } // namespace internal |
225 } // namespace base | 219 } // namespace base |
OLD | NEW |