Skip to content

Commit f6d6a07

Browse files
committed
8256938: Improve remembered set sampling task scheduling
Reviewed-by: tschatzl, ayang
1 parent b823ad9 commit f6d6a07

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,12 @@ class G1RemSetSamplingTask : public G1ServiceTask {
548548
// reevaluates the prediction for the remembered set scanning costs, and potentially
549549
// G1Policy resizes the young gen. This may do a premature GC or even
550550
// increase the young gen size to keep pause time length goal.
551-
void sample_young_list_rs_length(){
552-
SuspendibleThreadSetJoiner sts;
551+
void sample_young_list_rs_length(SuspendibleThreadSetJoiner* sts){
553552
G1CollectedHeap* g1h = G1CollectedHeap::heap();
554553
G1Policy* policy = g1h->policy();
555554

556555
if (policy->use_adaptive_young_list_length()) {
557-
G1YoungRemSetSamplingClosure cl(&sts);
556+
G1YoungRemSetSamplingClosure cl(sts);
558557

559558
G1CollectionSet* g1cs = g1h->collection_set();
560559
g1cs->iterate(&cl);
@@ -565,10 +564,36 @@ class G1RemSetSamplingTask : public G1ServiceTask {
565564
}
566565
}
567566

567+
// To avoid extensive rescheduling if the task is executed a bit early. The task is
568+
// only rescheduled if the expected time is more than 1ms away.
569+
bool should_reschedule() {
570+
return reschedule_delay_ms() > 1;
571+
}
572+
573+
// There is no reason to do the sampling if a GC occurred recently. We use the
574+
// G1ConcRefinementServiceIntervalMillis as the metric for recently and calculate
575+
// the diff to the last GC. If the last GC occurred longer ago than the interval
576+
// 0 is returned.
577+
jlong reschedule_delay_ms() {
578+
Tickspan since_last_gc = G1CollectedHeap::heap()->time_since_last_collection();
579+
jlong delay = (jlong) (G1ConcRefinementServiceIntervalMillis - since_last_gc.milliseconds());
580+
return MAX2<jlong>(0L, delay);
581+
}
582+
568583
public:
569584
G1RemSetSamplingTask(const char* name) : G1ServiceTask(name) { }
570585
virtual void execute() {
571-
sample_young_list_rs_length();
586+
SuspendibleThreadSetJoiner sts;
587+
588+
// Reschedule if a GC happened too recently.
589+
if (should_reschedule()) {
590+
// Calculate the delay given the last GC and the interval.
591+
schedule(reschedule_delay_ms());
592+
return;
593+
}
594+
595+
// Do the actual sampling.
596+
sample_young_list_rs_length(&sts);
572597
schedule(G1ConcRefinementServiceIntervalMillis);
573598
}
574599
};

0 commit comments

Comments
 (0)