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

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

Powered by Google App Engine
This is Rietveld 408576698