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

Side by Side Diff: base/memory/discardable_memory_android.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.h ('k') | base/memory/discardable_memory_emulated.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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 14 matching lines...) Expand all
25 25
26 size_t GetOptimalAshmemRegionSizeForAllocator() { 26 size_t GetOptimalAshmemRegionSizeForAllocator() {
27 // Note that this may do some I/O (without hitting the disk though) so it 27 // Note that this may do some I/O (without hitting the disk though) so it
28 // should not be called on the critical path. 28 // should not be called on the critical path.
29 return base::SysInfo::AmountOfPhysicalMemory() / 8; 29 return base::SysInfo::AmountOfPhysicalMemory() / 8;
30 } 30 }
31 31
32 // Holds the shared state used for allocations. 32 // Holds the shared state used for allocations.
33 struct SharedState { 33 struct SharedState {
34 SharedState() 34 SharedState()
35 : manager(kAshmemMemoryLimit, kAshmemMemoryLimit), 35 : manager(kAshmemMemoryLimit,
36 kAshmemMemoryLimit,
37 kAshmemMemoryLimit,
38 TimeDelta::Max()),
36 allocator(kAshmemAllocatorName, 39 allocator(kAshmemAllocatorName,
37 GetOptimalAshmemRegionSizeForAllocator()) {} 40 GetOptimalAshmemRegionSizeForAllocator()) {}
38 41
39 internal::DiscardableMemoryManager manager; 42 internal::DiscardableMemoryManager manager;
40 internal::DiscardableMemoryAshmemAllocator allocator; 43 internal::DiscardableMemoryAshmemAllocator allocator;
41 }; 44 };
42 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; 45 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER;
43 46
44 } // namespace 47 } // namespace
45 48
46 // static 49 // static
47 void DiscardableMemory::RegisterMemoryPressureListeners() { 50 void DiscardableMemory::RegisterMemoryPressureListeners() {
48 internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners(); 51 internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners();
49 } 52 }
50 53
51 // static 54 // static
52 void DiscardableMemory::UnregisterMemoryPressureListeners() { 55 void DiscardableMemory::UnregisterMemoryPressureListeners() {
53 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners(); 56 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners();
54 } 57 }
55 58
56 // static 59 // static
60 bool DiscardableMemory::ReduceMemoryUsage() {
61 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
62 }
63
64 // static
57 void DiscardableMemory::GetSupportedTypes( 65 void DiscardableMemory::GetSupportedTypes(
58 std::vector<DiscardableMemoryType>* types) { 66 std::vector<DiscardableMemoryType>* types) {
59 const DiscardableMemoryType supported_types[] = { 67 const DiscardableMemoryType supported_types[] = {
60 DISCARDABLE_MEMORY_TYPE_ASHMEM, 68 DISCARDABLE_MEMORY_TYPE_ASHMEM,
61 DISCARDABLE_MEMORY_TYPE_EMULATED, 69 DISCARDABLE_MEMORY_TYPE_EMULATED,
62 DISCARDABLE_MEMORY_TYPE_MALLOC 70 DISCARDABLE_MEMORY_TYPE_MALLOC
63 }; 71 };
64 types->assign(supported_types, supported_types + arraysize(supported_types)); 72 types->assign(supported_types, supported_types + arraysize(supported_types));
65 } 73 }
66 74
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return scoped_ptr<DiscardableMemory>(); 111 return scoped_ptr<DiscardableMemory>();
104 } 112 }
105 113
106 // static 114 // static
107 void DiscardableMemory::PurgeForTesting() { 115 void DiscardableMemory::PurgeForTesting() {
108 g_shared_state.Pointer()->manager.PurgeAll(); 116 g_shared_state.Pointer()->manager.PurgeAll();
109 internal::DiscardableMemoryEmulated::PurgeForTesting(); 117 internal::DiscardableMemoryEmulated::PurgeForTesting();
110 } 118 }
111 119
112 } // namespace base 120 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory.h ('k') | base/memory/discardable_memory_emulated.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698