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

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

Issue 336273003: base: Add soft memory limit to DiscardableMemoryManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac build Created 6 years, 5 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_emulated.h ('k') | base/memory/discardable_memory_linux.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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_emulated.h" 5 #include "base/memory/discardable_memory_emulated.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/discardable_memory_manager.h" 8 #include "base/memory/discardable_memory_manager.h"
9 9
10 namespace base { 10 namespace base {
11 namespace { 11 namespace {
12 12
13 // This is admittedly pretty magical. It's approximately enough memory for four 13 // This is admittedly pretty magical. It's approximately enough memory for four
14 // 2560x1600 images. 14 // 2560x1600 images.
15 const size_t kEmulatedMemoryLimit = 64 * 1024 * 1024; 15 const size_t kEmulatedMemoryLimit = 64 * 1024 * 1024;
16 const size_t kEmulatedBytesToKeepUnderModeratePressure = 16 const size_t kEmulatedBytesToKeepUnderModeratePressure =
17 kEmulatedMemoryLimit / 4; 17 kEmulatedMemoryLimit / 4;
18 18
19 struct SharedState { 19 struct SharedState {
20 SharedState() 20 SharedState()
21 : manager(kEmulatedMemoryLimit, 21 : manager(kEmulatedMemoryLimit,
22 kEmulatedBytesToKeepUnderModeratePressure) {} 22 kEmulatedMemoryLimit,
23 kEmulatedBytesToKeepUnderModeratePressure,
24 TimeDelta::Max()) {}
23 25
24 internal::DiscardableMemoryManager manager; 26 internal::DiscardableMemoryManager manager;
25 }; 27 };
26 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; 28 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER;
27 29
28 } // namespace 30 } // namespace
29 31
30 namespace internal { 32 namespace internal {
31 33
32 DiscardableMemoryEmulated::DiscardableMemoryEmulated(size_t bytes) 34 DiscardableMemoryEmulated::DiscardableMemoryEmulated(size_t bytes)
(...skipping 12 matching lines...) Expand all
45 void DiscardableMemoryEmulated::RegisterMemoryPressureListeners() { 47 void DiscardableMemoryEmulated::RegisterMemoryPressureListeners() {
46 g_shared_state.Pointer()->manager.RegisterMemoryPressureListener(); 48 g_shared_state.Pointer()->manager.RegisterMemoryPressureListener();
47 } 49 }
48 50
49 // static 51 // static
50 void DiscardableMemoryEmulated::UnregisterMemoryPressureListeners() { 52 void DiscardableMemoryEmulated::UnregisterMemoryPressureListeners() {
51 g_shared_state.Pointer()->manager.UnregisterMemoryPressureListener(); 53 g_shared_state.Pointer()->manager.UnregisterMemoryPressureListener();
52 } 54 }
53 55
54 // static 56 // static
57 bool DiscardableMemoryEmulated::ReduceMemoryUsage() {
58 return g_shared_state.Pointer()->manager.ReduceMemoryUsage();
59 }
60
61 // static
55 void DiscardableMemoryEmulated::PurgeForTesting() { 62 void DiscardableMemoryEmulated::PurgeForTesting() {
56 g_shared_state.Pointer()->manager.PurgeAll(); 63 g_shared_state.Pointer()->manager.PurgeAll();
57 } 64 }
58 65
59 bool DiscardableMemoryEmulated::Initialize() { 66 bool DiscardableMemoryEmulated::Initialize() {
60 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; 67 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
61 } 68 }
62 69
63 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() { 70 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() {
64 DCHECK(!is_locked_); 71 DCHECK(!is_locked_);
(...skipping 26 matching lines...) Expand all
91 memory_.reset(new uint8[bytes_]); 98 memory_.reset(new uint8[bytes_]);
92 return false; 99 return false;
93 } 100 }
94 101
95 void DiscardableMemoryEmulated::Purge() { 102 void DiscardableMemoryEmulated::Purge() {
96 memory_.reset(); 103 memory_.reset();
97 } 104 }
98 105
99 } // namespace internal 106 } // namespace internal
100 } // namespace base 107 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_emulated.h ('k') | base/memory/discardable_memory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698