Chromium Code Reviews

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

Issue 583593006: Force scavenge in idle notification if we estimate that it will take long. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « src/heap/gc-idle-time-handler.h ('k') | src/heap/gc-idle-time-handler-unittest.cc » ('j') | 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 #include "src/heap/gc-tracer.h" 6 #include "src/heap/gc-tracer.h"
7 #include "src/utils.h" 7 #include "src/utils.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 56 matching lines...)
67 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; 67 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed;
68 } 68 }
69 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; 69 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms;
70 return Min(result, kMaxMarkCompactTimeInMs); 70 return Min(result, kMaxMarkCompactTimeInMs);
71 } 71 }
72 72
73 73
74 size_t GCIdleTimeHandler::EstimateScavengeTime( 74 size_t GCIdleTimeHandler::EstimateScavengeTime(
75 size_t new_space_size, size_t scavenge_speed_in_bytes_per_ms) { 75 size_t new_space_size, size_t scavenge_speed_in_bytes_per_ms) {
76 if (scavenge_speed_in_bytes_per_ms == 0) { 76 if (scavenge_speed_in_bytes_per_ms == 0) {
77 scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed; 77 return GCIdleTimeHandler::kLargeIdleTime;
78 } 78 }
79 return new_space_size / scavenge_speed_in_bytes_per_ms; 79 return new_space_size / scavenge_speed_in_bytes_per_ms;
80 } 80 }
81 81
82 82
83 bool GCIdleTimeHandler::ScavangeMayHappenSoon( 83 bool GCIdleTimeHandler::ScavangeMayHappenSoon(
84 size_t available_new_space_memory, 84 size_t available_new_space_memory,
85 size_t new_space_allocation_throughput_in_bytes_per_ms) { 85 size_t new_space_allocation_throughput_in_bytes_per_ms) {
86 if (available_new_space_memory <= 86 if (available_new_space_memory <=
87 new_space_allocation_throughput_in_bytes_per_ms * 87 new_space_allocation_throughput_in_bytes_per_ms *
88 kMaxFrameRenderingIdleTime) { 88 kMaxFrameRenderingIdleTime) {
89 return true; 89 return true;
90 } 90 }
91 return false; 91 return false;
92 } 92 }
93 93
94 94
95 bool GCIdleTimeHandler::DoEarlyScavenge(
96 size_t idle_time_in_ms, size_t new_space_size,
97 size_t available_new_space_memory, size_t scavenger_speed_in_bytes_per_ms) {
98 // For small idle times, we conservatively decide not to do a Scavenge.
99 if (idle_time_in_ms < kLargeIdleTime &&
100 idle_time_in_ms > kMaxFrameRenderingIdleTime) {
jochen (gone - plz use gerrit) 2014/09/18 18:46:28 that is 16 < idle_time_in_ms < 10 which is always
101 return false;
102 }
103
104 size_t currently_allocated = new_space_size - available_new_space_memory;
105 size_t current_scavenging_estimate_in_ms = EstimateScavengeTime(
106 currently_allocated, scavenger_speed_in_bytes_per_ms);
107
108 // We just force a Scavenge if it may take really long.
109 if (current_scavenging_estimate_in_ms < kForceScavengeThreshold) return false;
110
111 if (idle_time_in_ms < current_scavenging_estimate_in_ms) return false;
jochen (gone - plz use gerrit) 2014/09/18 18:46:28 so basically, we force a scavenge if it would take
112 return true;
113 }
114
115
116 bool GCIdleTimeHandler::DoScavenge(
117 size_t idle_time_in_ms, size_t new_space_size,
118 size_t available_new_space_memory, size_t scavenge_speed_in_bytes_per_ms,
119 size_t new_space_allocation_throughput_in_bytes_per_ms) {
120 // Do not invoke scavenger for large idle notification requests.
121 if (idle_time_in_ms > kMaxFrameRenderingIdleTime) return false;
122
123 // We may force an early Scavenge if we think that the next Scavenge may take
124 // long or if we think that a Scavenge may happen soon.
125 return DoEarlyScavenge(idle_time_in_ms, new_space_size,
ulan 2014/09/19 10:47:47 As discussed offline, we can probably unify these
126 available_new_space_memory,
127 scavenge_speed_in_bytes_per_ms) ||
128 (ScavangeMayHappenSoon(
129 available_new_space_memory,
130 new_space_allocation_throughput_in_bytes_per_ms) &&
131 idle_time_in_ms >=
132 EstimateScavengeTime(new_space_size,
133 scavenge_speed_in_bytes_per_ms));
134 }
135
136
95 // The following logic is implemented by the controller: 137 // The following logic is implemented by the controller:
96 // (1) If the new space is almost full and we can effort a Scavenge, then a 138 // (1) If the new space is almost full and we can effort a Scavenge or if the
97 // Scavenge is performed. 139 // next Scavenge will very likely take long, then a Scavenge is performed.
98 // (2) If there is currently no MarkCompact idle round going on, we start a 140 // (2) If there is currently no MarkCompact idle round going on, we start a
99 // new idle round if enough garbage was created or we received a context 141 // new idle round if enough garbage was created or we received a context
100 // disposal event. Otherwise we do not perform garbage collection to keep 142 // disposal event. Otherwise we do not perform garbage collection to keep
101 // system utilization low. 143 // system utilization low.
102 // (3) If incremental marking is done, we perform a full garbage collection 144 // (3) If incremental marking is done, we perform a full garbage collection
103 // if context was disposed or if we are allowed to still do full garbage 145 // if context was disposed or if we are allowed to still do full garbage
104 // collections during this idle round or if we are not allowed to start 146 // collections during this idle round or if we are not allowed to start
105 // incremental marking. Otherwise we do not perform garbage collection to 147 // incremental marking. Otherwise we do not perform garbage collection to
106 // keep system utilization low. 148 // keep system utilization low.
107 // (4) If sweeping is in progress and we received a large enough idle time 149 // (4) If sweeping is in progress and we received a large enough idle time
108 // request, we finalize sweeping here. 150 // request, we finalize sweeping here.
109 // (5) If incremental marking is in progress, we perform a marking step. Note, 151 // (5) If incremental marking is in progress, we perform a marking step. Note,
110 // that this currently may trigger a full garbage collection. 152 // that this currently may trigger a full garbage collection.
111 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, 153 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms,
112 HeapState heap_state) { 154 HeapState heap_state) {
113 if (ScavangeMayHappenSoon( 155 if (DoScavenge(idle_time_in_ms, heap_state.new_space_capacity,
114 heap_state.available_new_space_memory, 156 heap_state.available_new_space_memory,
115 heap_state.new_space_allocation_throughput_in_bytes_per_ms) && 157 heap_state.scavenge_speed_in_bytes_per_ms,
116 idle_time_in_ms >= 158 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) {
117 EstimateScavengeTime(heap_state.new_space_capacity,
118 heap_state.scavenge_speed_in_bytes_per_ms)) {
119 return GCIdleTimeAction::Scavenge(); 159 return GCIdleTimeAction::Scavenge();
120 } 160 }
161
121 if (IsMarkCompactIdleRoundFinished()) { 162 if (IsMarkCompactIdleRoundFinished()) {
122 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { 163 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) {
123 StartIdleRound(); 164 StartIdleRound();
124 } else { 165 } else {
125 return GCIdleTimeAction::Done(); 166 return GCIdleTimeAction::Done();
126 } 167 }
127 } 168 }
128 169
129 if (idle_time_in_ms == 0) { 170 if (idle_time_in_ms == 0) {
130 return GCIdleTimeAction::Nothing(); 171 return GCIdleTimeAction::Nothing();
(...skipping 33 matching lines...)
164 if (heap_state.incremental_marking_stopped && 205 if (heap_state.incremental_marking_stopped &&
165 !heap_state.can_start_incremental_marking) { 206 !heap_state.can_start_incremental_marking) {
166 return GCIdleTimeAction::Nothing(); 207 return GCIdleTimeAction::Nothing();
167 } 208 }
168 size_t step_size = EstimateMarkingStepSize( 209 size_t step_size = EstimateMarkingStepSize(
169 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); 210 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms);
170 return GCIdleTimeAction::IncrementalMarking(step_size); 211 return GCIdleTimeAction::IncrementalMarking(step_size);
171 } 212 }
172 } 213 }
173 } 214 }
OLDNEW
« no previous file with comments | « src/heap/gc-idle-time-handler.h ('k') | src/heap/gc-idle-time-handler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine