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

Side by Side Diff: src/heap/gc-idle-time-handler.cc

Issue 1313083002: Allow more scavenges during idle times by pushing down the idle new space limit. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project 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 "src/heap/gc-idle-time-handler.h" 5 #include "src/heap/gc-idle-time-handler.h"
6 6
7 #include "src/flags.h" 7 #include "src/flags.h"
8 #include "src/heap/gc-tracer.h" 8 #include "src/heap/gc-tracer.h"
9 #include "src/utils.h" 9 #include "src/utils.h"
10 10
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 113
114 bool GCIdleTimeHandler::ShouldDoScavenge( 114 bool GCIdleTimeHandler::ShouldDoScavenge(
115 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, 115 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size,
116 size_t scavenge_speed_in_bytes_per_ms, 116 size_t scavenge_speed_in_bytes_per_ms,
117 size_t new_space_allocation_throughput_in_bytes_per_ms) { 117 size_t new_space_allocation_throughput_in_bytes_per_ms) {
118 if (idle_time_in_ms >= kMinBackgroundIdleTime) { 118 if (idle_time_in_ms >= kMinBackgroundIdleTime) {
119 // It is better to do full GC for the background tab. 119 // It is better to do full GC for the background tab.
120 return false; 120 return false;
121 } 121 }
122 size_t new_space_allocation_limit = 122
123 kMaxScheduledIdleTime * scavenge_speed_in_bytes_per_ms; 123 // Calculates how much memory are we able to scavenge in
124 // kMaxFrameRenderingIdleTime ms. If scavenge_speed_in_bytes_per_ms is 0 we
125 // will take care of this later.
126 size_t idle_new_space_allocation_limit =
127 kMaxFrameRenderingIdleTime * scavenge_speed_in_bytes_per_ms;
124 128
125 // If the limit is larger than the new space size, then scavenging used to be 129 // If the limit is larger than the new space size, then scavenging used to be
126 // really fast. We can take advantage of the whole new space. 130 // really fast. We can take advantage of the whole new space.
127 if (new_space_allocation_limit > new_space_size) { 131 if (idle_new_space_allocation_limit > new_space_size) {
128 new_space_allocation_limit = new_space_size; 132 idle_new_space_allocation_limit = new_space_size;
129 } 133 }
130 134
131 // We do not know the allocation throughput before the first scavenge. 135 // We do not know the allocation throughput before the first scavenge.
132 // TODO(hpayer): Estimate allocation throughput before the first scavenge. 136 // TODO(hpayer): Estimate allocation throughput before the first scavenge.
133 if (new_space_allocation_throughput_in_bytes_per_ms > 0) { 137 if (new_space_allocation_throughput_in_bytes_per_ms > 0) {
134 // We have to trigger scavenge before we reach the end of new space. 138 // We have to trigger scavenge before we reach the end of new space.
135 size_t adjust_limit = new_space_allocation_throughput_in_bytes_per_ms * 139 size_t adjust_limit = new_space_allocation_throughput_in_bytes_per_ms *
136 kTimeUntilNextIdleEvent; 140 kTimeUntilNextIdleEvent;
137 if (adjust_limit > new_space_allocation_limit) { 141 if (adjust_limit > idle_new_space_allocation_limit) {
138 new_space_allocation_limit = 0; 142 idle_new_space_allocation_limit = 0;
139 } else { 143 } else {
140 new_space_allocation_limit -= adjust_limit; 144 idle_new_space_allocation_limit -= adjust_limit;
141 } 145 }
142 } 146 }
143 147
144 if (new_space_allocation_throughput_in_bytes_per_ms <
145 kLowAllocationThroughput) {
146 new_space_allocation_limit =
147 Min(new_space_allocation_limit,
148 static_cast<size_t>(new_space_size * kConservativeTimeRatio));
149 }
150
151 // The allocated new space limit to trigger a scavange has to be at least 148 // The allocated new space limit to trigger a scavange has to be at least
152 // kMinimumNewSpaceSizeToPerformScavenge. 149 // kMinimumNewSpaceSizeToPerformScavenge.
153 if (new_space_allocation_limit < kMinimumNewSpaceSizeToPerformScavenge) { 150 if (idle_new_space_allocation_limit < kMinimumNewSpaceSizeToPerformScavenge) {
154 new_space_allocation_limit = kMinimumNewSpaceSizeToPerformScavenge; 151 idle_new_space_allocation_limit = kMinimumNewSpaceSizeToPerformScavenge;
155 } 152 }
156 153
154 // Set an initial scavenge speed if it is unknown.
157 if (scavenge_speed_in_bytes_per_ms == 0) { 155 if (scavenge_speed_in_bytes_per_ms == 0) {
158 scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed; 156 scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed;
159 } 157 }
160 158
161 if (new_space_allocation_limit <= used_new_space_size) { 159 // We apply a max factor to the new space size to make sure that a slowly
160 // allocating application still leaves enough of wiggle room to schedule a
161 // scavenge.
162 size_t max_limit;
163 const double kMaxNewSpaceSizeFactorLongIdleTimes = 0.5;
164 const double kMaxNewSpaceSizeFactorShortIdleTimes = 0.8;
165 if (idle_time_in_ms > kMaxFrameRenderingIdleTime) {
166 max_limit = static_cast<size_t>(new_space_size *
167 kMaxNewSpaceSizeFactorLongIdleTimes);
168 } else {
169 max_limit = static_cast<size_t>(new_space_size *
170 kMaxNewSpaceSizeFactorShortIdleTimes);
171 }
172 idle_new_space_allocation_limit =
173 Min(idle_new_space_allocation_limit, max_limit);
174
175 // We perform a scavenge if we are over the idle new space limit and
176 // a scavenge fits into the given idle time bucket.
177 if (idle_new_space_allocation_limit <= used_new_space_size) {
162 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <= 178 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <=
163 idle_time_in_ms) { 179 idle_time_in_ms) {
164 return true; 180 return true;
165 } 181 }
166 } 182 }
167 return false; 183 return false;
168 } 184 }
169 185
170 186
171 bool GCIdleTimeHandler::ShouldDoMarkCompact( 187 bool GCIdleTimeHandler::ShouldDoMarkCompact(
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 285
270 size_t step_size = EstimateMarkingStepSize( 286 size_t step_size = EstimateMarkingStepSize(
271 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), 287 static_cast<size_t>(kIncrementalMarkingStepTimeInMs),
272 heap_state.incremental_marking_speed_in_bytes_per_ms); 288 heap_state.incremental_marking_speed_in_bytes_per_ms);
273 return GCIdleTimeAction::IncrementalMarking(step_size); 289 return GCIdleTimeAction::IncrementalMarking(step_size);
274 } 290 }
275 291
276 292
277 } 293 }
278 } 294 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698