Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: base/memory/discardable_memory_mac.cc

Issue 458343003: Revert of base: Introduce an explicit call for reducing emulated discardable memory usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/memory/discardable_memory_linux.cc ('k') | base/memory/discardable_memory_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, TimeDelta::Max()) {} 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 mac::ScopedMachVM memory_; 153 mac::ScopedMachVM memory_;
150 const size_t bytes_; 154 const size_t bytes_;
151 bool is_locked_; 155 bool is_locked_;
152 156
153 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMac); 157 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMac);
154 }; 158 };
155 159
156 } // namespace 160 } // namespace
157 161
158 // static 162 // 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
159 bool DiscardableMemory::ReduceMemoryUsage() { 173 bool DiscardableMemory::ReduceMemoryUsage() {
160 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); 174 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
161 } 175 }
162 176
163 // static 177 // static
164 void DiscardableMemory::GetSupportedTypes( 178 void DiscardableMemory::GetSupportedTypes(
165 std::vector<DiscardableMemoryType>* types) { 179 std::vector<DiscardableMemoryType>* types) {
166 const DiscardableMemoryType supported_types[] = { 180 const DiscardableMemoryType supported_types[] = {
167 DISCARDABLE_MEMORY_TYPE_MAC, 181 DISCARDABLE_MEMORY_TYPE_MAC,
168 DISCARDABLE_MEMORY_TYPE_EMULATED, 182 DISCARDABLE_MEMORY_TYPE_EMULATED,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 222 }
209 223
210 // static 224 // static
211 void DiscardableMemory::PurgeForTesting() { 225 void DiscardableMemory::PurgeForTesting() {
212 int state = 0; 226 int state = 0;
213 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);
214 internal::DiscardableMemoryEmulated::PurgeForTesting(); 228 internal::DiscardableMemoryEmulated::PurgeForTesting();
215 } 229 }
216 230
217 } // namespace base 231 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_linux.cc ('k') | base/memory/discardable_memory_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698