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

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

Issue 1208993009: Reland "Replace reduce-memory mode in idle notification with delayed clean-up GC." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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 | « BUILD.gn ('k') | src/heap/gc-idle-time-handler.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 #ifndef V8_HEAP_GC_IDLE_TIME_HANDLER_H_ 5 #ifndef V8_HEAP_GC_IDLE_TIME_HANDLER_H_
6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_ 6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_
7 7
8 #include "src/globals.h" 8 #include "src/globals.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 12
13 enum GCIdleTimeActionType { 13 enum GCIdleTimeActionType {
14 DONE, 14 DONE,
15 DO_NOTHING, 15 DO_NOTHING,
16 DO_INCREMENTAL_MARKING, 16 DO_INCREMENTAL_MARKING,
17 DO_SCAVENGE, 17 DO_SCAVENGE,
18 DO_FULL_GC, 18 DO_FULL_GC,
19 DO_FINALIZE_SWEEPING 19 DO_FINALIZE_SWEEPING
20 }; 20 };
21 21
22 22
23 class GCIdleTimeAction { 23 class GCIdleTimeAction {
24 public: 24 public:
25 static GCIdleTimeAction Done() { 25 static GCIdleTimeAction Done() {
26 GCIdleTimeAction result; 26 GCIdleTimeAction result;
27 result.type = DONE; 27 result.type = DONE;
28 result.parameter = 0; 28 result.parameter = 0;
29 result.additional_work = false; 29 result.additional_work = false;
30 result.reduce_memory = false;
31 return result; 30 return result;
32 } 31 }
33 32
34 static GCIdleTimeAction Nothing() { 33 static GCIdleTimeAction Nothing() {
35 GCIdleTimeAction result; 34 GCIdleTimeAction result;
36 result.type = DO_NOTHING; 35 result.type = DO_NOTHING;
37 result.parameter = 0; 36 result.parameter = 0;
38 result.additional_work = false; 37 result.additional_work = false;
39 result.reduce_memory = false;
40 return result; 38 return result;
41 } 39 }
42 40
43 static GCIdleTimeAction IncrementalMarking(intptr_t step_size, 41 static GCIdleTimeAction IncrementalMarking(intptr_t step_size) {
44 bool reduce_memory) {
45 GCIdleTimeAction result; 42 GCIdleTimeAction result;
46 result.type = DO_INCREMENTAL_MARKING; 43 result.type = DO_INCREMENTAL_MARKING;
47 result.parameter = step_size; 44 result.parameter = step_size;
48 result.additional_work = false; 45 result.additional_work = false;
49 result.reduce_memory = reduce_memory;
50 return result; 46 return result;
51 } 47 }
52 48
53 static GCIdleTimeAction Scavenge() { 49 static GCIdleTimeAction Scavenge() {
54 GCIdleTimeAction result; 50 GCIdleTimeAction result;
55 result.type = DO_SCAVENGE; 51 result.type = DO_SCAVENGE;
56 result.parameter = 0; 52 result.parameter = 0;
57 result.additional_work = false; 53 result.additional_work = false;
58 // TODO(ulan): add reduce_memory argument and shrink new space size if
59 // reduce_memory = true.
60 result.reduce_memory = false;
61 return result; 54 return result;
62 } 55 }
63 56
64 static GCIdleTimeAction FullGC(bool reduce_memory) { 57 static GCIdleTimeAction FullGC() {
65 GCIdleTimeAction result; 58 GCIdleTimeAction result;
66 result.type = DO_FULL_GC; 59 result.type = DO_FULL_GC;
67 result.parameter = 0; 60 result.parameter = 0;
68 result.additional_work = false; 61 result.additional_work = false;
69 result.reduce_memory = reduce_memory;
70 return result; 62 return result;
71 } 63 }
72 64
73 static GCIdleTimeAction FinalizeSweeping() { 65 static GCIdleTimeAction FinalizeSweeping() {
74 GCIdleTimeAction result; 66 GCIdleTimeAction result;
75 result.type = DO_FINALIZE_SWEEPING; 67 result.type = DO_FINALIZE_SWEEPING;
76 result.parameter = 0; 68 result.parameter = 0;
77 result.additional_work = false; 69 result.additional_work = false;
78 result.reduce_memory = false;
79 return result; 70 return result;
80 } 71 }
81 72
82 void Print(); 73 void Print();
83 74
84 GCIdleTimeActionType type; 75 GCIdleTimeActionType type;
85 intptr_t parameter; 76 intptr_t parameter;
86 bool additional_work; 77 bool additional_work;
87 bool reduce_memory;
88 }; 78 };
89 79
90 80
91 class GCTracer; 81 class GCTracer;
92 82
93 // The idle time handler makes decisions about which garbage collection 83 // The idle time handler makes decisions about which garbage collection
94 // operations are executing during IdleNotification. 84 // operations are executing during IdleNotification.
95 class GCIdleTimeHandler { 85 class GCIdleTimeHandler {
96 public: 86 public:
97 // If we haven't recorded any incremental marking events yet, we carefully 87 // If we haven't recorded any incremental marking events yet, we carefully
(...skipping 23 matching lines...) Expand all
121 // EstimateFinalIncrementalMarkCompactTime. 111 // EstimateFinalIncrementalMarkCompactTime.
122 static const size_t kMaxFinalIncrementalMarkCompactTimeInMs; 112 static const size_t kMaxFinalIncrementalMarkCompactTimeInMs;
123 113
124 // This is the maximum scheduled idle time. Note that it can be more than 114 // This is the maximum scheduled idle time. Note that it can be more than
125 // 16.66 ms when there is currently no rendering going on. 115 // 16.66 ms when there is currently no rendering going on.
126 static const size_t kMaxScheduledIdleTime = 50; 116 static const size_t kMaxScheduledIdleTime = 50;
127 117
128 // The maximum idle time when frames are rendered is 16.66ms. 118 // The maximum idle time when frames are rendered is 16.66ms.
129 static const size_t kMaxFrameRenderingIdleTime = 17; 119 static const size_t kMaxFrameRenderingIdleTime = 17;
130 120
121 static const int kMinBackgroundIdleTime = 900;
122
131 // We conservatively assume that in the next kTimeUntilNextIdleEvent ms 123 // We conservatively assume that in the next kTimeUntilNextIdleEvent ms
132 // no idle notification happens. 124 // no idle notification happens.
133 static const size_t kTimeUntilNextIdleEvent = 100; 125 static const size_t kTimeUntilNextIdleEvent = 100;
134 126
135 // If we haven't recorded any scavenger events yet, we use a conservative 127 // If we haven't recorded any scavenger events yet, we use a conservative
136 // lower bound for the scavenger speed. 128 // lower bound for the scavenger speed.
137 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; 129 static const size_t kInitialConservativeScavengeSpeed = 100 * KB;
138 130
139 // The minimum size of allocated new space objects to trigger a scavenge. 131 // The minimum size of allocated new space objects to trigger a scavenge.
140 static const size_t kMinimumNewSpaceSizeToPerformScavenge = MB / 2; 132 static const size_t kMinimumNewSpaceSizeToPerformScavenge = MB / 2;
141 133
142 // If contexts are disposed at a higher rate a full gc is triggered. 134 // If contexts are disposed at a higher rate a full gc is triggered.
143 static const double kHighContextDisposalRate; 135 static const double kHighContextDisposalRate;
144 136
145 // Incremental marking step time. 137 // Incremental marking step time.
146 static const size_t kIncrementalMarkingStepTimeInMs = 1; 138 static const size_t kIncrementalMarkingStepTimeInMs = 1;
147 139
148 static const size_t kMinTimeForOverApproximatingWeakClosureInMs; 140 static const size_t kMinTimeForOverApproximatingWeakClosureInMs;
149 141
150 // The number of idle MarkCompact GCs to perform before transitioning to
151 // the kDone mode.
152 static const int kMaxIdleMarkCompacts = 3;
153
154 // The number of mutator MarkCompact GCs before transitioning to the
155 // kReduceLatency mode.
156 static const int kMarkCompactsBeforeMutatorIsActive = 1;
157
158 // Mutator is considered idle if
159 // 1) there are N idle notification with time >= kMinBackgroundIdleTime,
160 // 2) or there are M idle notifications with time >= kMinLongIdleTime
161 // without any mutator GC in between.
162 // Where N = kBackgroundIdleNotificationsBeforeMutatorIsIdle,
163 // M = kLongIdleNotificationsBeforeMutatorIsIdle
164 static const int kMinLongIdleTime = kMaxFrameRenderingIdleTime + 1;
165 static const int kMinBackgroundIdleTime = 900;
166 static const int kBackgroundIdleNotificationsBeforeMutatorIsIdle = 2;
167 static const int kLongIdleNotificationsBeforeMutatorIsIdle = 50;
168 // Number of times we will return a Nothing action in the current mode 142 // Number of times we will return a Nothing action in the current mode
169 // despite having idle time available before we returning a Done action to 143 // despite having idle time available before we returning a Done action to
170 // ensure we don't keep scheduling idle tasks and making no progress. 144 // ensure we don't keep scheduling idle tasks and making no progress.
171 static const int kMaxNoProgressIdleTimesPerMode = 10; 145 static const int kMaxNoProgressIdleTimes = 10;
172 146
173 class HeapState { 147 class HeapState {
174 public: 148 public:
175 void Print(); 149 void Print();
176 150
177 int contexts_disposed; 151 int contexts_disposed;
178 double contexts_disposal_rate; 152 double contexts_disposal_rate;
179 size_t size_of_objects; 153 size_t size_of_objects;
180 bool incremental_marking_stopped; 154 bool incremental_marking_stopped;
181 bool can_start_incremental_marking;
182 bool sweeping_in_progress; 155 bool sweeping_in_progress;
183 bool sweeping_completed; 156 bool sweeping_completed;
184 bool has_low_allocation_rate; 157 bool has_low_allocation_rate;
185 size_t mark_compact_speed_in_bytes_per_ms; 158 size_t mark_compact_speed_in_bytes_per_ms;
186 size_t incremental_marking_speed_in_bytes_per_ms; 159 size_t incremental_marking_speed_in_bytes_per_ms;
187 size_t final_incremental_mark_compact_speed_in_bytes_per_ms; 160 size_t final_incremental_mark_compact_speed_in_bytes_per_ms;
188 size_t scavenge_speed_in_bytes_per_ms; 161 size_t scavenge_speed_in_bytes_per_ms;
189 size_t used_new_space_size; 162 size_t used_new_space_size;
190 size_t new_space_capacity; 163 size_t new_space_capacity;
191 size_t new_space_allocation_throughput_in_bytes_per_ms; 164 size_t new_space_allocation_throughput_in_bytes_per_ms;
192 }; 165 };
193 166
194 GCIdleTimeHandler() 167 GCIdleTimeHandler() : idle_times_which_made_no_progress_(0) {}
195 : idle_mark_compacts_(0),
196 mark_compacts_(0),
197 scavenges_(0),
198 long_idle_notifications_(0),
199 background_idle_notifications_(0),
200 idle_times_which_made_no_progress_per_mode_(0),
201 next_gc_likely_to_collect_more_(false),
202 mode_(kReduceLatency) {}
203 168
204 GCIdleTimeAction Compute(double idle_time_in_ms, HeapState heap_state); 169 GCIdleTimeAction Compute(double idle_time_in_ms, HeapState heap_state);
205 170
206 void NotifyIdleMarkCompact() { ++idle_mark_compacts_; } 171 void ResetNoProgressCounter() { idle_times_which_made_no_progress_ = 0; }
207
208 void NotifyMarkCompact(bool next_gc_likely_to_collect_more) {
209 next_gc_likely_to_collect_more_ = next_gc_likely_to_collect_more;
210 ++mark_compacts_;
211 }
212
213 void NotifyScavenge() { ++scavenges_; }
214 172
215 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, 173 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms,
216 size_t marking_speed_in_bytes_per_ms); 174 size_t marking_speed_in_bytes_per_ms);
217 175
218 static size_t EstimateMarkCompactTime( 176 static size_t EstimateMarkCompactTime(
219 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); 177 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms);
220 178
221 static size_t EstimateFinalIncrementalMarkCompactTime( 179 static size_t EstimateFinalIncrementalMarkCompactTime(
222 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); 180 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms);
223 181
224 static bool ShouldDoMarkCompact(size_t idle_time_in_ms, 182 static bool ShouldDoMarkCompact(size_t idle_time_in_ms,
225 size_t size_of_objects, 183 size_t size_of_objects,
226 size_t mark_compact_speed_in_bytes_per_ms); 184 size_t mark_compact_speed_in_bytes_per_ms);
227 185
228 static bool ShouldDoContextDisposalMarkCompact(int context_disposed, 186 static bool ShouldDoContextDisposalMarkCompact(int context_disposed,
229 double contexts_disposal_rate); 187 double contexts_disposal_rate);
230 188
231 static bool ShouldDoFinalIncrementalMarkCompact( 189 static bool ShouldDoFinalIncrementalMarkCompact(
232 size_t idle_time_in_ms, size_t size_of_objects, 190 size_t idle_time_in_ms, size_t size_of_objects,
233 size_t final_incremental_mark_compact_speed_in_bytes_per_ms); 191 size_t final_incremental_mark_compact_speed_in_bytes_per_ms);
234 192
235 static bool ShouldDoOverApproximateWeakClosure(size_t idle_time_in_ms); 193 static bool ShouldDoOverApproximateWeakClosure(size_t idle_time_in_ms);
236 194
237 static bool ShouldDoScavenge( 195 static bool ShouldDoScavenge(
238 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, 196 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size,
239 size_t scavenger_speed_in_bytes_per_ms, 197 size_t scavenger_speed_in_bytes_per_ms,
240 size_t new_space_allocation_throughput_in_bytes_per_ms); 198 size_t new_space_allocation_throughput_in_bytes_per_ms);
241 199
242 enum Mode { kReduceLatency, kReduceMemory, kDone };
243
244 Mode mode() { return mode_; }
245
246 private: 200 private:
247 bool IsMutatorActive(int contexts_disposed, int gcs);
248 bool IsMutatorIdle(int long_idle_notifications,
249 int background_idle_notifications, int gcs);
250 void UpdateCounters(double idle_time_in_ms);
251 void ResetCounters();
252 Mode NextMode(const HeapState& heap_state);
253 GCIdleTimeAction Action(double idle_time_in_ms, const HeapState& heap_state,
254 bool reduce_memory);
255 GCIdleTimeAction NothingOrDone(); 201 GCIdleTimeAction NothingOrDone();
256 202
257 int idle_mark_compacts_; 203 // Idle notifications with no progress.
258 int mark_compacts_; 204 int idle_times_which_made_no_progress_;
259 int scavenges_;
260 // The number of long idle notifications with no GC happening
261 // between the notifications.
262 int long_idle_notifications_;
263 // The number of background idle notifications with no GC happening
264 // between the notifications.
265 int background_idle_notifications_;
266 // Idle notifications with no progress in the current mode.
267 int idle_times_which_made_no_progress_per_mode_;
268
269 bool next_gc_likely_to_collect_more_;
270
271 Mode mode_;
272 205
273 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); 206 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler);
274 }; 207 };
275 208
276 } // namespace internal 209 } // namespace internal
277 } // namespace v8 210 } // namespace v8
278 211
279 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ 212 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/heap/gc-idle-time-handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698