Skip to content

Commit 64813f4

Browse files
author
Thomas Schatzl
committed
8294850: Make rs length/pending card predictors dependent on gc phase
Reviewed-by: kbarrett, iwalulya, ayang
1 parent 21e4f06 commit 64813f4

File tree

3 files changed

+65
-41
lines changed

3 files changed

+65
-41
lines changed

src/hotspot/share/gc/g1/g1Analytics.cpp

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ G1Analytics::G1Analytics(const G1Predictions* predictor) :
7878
_concurrent_mark_cleanup_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
7979
_alloc_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
8080
_prev_collection_pause_end_ms(0.0),
81-
_rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)),
81+
_young_rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)),
82+
_mixed_rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)),
8283
_concurrent_refine_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
8384
_dirtied_cards_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
8485
_young_card_merge_to_scan_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),
@@ -91,8 +92,10 @@ G1Analytics::G1Analytics(const G1Predictions* predictor) :
9192
_constant_other_time_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
9293
_young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
9394
_non_young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
94-
_pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
95-
_rs_length_seq(new TruncatedSeq(TruncatedSeqLength)),
95+
_young_pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
96+
_mixed_pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
97+
_young_rs_length_seq(new TruncatedSeq(TruncatedSeqLength)),
98+
_mixed_rs_length_seq(new TruncatedSeq(TruncatedSeqLength)),
9699
_cost_per_byte_ms_during_cm_seq(new TruncatedSeq(TruncatedSeqLength)),
97100
_recent_prev_end_times_for_all_gcs_sec(new TruncatedSeq(NumPrevPausesForHeuristics)),
98101
_long_term_pause_time_ratio(0.0),
@@ -104,7 +107,7 @@ G1Analytics::G1Analytics(const G1Predictions* predictor) :
104107

105108
int index = MIN2(ParallelGCThreads - 1, 7u);
106109

107-
_rs_length_diff_seq->add(rs_length_diff_defaults[index]);
110+
_young_rs_length_diff_seq->add(rs_length_diff_defaults[index]);
108111
// Start with inverse of maximum STW cost.
109112
_concurrent_refine_rate_ms_seq->add(1/cost_per_logged_card_ms_defaults[0]);
110113
// Some applications have very low rates for logging cards.
@@ -193,8 +196,12 @@ void G1Analytics::report_card_merge_to_scan_ratio(double merge_to_scan_ratio, bo
193196
}
194197
}
195198

196-
void G1Analytics::report_rs_length_diff(double rs_length_diff) {
197-
_rs_length_diff_seq->add(rs_length_diff);
199+
void G1Analytics::report_rs_length_diff(double rs_length_diff, bool for_young_gc) {
200+
if (for_young_gc) {
201+
_young_rs_length_diff_seq->add(rs_length_diff);
202+
} else {
203+
_mixed_rs_length_diff_seq->add(rs_length_diff);
204+
}
198205
}
199206

200207
void G1Analytics::report_cost_per_byte_ms(double cost_per_byte_ms, bool mark_or_rebuild_in_progress) {
@@ -217,12 +224,20 @@ void G1Analytics::report_constant_other_time_ms(double constant_other_time_ms) {
217224
_constant_other_time_ms_seq->add(constant_other_time_ms);
218225
}
219226

220-
void G1Analytics::report_pending_cards(double pending_cards) {
221-
_pending_cards_seq->add(pending_cards);
227+
void G1Analytics::report_pending_cards(double pending_cards, bool for_young_gc) {
228+
if (for_young_gc) {
229+
_young_pending_cards_seq->add(pending_cards);
230+
} else {
231+
_mixed_pending_cards_seq->add(pending_cards);
232+
}
222233
}
223234

224-
void G1Analytics::report_rs_length(double rs_length) {
225-
_rs_length_seq->add(rs_length);
235+
void G1Analytics::report_rs_length(double rs_length, bool for_young_gc) {
236+
if (for_young_gc) {
237+
_young_rs_length_seq->add(rs_length);
238+
} else {
239+
_mixed_rs_length_seq->add(rs_length);
240+
}
226241
}
227242

228243
double G1Analytics::predict_alloc_rate_ms() const {
@@ -301,12 +316,20 @@ double G1Analytics::predict_cleanup_time_ms() const {
301316
return predict_zero_bounded(_concurrent_mark_cleanup_times_ms);
302317
}
303318

304-
size_t G1Analytics::predict_rs_length() const {
305-
return predict_size(_rs_length_seq) + predict_size(_rs_length_diff_seq);
319+
size_t G1Analytics::predict_rs_length(bool for_young_gc) const {
320+
if (for_young_gc || !enough_samples_available(_mixed_rs_length_seq)) {
321+
return predict_size(_young_rs_length_seq) + predict_size(_young_rs_length_diff_seq);
322+
} else {
323+
return predict_size(_mixed_rs_length_seq) + predict_size(_mixed_rs_length_diff_seq);
324+
}
306325
}
307326

308-
size_t G1Analytics::predict_pending_cards() const {
309-
return predict_size(_pending_cards_seq);
327+
size_t G1Analytics::predict_pending_cards(bool for_young_gc) const {
328+
if (for_young_gc || !enough_samples_available(_mixed_pending_cards_seq)) {
329+
return predict_size(_young_pending_cards_seq);
330+
} else {
331+
return predict_size(_mixed_pending_cards_seq);
332+
}
310333
}
311334

312335
double G1Analytics::oldest_known_gc_end_time_sec() const {

src/hotspot/share/gc/g1/g1Analytics.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class G1Analytics: public CHeapObj<mtGC> {
4545
TruncatedSeq* _alloc_rate_ms_seq;
4646
double _prev_collection_pause_end_ms;
4747

48-
TruncatedSeq* _rs_length_diff_seq;
48+
TruncatedSeq* _young_rs_length_diff_seq;
49+
TruncatedSeq* _mixed_rs_length_diff_seq;
4950
TruncatedSeq* _concurrent_refine_rate_ms_seq;
5051
TruncatedSeq* _dirtied_cards_rate_ms_seq;
5152
// The ratio between the number of merged cards and actually scanned cards, for
@@ -67,8 +68,10 @@ class G1Analytics: public CHeapObj<mtGC> {
6768
TruncatedSeq* _young_other_cost_per_region_ms_seq;
6869
TruncatedSeq* _non_young_other_cost_per_region_ms_seq;
6970

70-
TruncatedSeq* _pending_cards_seq;
71-
TruncatedSeq* _rs_length_seq;
71+
TruncatedSeq* _young_pending_cards_seq;
72+
TruncatedSeq* _mixed_pending_cards_seq;
73+
TruncatedSeq* _young_rs_length_seq;
74+
TruncatedSeq* _mixed_rs_length_seq;
7275

7376
TruncatedSeq* _cost_per_byte_ms_during_cm_seq;
7477

@@ -126,13 +129,13 @@ class G1Analytics: public CHeapObj<mtGC> {
126129
void report_cost_per_card_scan_ms(double cost_per_remset_card_ms, bool for_young_gc);
127130
void report_cost_per_card_merge_ms(double cost_per_card_ms, bool for_young_gc);
128131
void report_card_merge_to_scan_ratio(double cards_per_entry_ratio, bool for_young_gc);
129-
void report_rs_length_diff(double rs_length_diff);
132+
void report_rs_length_diff(double rs_length_diff, bool for_young_gc);
130133
void report_cost_per_byte_ms(double cost_per_byte_ms, bool mark_or_rebuild_in_progress);
131134
void report_young_other_cost_per_region_ms(double other_cost_per_region_ms);
132135
void report_non_young_other_cost_per_region_ms(double other_cost_per_region_ms);
133136
void report_constant_other_time_ms(double constant_other_time_ms);
134-
void report_pending_cards(double pending_cards);
135-
void report_rs_length(double rs_length);
137+
void report_pending_cards(double pending_cards, bool for_young_gc);
138+
void report_rs_length(double rs_length, bool for_young_gc);
136139

137140
double predict_alloc_rate_ms() const;
138141
int num_alloc_rate_ms() const;
@@ -161,8 +164,8 @@ class G1Analytics: public CHeapObj<mtGC> {
161164

162165
double predict_cleanup_time_ms() const;
163166

164-
size_t predict_rs_length() const;
165-
size_t predict_pending_cards() const;
167+
size_t predict_rs_length(bool for_young_gc) const;
168+
size_t predict_pending_cards(bool for_young_gc) const;
166169

167170
// Add a new GC of the given duration and end time to the record.
168171
void update_recent_gc_times(double end_time_sec, double elapsed_ms);

src/hotspot/share/gc/g1/g1Policy.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ uint G1Policy::calculate_desired_eden_length_by_mmu() const {
194194
}
195195

196196
void G1Policy::update_young_length_bounds() {
197-
update_young_length_bounds(_analytics->predict_pending_cards(),
198-
_analytics->predict_rs_length());
197+
bool for_young_gc = collector_state()->in_young_only_phase();
198+
update_young_length_bounds(_analytics->predict_pending_cards(for_young_gc),
199+
_analytics->predict_rs_length(for_young_gc));
199200
}
200201

201202
void G1Policy::update_young_length_bounds(size_t pending_cards, size_t rs_length) {
@@ -525,14 +526,15 @@ void G1Policy::revise_young_list_target_length_if_necessary(size_t rs_length) {
525526
update_rs_length_prediction(rs_length_prediction);
526527

527528
G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
528-
// We have no measure of the number of cards in the thread log buffers, assume
529-
// these are very few compared to the sum of the two other sources.
529+
// We have no measure of the number of cards in the thread buffers, assume
530+
// these are very few compared to the ones in the DCQS.
530531
update_young_length_bounds(dcqs.num_cards(), rs_length_prediction);
531532
}
532533
}
533534

534535
void G1Policy::update_rs_length_prediction() {
535-
update_rs_length_prediction(_analytics->predict_rs_length());
536+
bool for_young_gc = collector_state()->in_young_only_phase();
537+
update_rs_length_prediction(_analytics->predict_rs_length(for_young_gc));
536538
}
537539

538540
void G1Policy::update_rs_length_prediction(size_t prediction) {
@@ -753,6 +755,7 @@ void G1Policy::record_young_collection_end(bool concurrent_operation_is_full_mar
753755
double pause_time_ms = (end_time_sec - start_time_sec) * 1000.0;
754756

755757
G1GCPauseType this_pause = collector_state()->young_gc_pause_type(concurrent_operation_is_full_mark);
758+
bool is_young_only_pause = G1GCPauseTypeHelper::is_young_only_pause(this_pause);
756759

757760
if (G1GCPauseTypeHelper::is_concurrent_start_pause(this_pause)) {
758761
record_concurrent_mark_init_end();
@@ -806,7 +809,7 @@ void G1Policy::record_young_collection_end(bool concurrent_operation_is_full_mar
806809
maybe_start_marking();
807810
}
808811
} else {
809-
assert(G1GCPauseTypeHelper::is_young_only_pause(this_pause), "must be");
812+
assert(is_young_only_pause, "must be");
810813
}
811814

812815
_eden_surv_rate_group->start_adding_regions();
@@ -830,8 +833,7 @@ void G1Policy::record_young_collection_end(bool concurrent_operation_is_full_mar
830833
average_time_ms(G1GCPhaseTimes::MergeHCC) +
831834
average_time_ms(G1GCPhaseTimes::MergeLB) +
832835
average_time_ms(G1GCPhaseTimes::OptMergeRS);
833-
_analytics->report_cost_per_card_merge_ms(avg_time_merge_cards / total_cards_merged,
834-
G1GCPauseTypeHelper::is_young_only_pause(this_pause));
836+
_analytics->report_cost_per_card_merge_ms(avg_time_merge_cards / total_cards_merged, is_young_only_pause);
835837
}
836838

837839
// Update prediction for card scan
@@ -842,8 +844,7 @@ void G1Policy::record_young_collection_end(bool concurrent_operation_is_full_mar
842844
double avg_time_dirty_card_scan = average_time_ms(G1GCPhaseTimes::ScanHR) +
843845
average_time_ms(G1GCPhaseTimes::OptScanHR);
844846

845-
_analytics->report_cost_per_card_scan_ms(avg_time_dirty_card_scan / total_cards_scanned,
846-
G1GCPauseTypeHelper::is_young_only_pause(this_pause));
847+
_analytics->report_cost_per_card_scan_ms(avg_time_dirty_card_scan / total_cards_scanned, is_young_only_pause);
847848
}
848849

849850
// Update prediction for the ratio between cards from the remembered
@@ -857,12 +858,11 @@ void G1Policy::record_young_collection_end(bool concurrent_operation_is_full_mar
857858
if (total_cards_scanned > 0) {
858859
merge_to_scan_ratio = (double) from_rs_length_cards / total_cards_scanned;
859860
}
860-
_analytics->report_card_merge_to_scan_ratio(merge_to_scan_ratio,
861-
G1GCPauseTypeHelper::is_young_only_pause(this_pause));
861+
_analytics->report_card_merge_to_scan_ratio(merge_to_scan_ratio, is_young_only_pause);
862862

863863
const size_t recorded_rs_length = _collection_set->recorded_rs_length();
864864
const size_t rs_length_diff = _rs_length > recorded_rs_length ? _rs_length - recorded_rs_length : 0;
865-
_analytics->report_rs_length_diff(rs_length_diff);
865+
_analytics->report_rs_length_diff(rs_length_diff, is_young_only_pause);
866866

867867
// Update prediction for copy cost per byte
868868
size_t copied_bytes = p->sum_thread_work_items(G1GCPhaseTimes::MergePSS, G1GCPhaseTimes::MergePSSCopiedBytes);
@@ -887,11 +887,8 @@ void G1Policy::record_young_collection_end(bool concurrent_operation_is_full_mar
887887
// Do not update RS lengths and the number of pending cards with information from mixed gc:
888888
// these are is wildly different to during young only gc and mess up young gen sizing right
889889
// after the mixed gc phase.
890-
// During mixed gc we do not use them for young gen sizing.
891-
if (G1GCPauseTypeHelper::is_young_only_pause(this_pause)) {
892-
_analytics->report_pending_cards((double) _pending_cards_at_gc_start);
893-
_analytics->report_rs_length((double) _rs_length);
894-
}
890+
_analytics->report_pending_cards((double) _pending_cards_at_gc_start, is_young_only_pause);
891+
_analytics->report_rs_length((double) _rs_length, is_young_only_pause);
895892
}
896893

897894
assert(!(G1GCPauseTypeHelper::is_concurrent_start_pause(this_pause) && collector_state()->mark_or_rebuild_in_progress()),
@@ -1036,7 +1033,8 @@ double G1Policy::predict_base_time_ms(size_t pending_cards,
10361033
}
10371034

10381035
double G1Policy::predict_base_time_ms(size_t pending_cards) const {
1039-
size_t rs_length = _analytics->predict_rs_length();
1036+
bool for_young_gc = collector_state()->in_young_only_phase();
1037+
size_t rs_length = _analytics->predict_rs_length(for_young_gc);
10401038
return predict_base_time_ms(pending_cards, rs_length);
10411039
}
10421040

0 commit comments

Comments
 (0)