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() | 28 SharedState() : manager(kMacMemoryLimit, kMacMemoryLimit, TimeDelta::Max()) {} |
29 : manager(kMacMemoryLimit, | |
30 kMacMemoryLimit, | |
31 kMacMemoryLimit, | |
32 TimeDelta::Max()) {} | |
33 | 29 |
34 internal::DiscardableMemoryManager manager; | 30 internal::DiscardableMemoryManager manager; |
35 }; | 31 }; |
36 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; | 32 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; |
37 | 33 |
38 // The VM subsystem allows tagging of memory and 240-255 is reserved for | 34 // The VM subsystem allows tagging of memory and 240-255 is reserved for |
39 // application use (see mach/vm_statistics.h). Pick 252 (after chromium's atomic | 35 // application use (see mach/vm_statistics.h). Pick 252 (after chromium's atomic |
40 // weight of ~52). | 36 // weight of ~52). |
41 const int kDiscardableMemoryTag = VM_MAKE_TAG(252); | 37 const int kDiscardableMemoryTag = VM_MAKE_TAG(252); |
42 | 38 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 mac::ScopedMachVM memory_; | 149 mac::ScopedMachVM memory_; |
154 const size_t bytes_; | 150 const size_t bytes_; |
155 bool is_locked_; | 151 bool is_locked_; |
156 | 152 |
157 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMac); | 153 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMac); |
158 }; | 154 }; |
159 | 155 |
160 } // namespace | 156 } // namespace |
161 | 157 |
162 // static | 158 // static |
163 void DiscardableMemory::RegisterMemoryPressureListeners() { | |
164 internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners(); | |
165 } | |
166 | |
167 // static | |
168 void DiscardableMemory::UnregisterMemoryPressureListeners() { | |
169 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners(); | |
170 } | |
171 | |
172 // static | |
173 bool DiscardableMemory::ReduceMemoryUsage() { | 159 bool DiscardableMemory::ReduceMemoryUsage() { |
174 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); | 160 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); |
175 } | 161 } |
176 | 162 |
177 // static | 163 // static |
178 void DiscardableMemory::GetSupportedTypes( | 164 void DiscardableMemory::GetSupportedTypes( |
179 std::vector<DiscardableMemoryType>* types) { | 165 std::vector<DiscardableMemoryType>* types) { |
180 const DiscardableMemoryType supported_types[] = { | 166 const DiscardableMemoryType supported_types[] = { |
181 DISCARDABLE_MEMORY_TYPE_MAC, | 167 DISCARDABLE_MEMORY_TYPE_MAC, |
182 DISCARDABLE_MEMORY_TYPE_EMULATED, | 168 DISCARDABLE_MEMORY_TYPE_EMULATED, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 208 } |
223 | 209 |
224 // static | 210 // static |
225 void DiscardableMemory::PurgeForTesting() { | 211 void DiscardableMemory::PurgeForTesting() { |
226 int state = 0; | 212 int state = 0; |
227 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); | 213 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); |
228 internal::DiscardableMemoryEmulated::PurgeForTesting(); | 214 internal::DiscardableMemoryEmulated::PurgeForTesting(); |
229 } | 215 } |
230 | 216 |
231 } // namespace base | 217 } // namespace base |
OLD | NEW |