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

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

Issue 336273003: base: Add soft memory limit to DiscardableMemoryManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: v2 Created 6 years, 6 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 | Annotate | Revision Log
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 <vector> 10 #include <vector>
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 891
892 base::allocator::ReleaseFreeMemory(); 892 base::allocator::ReleaseFreeMemory();
893 893
894 // Continue the idle timer if the webkit shared timer is not suspended or 894 // Continue the idle timer if the webkit shared timer is not suspended or
895 // something is left to do. 895 // something is left to do.
896 bool continue_timer = !webkit_shared_timer_suspended_; 896 bool continue_timer = !webkit_shared_timer_suspended_;
897 897
898 if (!v8::V8::IdleNotification()) { 898 if (!v8::V8::IdleNotification()) {
899 continue_timer = true; 899 continue_timer = true;
900 } 900 }
901 if (!base::DiscardableMemory::IdleNotification()) {
902 continue_timer = true;
903 }
901 904
902 // Schedule next invocation. 905 // Schedule next invocation.
903 // Dampen the delay using the algorithm (if delay is in seconds): 906 // Dampen the delay using the algorithm (if delay is in seconds):
904 // delay = delay + 1 / (delay + 2) 907 // delay = delay + 1 / (delay + 2)
905 // Using floor(delay) has a dampening effect such as: 908 // Using floor(delay) has a dampening effect such as:
906 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... 909 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
907 // If the delay is in milliseconds, the above formula is equivalent to: 910 // If the delay is in milliseconds, the above formula is equivalent to:
908 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2) 911 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
909 // which is equivalent to 912 // which is equivalent to
910 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000). 913 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
(...skipping 21 matching lines...) Expand all
932 if (idle_notifications_to_skip_ > 0) { 935 if (idle_notifications_to_skip_ > 0) {
933 idle_notifications_to_skip_--; 936 idle_notifications_to_skip_--;
934 } else { 937 } else {
935 int cpu_usage = 0; 938 int cpu_usage = 0;
936 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage)); 939 Send(new ViewHostMsg_GetCPUUsage(&cpu_usage));
937 // Idle notification hint roughly specifies the expected duration of the 940 // Idle notification hint roughly specifies the expected duration of the
938 // idle pause. We set it proportional to the idle timer delay. 941 // idle pause. We set it proportional to the idle timer delay.
939 int idle_hint = static_cast<int>(new_delay_ms / 10); 942 int idle_hint = static_cast<int>(new_delay_ms / 10);
940 if (cpu_usage < kIdleCPUUsageThresholdInPercents) { 943 if (cpu_usage < kIdleCPUUsageThresholdInPercents) {
941 base::allocator::ReleaseFreeMemory(); 944 base::allocator::ReleaseFreeMemory();
942 if (v8::V8::IdleNotification(idle_hint)) { 945
943 // V8 finished collecting garbage. 946 bool finished_idle_work = true;
947 if (!v8::V8::IdleNotification(idle_hint))
948 finished_idle_work = false;
949 if (!base::DiscardableMemory::IdleNotification())
950 finished_idle_work = false;
951
952 // V8 finished collecting garbage and discardable memory system has no
953 // more idle work left.
954 if (finished_idle_work)
944 new_delay_ms = kLongIdleHandlerDelayMs; 955 new_delay_ms = kLongIdleHandlerDelayMs;
945 }
946 } 956 }
947 } 957 }
948 ScheduleIdleHandler(new_delay_ms); 958 ScheduleIdleHandler(new_delay_ms);
949 } 959 }
950 960
951 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { 961 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
952 return idle_notification_delay_in_ms_; 962 return idle_notification_delay_in_ms_;
953 } 963 }
954 964
955 void RenderThreadImpl::SetIdleNotificationDelayInMs( 965 void RenderThreadImpl::SetIdleNotificationDelayInMs(
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 hidden_widget_count_--; 1529 hidden_widget_count_--;
1520 1530
1521 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { 1531 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
1522 return; 1532 return;
1523 } 1533 }
1524 1534
1525 ScheduleIdleHandler(kLongIdleHandlerDelayMs); 1535 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1526 } 1536 }
1527 1537
1528 } // namespace content 1538 } // namespace content
OLDNEW
« base/memory/discardable_memory_android.cc ('K') | « base/memory/discardable_memory_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698