| 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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 | 910 |
| 911 #if defined(OS_LINUX) | 911 #if defined(OS_LINUX) |
| 912 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); | 912 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); |
| 913 ChildThreadImpl::current()->SetThreadPriority( | 913 ChildThreadImpl::current()->SetThreadPriority( |
| 914 categorized_worker_pool_->background_worker_thread_id(), | 914 categorized_worker_pool_->background_worker_thread_id(), |
| 915 base::ThreadPriority::BACKGROUND); | 915 base::ThreadPriority::BACKGROUND); |
| 916 #endif | 916 #endif |
| 917 | 917 |
| 918 record_purge_suspend_metric_closure_.Reset(base::Bind( | 918 record_purge_suspend_metric_closure_.Reset(base::Bind( |
| 919 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); | 919 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); |
| 920 is_renderer_suspended_ = false; | |
| 921 | 920 |
| 922 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 921 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 923 | 922 |
| 924 // If this renderer doesn't run inside the browser process, enable | 923 // If this renderer doesn't run inside the browser process, enable |
| 925 // SequencedWorkerPool. Otherwise, it should already have been enabled. | 924 // SequencedWorkerPool. Otherwise, it should already have been enabled. |
| 926 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | 925 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
| 927 // redirection experiment concludes https://crbug.com/622400. | 926 // redirection experiment concludes https://crbug.com/622400. |
| 928 if (!command_line.HasSwitch(switches::kSingleProcess)) | 927 if (!command_line.HasSwitch(switches::kSingleProcess)) |
| 929 base::SequencedWorkerPool::EnableForProcess(); | 928 base::SequencedWorkerPool::EnableForProcess(); |
| 930 } | 929 } |
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | 1770 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1772 // and follow MemoryCoordinator's request. | 1771 // and follow MemoryCoordinator's request. |
| 1773 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | 1772 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 1774 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1773 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1775 base::MemoryState::NORMAL); | 1774 base::MemoryState::NORMAL); |
| 1776 | 1775 |
| 1777 record_purge_suspend_metric_closure_.Cancel(); | 1776 record_purge_suspend_metric_closure_.Cancel(); |
| 1778 record_purge_suspend_metric_closure_.Reset( | 1777 record_purge_suspend_metric_closure_.Reset( |
| 1779 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1778 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| 1780 base::Unretained(this))); | 1779 base::Unretained(this))); |
| 1781 is_renderer_suspended_ = false; | |
| 1782 } | 1780 } |
| 1783 } | 1781 } |
| 1784 | 1782 |
| 1785 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1783 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1786 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1784 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1787 DCHECK(!is_renderer_suspended_); | |
| 1788 if (!RendererIsHidden()) | 1785 if (!RendererIsHidden()) |
| 1789 return; | 1786 return; |
| 1790 is_renderer_suspended_ = true; | |
| 1791 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1787 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1792 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify | 1788 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
| 1793 // and follow MemoryCoordinator's request. | 1789 // and follow MemoryCoordinator's request. |
| 1794 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1790 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1795 base::MemoryState::SUSPENDED); | 1791 base::MemoryState::SUSPENDED); |
| 1796 } | 1792 } |
| 1797 // 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, ...), |
| 1798 // 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 |
| 1799 // update purge+suspend UMA histogram. | 1795 // update purge+suspend UMA histogram. |
| 1800 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1796 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 | 1846 |
| 1851 } // namespace | 1847 } // namespace |
| 1852 #endif | 1848 #endif |
| 1853 | 1849 |
| 1854 // TODO(tasak): Once it is possible to use memory-infra without tracing, | 1850 // TODO(tasak): Once it is possible to use memory-infra without tracing, |
| 1855 // we should collect the metrics using memory-infra. | 1851 // we should collect the metrics using memory-infra. |
| 1856 // TODO(tasak): We should also report a difference between the memory usages | 1852 // TODO(tasak): We should also report a difference between the memory usages |
| 1857 // before and after purging by using memory-infra. | 1853 // before and after purging by using memory-infra. |
| 1858 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const { | 1854 void RenderThreadImpl::RecordPurgeAndSuspendMetrics() const { |
| 1859 // If this renderer is resumed, we should not update UMA. | 1855 // If this renderer is resumed, we should not update UMA. |
| 1860 if (!is_renderer_suspended_) | 1856 if (!RendererIsHidden()) |
| 1861 return; | 1857 return; |
| 1862 | 1858 |
| 1863 // TODO(tasak): Compare memory metrics between purge-enabled renderers and | 1859 // TODO(tasak): Compare memory metrics between purge-enabled renderers and |
| 1864 // purge-disabled renderers (A/B testing). | 1860 // purge-disabled renderers (A/B testing). |
| 1865 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); | 1861 blink::WebMemoryStatistics blink_stats = blink::WebMemoryStatistics::Get(); |
| 1866 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", | 1862 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.PartitionAllocKB", |
| 1867 blink_stats.partitionAllocTotalAllocatedBytes / 1024); | 1863 blink_stats.partitionAllocTotalAllocatedBytes / 1024); |
| 1868 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", | 1864 UMA_HISTOGRAM_MEMORY_KB("PurgeAndSuspend.Memory.BlinkGCKB", |
| 1869 blink_stats.blinkGCTotalAllocatedBytes / 1024); | 1865 blink_stats.blinkGCTotalAllocatedBytes / 1024); |
| 1870 #if defined(OS_LINUX) || defined(OS_ANDROID) | 1866 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1901 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", | 1897 UMA_HISTOGRAM_MEMORY_MB("PurgeAndSuspend.Memory.TotalAllocatedMB", |
| 1902 (blink_stats.partitionAllocTotalAllocatedBytes + | 1898 (blink_stats.partitionAllocTotalAllocatedBytes + |
| 1903 blink_stats.blinkGCTotalAllocatedBytes + | 1899 blink_stats.blinkGCTotalAllocatedBytes + |
| 1904 malloc_usage + v8_usage + discardable_usage) / | 1900 malloc_usage + v8_usage + discardable_usage) / |
| 1905 1024 / 1024); | 1901 1024 / 1024); |
| 1906 } | 1902 } |
| 1907 | 1903 |
| 1908 void RenderThreadImpl::OnProcessResume() { | 1904 void RenderThreadImpl::OnProcessResume() { |
| 1909 ChildThreadImpl::OnProcessResume(); | 1905 ChildThreadImpl::OnProcessResume(); |
| 1910 | 1906 |
| 1911 DCHECK(is_renderer_suspended_); | 1907 if (!RendererIsHidden()) |
| 1912 is_renderer_suspended_ = false; | 1908 return; |
| 1913 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1909 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1914 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | 1910 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1915 // and follow MemoryCoordinator's request. | 1911 // and follow MemoryCoordinator's request. |
| 1916 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1912 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1917 base::MemoryState::NORMAL); | 1913 base::MemoryState::NORMAL); |
| 1918 renderer_scheduler_->ResumeRenderer(); | 1914 renderer_scheduler_->ResumeRenderer(); |
| 1919 } | 1915 } |
| 1920 } | 1916 } |
| 1921 | 1917 |
| 1922 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1918 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2517 } | 2513 } |
| 2518 } | 2514 } |
| 2519 | 2515 |
| 2520 void RenderThreadImpl::OnRendererInterfaceRequest( | 2516 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2521 mojom::RendererAssociatedRequest request) { | 2517 mojom::RendererAssociatedRequest request) { |
| 2522 DCHECK(!renderer_binding_.is_bound()); | 2518 DCHECK(!renderer_binding_.is_bound()); |
| 2523 renderer_binding_.Bind(std::move(request)); | 2519 renderer_binding_.Bind(std::move(request)); |
| 2524 } | 2520 } |
| 2525 | 2521 |
| 2526 } // namespace content | 2522 } // namespace content |
| OLD | NEW |