Chromium Code Reviews| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 #if defined(OS_ANDROID) | 240 #if defined(OS_ANDROID) |
| 241 // On Android, resource messages can each take ~1.5ms to dispatch on the browser | 241 // On Android, resource messages can each take ~1.5ms to dispatch on the browser |
| 242 // IO thread. Limiting the message rate to 3/frame at 60hz ensures that the | 242 // IO thread. Limiting the message rate to 3/frame at 60hz ensures that the |
| 243 // induced work takes but a fraction (~1/4) of the overall frame budget. | 243 // induced work takes but a fraction (~1/4) of the overall frame budget. |
| 244 const int kMaxResourceRequestsPerFlushWhenThrottled = 3; | 244 const int kMaxResourceRequestsPerFlushWhenThrottled = 3; |
| 245 #else | 245 #else |
| 246 const int kMaxResourceRequestsPerFlushWhenThrottled = 8; | 246 const int kMaxResourceRequestsPerFlushWhenThrottled = 8; |
| 247 #endif | 247 #endif |
| 248 const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; | 248 const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; |
| 249 | 249 |
| 250 // Max count of reporting PurgeAndSuspend.Experimental.MemoryGrowth.*. | |
| 251 const int kMaxCountOfReportMemoryGrowthMetrics = 2; | |
| 252 | |
| 250 // Maximum allocation size allowed for image scaling filters that | 253 // Maximum allocation size allowed for image scaling filters that |
| 251 // require pre-scaling. Skia will fallback to a filter that doesn't | 254 // require pre-scaling. Skia will fallback to a filter that doesn't |
| 252 // require pre-scaling if the default filter would require an | 255 // require pre-scaling if the default filter would require an |
| 253 // allocation that exceeds this limit. | 256 // allocation that exceeds this limit. |
| 254 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; | 257 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; |
| 255 | 258 |
| 256 #if defined(OS_ANDROID) | 259 #if defined(OS_ANDROID) |
| 257 // Unique identifier for each output surface created. | 260 // Unique identifier for each output surface created. |
| 258 uint32_t g_next_compositor_frame_sink_id = 1; | 261 uint32_t g_next_compositor_frame_sink_id = 1; |
| 259 #endif | 262 #endif |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 #if defined(OS_LINUX) | 900 #if defined(OS_LINUX) |
| 898 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); | 901 ChildProcess::current()->SetIOThreadPriority(base::ThreadPriority::DISPLAY); |
| 899 ChildThreadImpl::current()->SetThreadPriority( | 902 ChildThreadImpl::current()->SetThreadPriority( |
| 900 categorized_worker_pool_->background_worker_thread_id(), | 903 categorized_worker_pool_->background_worker_thread_id(), |
| 901 base::ThreadPriority::BACKGROUND); | 904 base::ThreadPriority::BACKGROUND); |
| 902 #endif | 905 #endif |
| 903 | 906 |
| 904 record_purge_suspend_growth_metric_closure_.Reset( | 907 record_purge_suspend_growth_metric_closure_.Reset( |
| 905 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | 908 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 906 base::Unretained(this))); | 909 base::Unretained(this))); |
| 910 memory_growth_report_count_ = 0; | |
| 907 needs_to_record_first_active_paint_ = false; | 911 needs_to_record_first_active_paint_ = false; |
| 908 | 912 |
| 909 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 913 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 910 | 914 |
| 911 // If this renderer doesn't run inside the browser process, enable | 915 // If this renderer doesn't run inside the browser process, enable |
| 912 // SequencedWorkerPool. Otherwise, it should already have been enabled. | 916 // SequencedWorkerPool. Otherwise, it should already have been enabled. |
| 913 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | 917 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
| 914 // redirection experiment concludes https://crbug.com/622400. | 918 // redirection experiment concludes https://crbug.com/622400. |
| 915 if (!command_line.HasSwitch(switches::kSingleProcess)) | 919 if (!command_line.HasSwitch(switches::kSingleProcess)) |
| 916 base::SequencedWorkerPool::EnableForProcess(); | 920 base::SequencedWorkerPool::EnableForProcess(); |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1676 | 1680 |
| 1677 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); | 1681 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); |
| 1678 needs_to_record_first_active_paint_ = true; | 1682 needs_to_record_first_active_paint_ = true; |
| 1679 | 1683 |
| 1680 RendererMemoryMetrics memory_metrics; | 1684 RendererMemoryMetrics memory_metrics; |
| 1681 if (!GetRendererMemoryMetrics(&memory_metrics)) | 1685 if (!GetRendererMemoryMetrics(&memory_metrics)) |
| 1682 return; | 1686 return; |
| 1683 | 1687 |
| 1684 purge_and_suspend_memory_metrics_ = memory_metrics; | 1688 purge_and_suspend_memory_metrics_ = memory_metrics; |
| 1685 // record how many memory usage increases after purged. | 1689 // record how many memory usage increases after purged. |
| 1690 memory_growth_report_count_ = 0; | |
| 1686 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1691 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1687 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), | 1692 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), |
| 1688 base::TimeDelta::FromMinutes(5)); | 1693 base::TimeDelta::FromMinutes(30)); |
| 1689 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | |
| 1690 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), | |
| 1691 base::TimeDelta::FromMinutes(10)); | |
| 1692 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | |
| 1693 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), | |
| 1694 base::TimeDelta::FromMinutes(15)); | |
|
Ilya Sherman
2017/05/09 03:58:58
I think this previous structure was both simpler a
tasak
2017/05/10 09:57:02
Done.
| |
| 1695 } | 1694 } |
| 1696 | 1695 |
| 1697 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra | 1696 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra |
| 1698 // when it is possible to run memory-infra without tracing. | 1697 // when it is possible to run memory-infra without tracing. |
| 1699 #if defined(OS_WIN) | 1698 #if defined(OS_WIN) |
| 1700 namespace { | 1699 namespace { |
| 1701 | 1700 |
| 1702 static size_t GetMallocUsage() { | 1701 static size_t GetMallocUsage() { |
| 1703 // Iterate through whichever heap the CRT is using. | 1702 // Iterate through whichever heap the CRT is using. |
| 1704 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); | 1703 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1786 total_allocated / render_view_count / 1024 / 1024; | 1785 total_allocated / render_view_count / 1024 / 1024; |
| 1787 | 1786 |
| 1788 return true; | 1787 return true; |
| 1789 } | 1788 } |
| 1790 | 1789 |
| 1791 #define GET_MEMORY_GROWTH(current, previous, allocator) \ | 1790 #define GET_MEMORY_GROWTH(current, previous, allocator) \ |
| 1792 (current.allocator > previous.allocator \ | 1791 (current.allocator > previous.allocator \ |
| 1793 ? current.allocator - previous.allocator \ | 1792 ? current.allocator - previous.allocator \ |
| 1794 : 0) | 1793 : 0) |
| 1795 | 1794 |
| 1796 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics() const { | 1795 #define UMA_HISTOGRAM_MEMORY_GROWTH(name) \ |
| 1796 UMA_HISTOGRAM_MEMORY_KB( \ | |
| 1797 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB" name, \ | |
| 1798 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
| 1799 partition_alloc_kb)); \ | |
| 1800 UMA_HISTOGRAM_MEMORY_KB( \ | |
| 1801 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB" name, \ | |
| 1802 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
| 1803 blink_gc_kb)); \ | |
| 1804 UMA_HISTOGRAM_MEMORY_KB( \ | |
| 1805 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB" name, \ | |
| 1806 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
| 1807 malloc_mb) * \ | |
| 1808 1024); \ | |
| 1809 UMA_HISTOGRAM_MEMORY_KB( \ | |
| 1810 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB" name, \ | |
| 1811 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
| 1812 discardable_kb)); \ | |
| 1813 UMA_HISTOGRAM_MEMORY_KB( \ | |
| 1814 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB" name, \ | |
| 1815 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
| 1816 v8_main_thread_isolate_mb) * \ | |
| 1817 1024); \ | |
| 1818 UMA_HISTOGRAM_MEMORY_KB( \ | |
| 1819 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB" name, \ | |
| 1820 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, \ | |
| 1821 total_allocated_mb) * \ | |
| 1822 1024); | |
| 1823 | |
| 1824 void RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics() { | |
| 1797 // If this renderer is resumed, we should not update UMA. | 1825 // If this renderer is resumed, we should not update UMA. |
| 1798 if (!RendererIsHidden()) | 1826 if (!RendererIsHidden()) |
| 1799 return; | 1827 return; |
| 1828 if (memory_growth_report_count_ > kMaxCountOfReportMemoryGrowthMetrics) | |
| 1829 return; | |
| 1800 | 1830 |
| 1801 RendererMemoryMetrics memory_metrics; | 1831 RendererMemoryMetrics memory_metrics; |
| 1802 if (!GetRendererMemoryMetrics(&memory_metrics)) | 1832 if (!GetRendererMemoryMetrics(&memory_metrics)) |
| 1803 return; | 1833 return; |
| 1804 | 1834 |
| 1805 UMA_HISTOGRAM_MEMORY_KB( | 1835 switch (memory_growth_report_count_) { |
| 1806 "PurgeAndSuspend.Experimental.MemoryGrowth.PartitionAllocKB", | 1836 case 0: |
| 1807 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1837 UMA_HISTOGRAM_MEMORY_GROWTH(".30min"); |
| 1808 partition_alloc_kb)); | 1838 ++memory_growth_report_count_; |
| 1809 UMA_HISTOGRAM_MEMORY_KB( | 1839 break; |
| 1810 "PurgeAndSuspend.Experimental.MemoryGrowth.BlinkGCKB", | 1840 case 1: |
| 1811 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1841 UMA_HISTOGRAM_MEMORY_GROWTH(".60min"); |
| 1812 blink_gc_kb)); | 1842 ++memory_growth_report_count_; |
| 1813 UMA_HISTOGRAM_MEMORY_KB( | 1843 break; |
| 1814 "PurgeAndSuspend.Experimental.MemoryGrowth.MallocKB", | 1844 case 2: |
| 1815 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1845 UMA_HISTOGRAM_MEMORY_GROWTH(".90min"); |
|
Ilya Sherman
2017/05/09 03:58:58
Optional nit: I think it'd be a bit cleaner to hav
tasak
2017/05/10 09:57:02
Done.
| |
| 1816 malloc_mb) * 1024); | 1846 ++memory_growth_report_count_; |
| 1817 UMA_HISTOGRAM_MEMORY_KB( | 1847 break; |
| 1818 "PurgeAndSuspend.Experimental.MemoryGrowth.DiscardableKB", | 1848 } |
| 1819 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1849 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1820 discardable_kb)); | 1850 FROM_HERE, record_purge_suspend_growth_metric_closure_.callback(), |
| 1821 UMA_HISTOGRAM_MEMORY_KB( | 1851 base::TimeDelta::FromMinutes(30)); |
| 1822 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", | |
| 1823 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | |
| 1824 v8_main_thread_isolate_mb) * 1024); | |
| 1825 UMA_HISTOGRAM_MEMORY_KB( | |
| 1826 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", | |
| 1827 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | |
| 1828 total_allocated_mb) * 1024); | |
| 1829 } | 1852 } |
| 1830 | 1853 |
| 1831 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1854 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
| 1832 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1855 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
| 1833 | 1856 |
| 1834 if (gpu_channel_) { | 1857 if (gpu_channel_) { |
| 1835 // Do nothing if we already have a GPU channel or are already | 1858 // Do nothing if we already have a GPU channel or are already |
| 1836 // establishing one. | 1859 // establishing one. |
| 1837 if (!gpu_channel_->IsLost()) | 1860 if (!gpu_channel_->IsLost()) |
| 1838 return gpu_channel_; | 1861 return gpu_channel_; |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2441 } | 2464 } |
| 2442 } | 2465 } |
| 2443 | 2466 |
| 2444 void RenderThreadImpl::OnRendererInterfaceRequest( | 2467 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2445 mojom::RendererAssociatedRequest request) { | 2468 mojom::RendererAssociatedRequest request) { |
| 2446 DCHECK(!renderer_binding_.is_bound()); | 2469 DCHECK(!renderer_binding_.is_bound()); |
| 2447 renderer_binding_.Bind(std::move(request)); | 2470 renderer_binding_.Bind(std::move(request)); |
| 2448 } | 2471 } |
| 2449 | 2472 |
| 2450 } // namespace content | 2473 } // namespace content |
| OLD | NEW |