Skip to content

Commit

Permalink
Ignore ZGC warmup + zero-sized live data after GC
Browse files Browse the repository at this point in the history
In some cases, the live data after GC size in the GC notification is
reported as 0 when ZGC is warming up.
We should ignore these notifications.

Closes gh-4497
  • Loading branch information
jonatan-ivanov committed Jan 19, 2024
1 parent 8fe8842 commit 3c46759
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ public void handleNotification(Notification notification, Object ref) {

// Some GC implementations such as G1 can reduce the old gen size as part of a
// minor GC. To track the live data size we record the value if we see a
// reduction in the long-lived
// heap size or after a major/non-generational GC. In some cases,
// longLivedAfter is 0, we ignore those notifications, see: gh-4497.
if (longLivedAfter > 0 && (longLivedAfter < longLivedBefore
|| shouldUpdateDataSizeMetrics(notificationInfo.getGcName()))) {
// reduction in the long-lived heap size or after a major/non-generational GC.
// ZGC Warmup notifications should be ignored since the long-lived heap size
// is zero there.
if ((longLivedAfter < longLivedBefore || shouldUpdateDataSizeMetrics(notificationInfo.getGcName()))
&& !isZgcWarmingUp(gcCause, longLivedAfter)) {
liveDataSize.set(longLivedAfter);
maxDataSize.set(longLivedPoolNames.stream().mapToLong(pool -> after.get(pool).getMax()).sum());
}
Expand All @@ -242,6 +242,19 @@ private void countPoolSizeDelta(Map<String, MemoryUsage> before, Map<String, Mem
}
}

/**
* Sometimes ZGC emits "Warmup" notification, where longLivedAfter is 0, we should
* ignore those notifications, see: gh-4497. This method should detect these
* cases.
* @param gcCause The action performed by the garbage collector
* @param longLivedAfter Size of the long-lived pools after collection
* @return Whether the ZGC warmup notification is emitted with zero long-lived
* pools size
*/
private boolean isZgcWarmingUp(String gcCause, long longLivedAfter) {
return longLivedAfter == 0 && "Warmup".equals(gcCause);
}

private boolean shouldUpdateDataSizeMetrics(String gcName) {
return nonGenerationalGcShouldUpdateDataSize(gcName) || isMajorGenerationalGc(gcName);
}
Expand Down

0 comments on commit 3c46759

Please sign in to comment.