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

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 2763933002: memory coordinator: Purge memory under memory pressure (Closed)
Patch Set: comments Created 3 years, 8 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
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/render_thread_impl.h" 5 #include "content/renderer/render_thread_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 } 2228 }
2229 2229
2230 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { 2230 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) {
2231 if (blink_platform_impl_) { 2231 if (blink_platform_impl_) {
2232 blink::WebMemoryCoordinator::onMemoryStateChange( 2232 blink::WebMemoryCoordinator::onMemoryStateChange(
2233 static_cast<blink::MemoryState>(state)); 2233 static_cast<blink::MemoryState>(state));
2234 } 2234 }
2235 } 2235 }
2236 2236
2237 void RenderThreadImpl::OnPurgeMemory() { 2237 void RenderThreadImpl::OnPurgeMemory() {
2238 // Record amount of purged memory after 2 seconds. 2 seconds is arbitrary
2239 // but it works most cases.
2240 RendererMemoryMetrics metrics;
2241 GetRendererMemoryMetrics(&metrics);
2242 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
2243 FROM_HERE,
2244 base::Bind(&RenderThreadImpl::RecordPurgeMemory, base::Unretained(this),
2245 std::move(metrics)),
2246 base::TimeDelta::FromSeconds(2));
2247
2238 OnTrimMemoryImmediately(); 2248 OnTrimMemoryImmediately();
2239 ReleaseFreeMemory(); 2249 ReleaseFreeMemory();
2240 ClearMemory(); 2250 ClearMemory();
2241 if (blink_platform_impl_) 2251 if (blink_platform_impl_)
2242 blink::WebMemoryCoordinator::onPurgeMemory(); 2252 blink::WebMemoryCoordinator::onPurgeMemory();
2243 } 2253 }
2244 2254
2255 void RenderThreadImpl::RecordPurgeMemory(RendererMemoryMetrics before) {
2256 RendererMemoryMetrics after;
2257 GetRendererMemoryMetrics(&after);
2258 int64_t mbytes = static_cast<int64_t>(before.total_allocated_mb) -
2259 static_cast<int64_t>(after.total_allocated_mb);
2260 if (mbytes < 0)
2261 mbytes = 0;
2262 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Experimental.Renderer.PurgedMemory",
2263 mbytes);
2264 }
2265
2245 void RenderThreadImpl::ClearMemory() { 2266 void RenderThreadImpl::ClearMemory() {
2246 // Do not call into blink if it is not initialized. 2267 // Do not call into blink if it is not initialized.
2247 if (blink_platform_impl_) { 2268 if (blink_platform_impl_) {
2248 // Purge Skia font cache, by setting it to 0 and then again to the 2269 // Purge Skia font cache, by setting it to 0 and then again to the
2249 // previous limit. 2270 // previous limit.
2250 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); 2271 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0);
2251 SkGraphics::SetFontCacheLimit(font_cache_limit); 2272 SkGraphics::SetFontCacheLimit(font_cache_limit);
2252 } 2273 }
2253 } 2274 }
2254 2275
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 } 2453 }
2433 } 2454 }
2434 2455
2435 void RenderThreadImpl::OnRendererInterfaceRequest( 2456 void RenderThreadImpl::OnRendererInterfaceRequest(
2436 mojom::RendererAssociatedRequest request) { 2457 mojom::RendererAssociatedRequest request) {
2437 DCHECK(!renderer_binding_.is_bound()); 2458 DCHECK(!renderer_binding_.is_bound());
2438 renderer_binding_.Bind(std::move(request)); 2459 renderer_binding_.Bind(std::move(request));
2439 } 2460 }
2440 2461
2441 } // namespace content 2462 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698