OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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.h" | 5 #include "base/memory/discardable_memory.h" |
6 | 6 |
7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/mac/mach_logging.h" | 13 #include "base/mac/mach_logging.h" |
14 #include "base/mac/scoped_mach_vm.h" | 14 #include "base/mac/scoped_mach_vm.h" |
15 #include "base/memory/discardable_memory_emulated.h" | 15 #include "base/memory/discardable_memory_emulated.h" |
16 #include "base/memory/discardable_memory_malloc.h" | 16 #include "base/memory/discardable_memory_malloc.h" |
17 #include "base/memory/discardable_memory_manager.h" | 17 #include "base/memory/discardable_memory_manager.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 namespace { | 21 namespace { |
22 | 22 |
23 // For Mac, have the DiscardableMemoryManager trigger userspace eviction when | 23 // For Mac, have the DiscardableMemoryManager trigger userspace eviction when |
24 // address space usage gets too high (e.g. 512 MBytes). | 24 // address space usage gets too high (e.g. 512 MBytes). |
25 const size_t kMacMemoryLimit = 512 * 1024 * 1024; | 25 const size_t kMacMemoryLimit = 512 * 1024 * 1024; |
26 | 26 |
27 struct SharedState { | 27 struct SharedState { |
28 SharedState() : manager(kMacMemoryLimit, kMacMemoryLimit) {} | 28 SharedState() |
| 29 : manager(kMacMemoryLimit, |
| 30 kMacMemoryLimit, |
| 31 kMacMemoryLimit, |
| 32 TimeDelta::Max()) {} |
29 | 33 |
30 internal::DiscardableMemoryManager manager; | 34 internal::DiscardableMemoryManager manager; |
31 }; | 35 }; |
32 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; | 36 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; |
33 | 37 |
34 // The VM subsystem allows tagging of memory and 240-255 is reserved for | 38 // The VM subsystem allows tagging of memory and 240-255 is reserved for |
35 // application use (see mach/vm_statistics.h). Pick 252 (after chromium's atomic | 39 // application use (see mach/vm_statistics.h). Pick 252 (after chromium's atomic |
36 // weight of ~52). | 40 // weight of ~52). |
37 const int kDiscardableMemoryTag = VM_MAKE_TAG(252); | 41 const int kDiscardableMemoryTag = VM_MAKE_TAG(252); |
38 | 42 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 void DiscardableMemory::RegisterMemoryPressureListeners() { | 163 void DiscardableMemory::RegisterMemoryPressureListeners() { |
160 internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners(); | 164 internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners(); |
161 } | 165 } |
162 | 166 |
163 // static | 167 // static |
164 void DiscardableMemory::UnregisterMemoryPressureListeners() { | 168 void DiscardableMemory::UnregisterMemoryPressureListeners() { |
165 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners(); | 169 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners(); |
166 } | 170 } |
167 | 171 |
168 // static | 172 // static |
| 173 bool DiscardableMemory::ReduceMemoryUsage() { |
| 174 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); |
| 175 } |
| 176 |
| 177 // static |
169 void DiscardableMemory::GetSupportedTypes( | 178 void DiscardableMemory::GetSupportedTypes( |
170 std::vector<DiscardableMemoryType>* types) { | 179 std::vector<DiscardableMemoryType>* types) { |
171 const DiscardableMemoryType supported_types[] = { | 180 const DiscardableMemoryType supported_types[] = { |
172 DISCARDABLE_MEMORY_TYPE_MAC, | 181 DISCARDABLE_MEMORY_TYPE_MAC, |
173 DISCARDABLE_MEMORY_TYPE_EMULATED, | 182 DISCARDABLE_MEMORY_TYPE_EMULATED, |
174 DISCARDABLE_MEMORY_TYPE_MALLOC | 183 DISCARDABLE_MEMORY_TYPE_MALLOC |
175 }; | 184 }; |
176 types->assign(supported_types, supported_types + arraysize(supported_types)); | 185 types->assign(supported_types, supported_types + arraysize(supported_types)); |
177 } | 186 } |
178 | 187 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 222 } |
214 | 223 |
215 // static | 224 // static |
216 void DiscardableMemory::PurgeForTesting() { | 225 void DiscardableMemory::PurgeForTesting() { |
217 int state = 0; | 226 int state = 0; |
218 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); | 227 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); |
219 internal::DiscardableMemoryEmulated::PurgeForTesting(); | 228 internal::DiscardableMemoryEmulated::PurgeForTesting(); |
220 } | 229 } |
221 | 230 |
222 } // namespace base | 231 } // namespace base |
OLD | NEW |