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

Side by Side Diff: components/web_cache/browser/web_cache_manager.h

Issue 2435603002: [WeakMemoryCache] Remove dead/live distinction of Resource outside core/fetch (Closed)
Patch Set: Rebase, rename capacities to capacity Created 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This is the browser side of the cache manager, it tracks the activity of the 5 // This is the browser side of the cache manager, it tracks the activity of the
6 // render processes and allocates available memory cache resources. 6 // render processes and allocates available memory cache resources.
7 7
8 #ifndef COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ 8 #ifndef COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_
9 #define COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ 9 #define COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // cache resources. 77 // cache resources.
78 // 78 //
79 // When a renderer moves from being inactive to being active, the cache 79 // When a renderer moves from being inactive to being active, the cache
80 // manager may decide to adjust its resource allocation, but it will delay 80 // manager may decide to adjust its resource allocation, but it will delay
81 // the recalculation, allowing ObserveActivity to return quickly. 81 // the recalculation, allowing ObserveActivity to return quickly.
82 void ObserveActivity(int renderer_id); 82 void ObserveActivity(int renderer_id);
83 83
84 // Periodically, renderers should inform the cache manager of their current 84 // Periodically, renderers should inform the cache manager of their current
85 // statistics. The more up-to-date the cache manager's statistics, the 85 // statistics. The more up-to-date the cache manager's statistics, the
86 // better it can allocate cache resources. 86 // better it can allocate cache resources.
87 void ObserveStats(int renderer_id, 87 void ObserveStats(int renderer_id, uint64_t capacity, uint64_t size);
88 uint64_t min_dead_capacity,
89 uint64_t max_dead_capacity,
90 uint64_t capacity,
91 uint64_t live_size,
92 uint64_t dead_size);
93 88
94 // The global limit on the number of bytes in all the in-memory caches. 89 // The global limit on the number of bytes in all the in-memory caches.
95 uint64_t global_size_limit() const { return global_size_limit_; } 90 uint64_t global_size_limit() const { return global_size_limit_; }
96 91
97 // Sets the global size limit, forcing a recalculation of cache allocations. 92 // Sets the global size limit, forcing a recalculation of cache allocations.
98 void SetGlobalSizeLimit(uint64_t bytes); 93 void SetGlobalSizeLimit(uint64_t bytes);
99 94
100 // Clears all in-memory caches. 95 // Clears all in-memory caches.
101 void ClearCache(); 96 void ClearCache();
102 97
(...skipping 15 matching lines...) Expand all
118 static uint64_t GetDefaultGlobalSizeLimit(); 113 static uint64_t GetDefaultGlobalSizeLimit();
119 114
120 protected: 115 protected:
121 // The amount of idle time before we consider a tab to be "inactive" 116 // The amount of idle time before we consider a tab to be "inactive"
122 static const int kRendererInactiveThresholdMinutes = 5; 117 static const int kRendererInactiveThresholdMinutes = 5;
123 118
124 // Keep track of some renderer information. 119 // Keep track of some renderer information.
125 struct RendererInfo { 120 struct RendererInfo {
126 // The access time for this renderer. 121 // The access time for this renderer.
127 base::Time access; 122 base::Time access;
128 uint64_t min_dead_capacity;
129 uint64_t max_dead_capacity;
130 uint64_t capacity; 123 uint64_t capacity;
131 uint64_t live_size; 124 uint64_t size;
132 uint64_t dead_size;
133 }; 125 };
134 126
135 typedef std::map<int, RendererInfo> StatsMap; 127 typedef std::map<int, RendererInfo> StatsMap;
136 128
137 // An allocation is the number of bytes a specific renderer should use for 129 // An allocation is the number of bytes a specific renderer should use for
138 // its cache. 130 // its cache.
139 typedef std::pair<int,uint64_t> Allocation; 131 typedef std::pair<int,uint64_t> Allocation;
140 132
141 // An allocation strategy is a list of allocations specifying the resources 133 // An allocation strategy is a list of allocations specifying the resources
142 // each renderer is permitted to consume for its cache. 134 // each renderer is permitted to consume for its cache.
(...skipping 27 matching lines...) Expand all
170 // Ignore cache statistics and divide resources equally among the given 162 // Ignore cache statistics and divide resources equally among the given
171 // set of caches. 163 // set of caches.
172 DIVIDE_EVENLY, 164 DIVIDE_EVENLY,
173 165
174 // Allow each renderer to keep its current set of cached resources, with 166 // Allow each renderer to keep its current set of cached resources, with
175 // some extra allocation to store new objects. 167 // some extra allocation to store new objects.
176 KEEP_CURRENT_WITH_HEADROOM, 168 KEEP_CURRENT_WITH_HEADROOM,
177 169
178 // Allow each renderer to keep its current set of cached resources. 170 // Allow each renderer to keep its current set of cached resources.
179 KEEP_CURRENT, 171 KEEP_CURRENT,
180
181 // Allow each renderer to keep cache resources it believes are currently
182 // being used, with some extra allocation to store new objects.
183 KEEP_LIVE_WITH_HEADROOM,
184
185 // Allow each renderer to keep cache resources it believes are currently
186 // being used, but instruct the renderer to discard all other data.
187 KEEP_LIVE,
188 }; 172 };
189 173
190 // Helper functions for devising an allocation strategy 174 // Helper functions for devising an allocation strategy
191 175
192 // Add up all the stats from the given set of renderers and place the result 176 // Add up all the stats from the given set of renderers and place the result
193 // in the given parameters. 177 // in the given parameters.
194 void GatherStats(const std::set<int>& renderers, 178 void GatherStats(const std::set<int>& renderers,
195 uint64_t* capacity, 179 uint64_t* capacity,
196 uint64_t* live_size, 180 uint64_t* size);
197 uint64_t* dead_size);
198 181
199 // Get the amount of memory that would be required to implement |tactic| 182 // Get the amount of memory that would be required to implement |tactic|
200 // using the specified allocation tactic. This function defines the 183 // using the specified allocation tactic. This function defines the
201 // semantics for each of the tactics. 184 // semantics for each of the tactics.
202 static uint64_t GetSize(AllocationTactic tactic, 185 static uint64_t GetSize(AllocationTactic tactic, uint64_t size);
203 uint64_t live_size,
204 uint64_t dead_size);
205 186
206 // Attempt to use the specified tactics to compute an allocation strategy 187 // Attempt to use the specified tactics to compute an allocation strategy
207 // and place the result in |strategy|. |active_stats| and |inactive_stats| 188 // and place the result in |strategy|. |active_stats| and |inactive_stats|
208 // are the aggregate statistics for |active_renderers_| and 189 // are the aggregate statistics for |active_renderers_| and
209 // |inactive_renderers_|, respectively. 190 // |inactive_renderers_|, respectively.
210 // 191 //
211 // Returns |true| on success and |false| on failure. Does not modify 192 // Returns |true| on success and |false| on failure. Does not modify
212 // |strategy| on failure. 193 // |strategy| on failure.
213 bool AttemptTactic(AllocationTactic active_tactic, 194 bool AttemptTactic(AllocationTactic active_tactic,
214 uint64_t active_live_size, 195 uint64_t active_size,
215 uint64_t active_dead_size,
216 AllocationTactic inactive_tactic, 196 AllocationTactic inactive_tactic,
217 uint64_t inactive_live_size, 197 uint64_t inactive_size,
218 uint64_t inactive_dead_size,
219 AllocationStrategy* strategy); 198 AllocationStrategy* strategy);
220 199
221 // For each renderer in |renderers|, computes its allocation according to 200 // For each renderer in |renderers|, computes its allocation according to
222 // |tactic| and add the result to |strategy|. Any |extra_bytes_to_allocate| 201 // |tactic| and add the result to |strategy|. Any |extra_bytes_to_allocate|
223 // is divided evenly among the renderers. 202 // is divided evenly among the renderers.
224 void AddToStrategy(const std::set<int>& renderers, 203 void AddToStrategy(const std::set<int>& renderers,
225 AllocationTactic tactic, 204 AllocationTactic tactic,
226 uint64_t extra_bytes_to_allocate, 205 uint64_t extra_bytes_to_allocate,
227 AllocationStrategy* strategy); 206 AllocationStrategy* strategy);
228 207
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 WebCacheServicesMap web_cache_services_; 245 WebCacheServicesMap web_cache_services_;
267 246
268 base::WeakPtrFactory<WebCacheManager> weak_factory_; 247 base::WeakPtrFactory<WebCacheManager> weak_factory_;
269 248
270 DISALLOW_COPY_AND_ASSIGN(WebCacheManager); 249 DISALLOW_COPY_AND_ASSIGN(WebCacheManager);
271 }; 250 };
272 251
273 } // namespace web_cache 252 } // namespace web_cache
274 253
275 #endif // COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_ 254 #endif // COMPONENTS_WEB_CACHE_BROWSER_WEB_CACHE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698