OLD | NEW |
---|---|
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 1760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1771 record_purge_suspend_metric_closure_.Reset( | 1771 record_purge_suspend_metric_closure_.Reset( |
1772 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1772 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
1773 base::Unretained(this))); | 1773 base::Unretained(this))); |
1774 } | 1774 } |
1775 } | 1775 } |
1776 | 1776 |
1777 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1777 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
1778 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1778 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
1779 if (!RendererIsHidden()) | 1779 if (!RendererIsHidden()) |
1780 return; | 1780 return; |
1781 | |
1782 // Disable PurgeAndSuspend and not record UMA to avoid conflicting | |
1783 // MemoryCoordinator finch experiment when MemoryCoordinator is enabled. | |
haraken
2016/12/21 04:03:23
Just say:
TODO(bashi): Enable the tab suspension
tasak
2016/12/22 04:49:52
Done.
| |
1784 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | |
bashi
2016/12/21 08:44:02
Why do we need this guard? Isn't having a guard in
tasak
2016/12/21 08:49:31
To avoid invoking record_purge_suspend_metric_clos
bashi
2016/12/21 08:55:32
How about calling PostDelayedTask() in SuspendRend
tasak
2016/12/21 08:58:28
To enable A/B testing, the PostDelayedTask is also
bashi
2016/12/21 09:02:41
OK
| |
1785 return; | |
1786 | |
1781 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1787 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
1782 // TODO(tasak,bashi): After enabling MemoryCoordinator, stop calling | 1788 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
1783 // SuspendRenderer() here. | 1789 // and follow MemoryCoordinator's request. |
1784 SuspendRenderer(); | 1790 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
1791 base::MemoryState::SUSPENDED); | |
1785 } | 1792 } |
1786 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1793 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
1787 // we need to wait until the task is finished. So wait 15 seconds and | 1794 // we need to wait until the task is finished. So wait 15 seconds and |
1788 // update purge+suspend UMA histogram. | 1795 // update purge+suspend UMA histogram. |
1789 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1796 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
1790 // UMA when MemoryCoordinator is available. | 1797 // UMA when MemoryCoordinator is available. |
1791 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1798 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
1792 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1799 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
1793 base::TimeDelta::FromSeconds(15)); | 1800 base::TimeDelta::FromSeconds(15)); |
1794 } | 1801 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1881 blink_stats.blinkGCTotalAllocatedBytes + | 1888 blink_stats.blinkGCTotalAllocatedBytes + |
1882 malloc_usage + v8_usage + discardable_usage) / | 1889 malloc_usage + v8_usage + discardable_usage) / |
1883 1024 / 1024); | 1890 1024 / 1024); |
1884 } | 1891 } |
1885 | 1892 |
1886 void RenderThreadImpl::OnProcessResume() { | 1893 void RenderThreadImpl::OnProcessResume() { |
1887 ChildThreadImpl::OnProcessResume(); | 1894 ChildThreadImpl::OnProcessResume(); |
1888 | 1895 |
1889 if (!RendererIsHidden()) | 1896 if (!RendererIsHidden()) |
1890 return; | 1897 return; |
1898 | |
1899 // Disable PurgeAndSuspend and not record UMA to avoid conflicting | |
1900 // MemoryCoordinator finch experiment when MemoryCoordinator is enabled. | |
haraken
2016/12/21 04:03:23
Ditto.
tasak
2016/12/22 04:49:52
Done.
| |
1901 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | |
1902 return; | |
1903 | |
1891 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1904 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
1892 // TODO(tasak,bashi): After enabling MemoryCoordinator, stop calling | 1905 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
1893 // ResumeRenderer() here. | 1906 // and follow MemoryCoordinator's request. |
1894 ResumeRenderer(); | 1907 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
1908 base::MemoryState::NORMAL); | |
1895 } | 1909 } |
1896 } | 1910 } |
1897 | 1911 |
1898 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1912 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
1899 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1913 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
1900 | 1914 |
1901 if (gpu_channel_) { | 1915 if (gpu_channel_) { |
1902 // Do nothing if we already have a GPU channel or are already | 1916 // Do nothing if we already have a GPU channel or are already |
1903 // establishing one. | 1917 // establishing one. |
1904 if (!gpu_channel_->IsLost()) | 1918 if (!gpu_channel_->IsLost()) |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2251 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { | 2265 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
2252 // TODO(hajimehoshi): Adjust the size of this memory usage according to | 2266 // TODO(hajimehoshi): Adjust the size of this memory usage according to |
2253 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at | 2267 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at |
2254 // present. | 2268 // present. |
2255 if (blink_platform_impl_) { | 2269 if (blink_platform_impl_) { |
2256 blink::WebMemoryCoordinator::onMemoryStateChange( | 2270 blink::WebMemoryCoordinator::onMemoryStateChange( |
2257 static_cast<blink::MemoryState>(state)); | 2271 static_cast<blink::MemoryState>(state)); |
2258 } | 2272 } |
2259 switch (state) { | 2273 switch (state) { |
2260 case base::MemoryState::NORMAL: | 2274 case base::MemoryState::NORMAL: |
2261 // TODO(bashi): When the renderer is suspended, resume it. | 2275 ResumeRenderer(); |
2262 break; | 2276 break; |
2263 case base::MemoryState::THROTTLED: | 2277 case base::MemoryState::THROTTLED: |
2264 // TODO(bashi): When the renderer is suspended, resume it. | 2278 ResumeRenderer(); |
2265 // TODO(bashi): Figure out what kind of strategy is suitable on | 2279 // TODO(bashi): Figure out what kind of strategy is suitable on |
2266 // THROTTLED state. crbug.com/674815 | 2280 // THROTTLED state. crbug.com/674815 |
2267 #if defined(OS_ANDROID) | 2281 #if defined(OS_ANDROID) |
2268 OnTrimMemoryImmediately(); | 2282 OnTrimMemoryImmediately(); |
2269 #else | 2283 #else |
2270 OnSyncMemoryPressure( | 2284 OnSyncMemoryPressure( |
2271 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); | 2285 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
2272 #endif | 2286 #endif |
2273 ReleaseFreeMemory(); | 2287 ReleaseFreeMemory(); |
2274 break; | 2288 break; |
2275 case base::MemoryState::SUSPENDED: | 2289 case base::MemoryState::SUSPENDED: |
2276 // TODO(bashi): Suspend the renderer. | 2290 SuspendRenderer(); |
2277 OnTrimMemoryImmediately(); | |
2278 ReleaseFreeMemory(); | |
2279 ClearMemory(); | |
2280 break; | 2291 break; |
2281 case base::MemoryState::UNKNOWN: | 2292 case base::MemoryState::UNKNOWN: |
2282 NOTREACHED(); | 2293 NOTREACHED(); |
2283 break; | 2294 break; |
2284 } | 2295 } |
2285 } | 2296 } |
2286 | 2297 |
2287 void RenderThreadImpl::SuspendRenderer() { | 2298 void RenderThreadImpl::SuspendRenderer() { |
2288 DCHECK(IsMainThread()); | 2299 DCHECK(IsMainThread()); |
2289 OnTrimMemoryImmediately(); | 2300 OnTrimMemoryImmediately(); |
2290 ReleaseFreeMemory(); | 2301 ReleaseFreeMemory(); |
2291 ClearMemory(); | 2302 ClearMemory(); |
2292 renderer_scheduler_->SuspendRenderer(); | 2303 // When only PurgeAndSuspend is enabled, suspend blink scheduler. |
haraken
2016/12/21 04:03:23
Ditto.
tasak
2016/12/22 04:49:52
Done.
| |
2304 if (!base::FeatureList::IsEnabled(features::kMemoryCoordinator) && | |
2305 base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | |
2306 renderer_scheduler_->SuspendRenderer(); | |
2293 } | 2307 } |
2294 | 2308 |
2295 void RenderThreadImpl::ResumeRenderer() { | 2309 void RenderThreadImpl::ResumeRenderer() { |
2296 DCHECK(IsMainThread()); | 2310 DCHECK(IsMainThread()); |
2297 renderer_scheduler_->ResumeRenderer(); | 2311 // When only PurgeAndSuspend is enabled, resume blink scheduler. |
haraken
2016/12/21 04:03:23
Ditto.
tasak
2016/12/22 04:49:52
Done.
| |
2312 if (!base::FeatureList::IsEnabled(features::kMemoryCoordinator) && | |
2313 base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | |
2314 renderer_scheduler_->ResumeRenderer(); | |
2298 } | 2315 } |
2299 | 2316 |
2300 void RenderThreadImpl::ClearMemory() { | 2317 void RenderThreadImpl::ClearMemory() { |
2301 // Do not call into blink if it is not initialized. | 2318 // Do not call into blink if it is not initialized. |
2302 if (blink_platform_impl_) { | 2319 if (blink_platform_impl_) { |
2303 // Purge Skia font cache, by setting it to 0 and then again to the | 2320 // Purge Skia font cache, by setting it to 0 and then again to the |
2304 // previous limit. | 2321 // previous limit. |
2305 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2322 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
2306 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2323 SkGraphics::SetFontCacheLimit(font_cache_limit); |
2307 } | 2324 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2487 } | 2504 } |
2488 } | 2505 } |
2489 | 2506 |
2490 void RenderThreadImpl::OnRendererInterfaceRequest( | 2507 void RenderThreadImpl::OnRendererInterfaceRequest( |
2491 mojom::RendererAssociatedRequest request) { | 2508 mojom::RendererAssociatedRequest request) { |
2492 DCHECK(!renderer_binding_.is_bound()); | 2509 DCHECK(!renderer_binding_.is_bound()); |
2493 renderer_binding_.Bind(std::move(request)); | 2510 renderer_binding_.Bind(std::move(request)); |
2494 } | 2511 } |
2495 | 2512 |
2496 } // namespace content | 2513 } // namespace content |
OLD | NEW |