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

Side by Side Diff: base/memory/discardable_memory_provider.h

Issue 59083011: base: Avoid purging more discardable memory than necessary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better comment Created 7 years, 1 month 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 | « no previous file | base/memory/discardable_memory_provider.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 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_
6 #define BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/containers/mru_cache.h" 10 #include "base/containers/mru_cache.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 static DiscardableMemoryProvider* GetInstance(); 49 static DiscardableMemoryProvider* GetInstance();
50 50
51 // Sets the instance of DiscardableMemoryProvider to be returned by 51 // Sets the instance of DiscardableMemoryProvider to be returned by
52 // GetInstance. This should only be used by tests and must be called 52 // GetInstance. This should only be used by tests and must be called
53 // prior to GetInstance(). The ownership of the given provider is 53 // prior to GetInstance(). The ownership of the given provider is
54 // retained by the caller. 54 // retained by the caller.
55 static void SetInstanceForTest(DiscardableMemoryProvider* provider); 55 static void SetInstanceForTest(DiscardableMemoryProvider* provider);
56 56
57 // The maximum number of bytes of discardable memory that may be allocated 57 // The maximum number of bytes of discardable memory that may be allocated
58 // before we assume moderate memory pressure. If this amount is zero, it is 58 // before we force a purge. If this amount is zero, it is interpreted as
59 // interpreted as having no limit at all. 59 // having no limit at all.
60 void SetDiscardableMemoryLimit(size_t bytes); 60 void SetDiscardableMemoryLimit(size_t bytes);
61 61
62 // Sets the amount of memory to reclaim when we're under moderate pressure. 62 // Sets the amount of memory to reclaim when we're under moderate pressure.
63 void SetBytesToReclaimUnderModeratePressure(size_t bytes); 63 void SetBytesToReclaimUnderModeratePressure(size_t bytes);
64 64
65 // Adds the given discardable memory to the provider's collection. 65 // Adds the given discardable memory to the provider's collection.
66 void Register(const DiscardableMemory* discardable, size_t bytes); 66 void Register(const DiscardableMemory* discardable, size_t bytes);
67 67
68 // Removes the given discardable memory from the provider's collection. 68 // Removes the given discardable memory from the provider's collection.
69 void Unregister(const DiscardableMemory* discardable); 69 void Unregister(const DiscardableMemory* discardable);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 size_t bytes; 104 size_t bytes;
105 uint8* memory; 105 uint8* memory;
106 }; 106 };
107 typedef HashingMRUCache<const DiscardableMemory*, Allocation> AllocationMap; 107 typedef HashingMRUCache<const DiscardableMemory*, Allocation> AllocationMap;
108 108
109 // This can be called as a hint that the system is under memory pressure. 109 // This can be called as a hint that the system is under memory pressure.
110 static void NotifyMemoryPressure( 110 static void NotifyMemoryPressure(
111 MemoryPressureListener::MemoryPressureLevel pressure_level); 111 MemoryPressureListener::MemoryPressureLevel pressure_level);
112 112
113 // Purges least recently used memory based on the value of 113 // Purges |bytes_to_reclaim_under_moderate_pressure_| bytes of
114 // |bytes_to_reclaim_under_moderate_pressure_|. 114 // discardable memory.
115 void Purge(); 115 void Purge();
116 116
117 // Purges least recently used memory until usage is less or equal to |limit|. 117 // Purges least recently used memory until usage is less or equal to |limit|.
118 // Caller must acquire |lock_| prior to calling this function. 118 // Caller must acquire |lock_| prior to calling this function.
119 void PurgeLRUWithLockAcquiredUntilUsageIsWithin(size_t limit); 119 void PurgeLRUWithLockAcquiredUntilUsageIsWithin(size_t limit);
120 120
121 // Ensures that we don't allocate beyond our memory limit. 121 // Ensures that we don't allocate beyond our memory limit.
122 // Caller must acquire |lock_| prior to calling this function. 122 // Caller must acquire |lock_| prior to calling this function.
123 void EnforcePolicyWithLockAcquired(); 123 void EnforcePolicyWithLockAcquired();
124 124
(...skipping 17 matching lines...) Expand all
142 // pressure. 142 // pressure.
143 MemoryPressureListener memory_pressure_listener_; 143 MemoryPressureListener memory_pressure_listener_;
144 144
145 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryProvider); 145 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryProvider);
146 }; 146 };
147 147
148 } // namespace internal 148 } // namespace internal
149 } // namespace base 149 } // namespace base
150 150
151 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ 151 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/discardable_memory_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698