RFR: 8238687: Investigate memory uncommit during young collections in G1 [v4]
Thomas Schatzl
tschatzl at openjdk.org
Tue Jun 24 08:39:31 UTC 2025
On Thu, 19 Jun 2025 12:26:15 GMT, Ivan Walulya <iwalulya at openjdk.org> wrote:
>> Hi all,
>>
>> Please review this change to the G1 heap resizing policy, aimed at improving alignment with the configured GCTimeRatio. The GCTimeRatio is intended to manage the balance between GC time and Application execution time. G1's current implementation of GCTimeRatio appears to have drifted from its intended purpose over time. Therefore, we need to change G1’s use of the GCTimeRatio to better manage heap sizes without relying on additional magic constants.
>>
>> The primary goal is to enable both heap expansion and shrinking at the end of any GC, rather than limiting shrinking to only the Remark or Full GC pauses as is currently done. We achieve this using heuristics that monitor both short-term and long-term GC time ratios relative to the configured GCTimeRatio.
>>
>> - The short-term policy adjusts a counter based on whether recent GC time is above or below a target range around GCTimeRatio (as defined by G1MinimumPercentOfGCTimeRatio). When the counter crosses predefined thresholds, the heap may be expanded or shrunk accordingly.
>>
>> - The long-term policy evaluates the GC time ratio over a long-term interval and triggers resizing if the number of recorded ratios exceeds a threshold and the GC time ratio over the long-term interval is outside the target range.
>>
>> - These heuristics allow for responsive heap resizing (both expansion and shrinking) at the end of any GC, guided by actual GC performance rather than fixed thresholds or constants.
>>
>> We are increasing the default GCTimeRatio from 12 to 24, since under the new policy, the current default leads to overly aggressive heap shrinking as the GCTimeRatio allows for a lot more GC overhead.
>>
>> Additionally, we are removing the heap resizing step at the end of the Remark pause which was based on MinHeapFreeRatio and MaxHeapFreeRatio. We keep this MinHeapFreeRatio-MaxHeapFreeRatio based resizing logic at the end of Full GC and Remark pauses that may have been triggered by PeriodicGCs.
>>
>> As a result of these changes, some applications may settle at more appropriate and in some cases smaller heap sizes for the configured GCTimeRatio. While this may appear as a regression in some benchmarks that are sensitive to heap size, it represents more accurate G1 behavior with respect to the GCTimeRatio. Although smaller heap sizes may lead to more frequent GCs, this is the expected outcome, provided the cumulative GC overhead remains within the limits defined by the GCTimeRatio.
>>
>> Testing: Mach5 ...
>
> Ivan Walulya has updated the pull request incrementally with one additional commit since the last revision:
>
> Albert suggestions
Some typos
src/hotspot/share/gc/g1/g1HeapSizingPolicy.cpp line 410:
> 408: // with respect to the heap max size as it's an upper bound (i.e.,
> 409: // we'll try to make the capacity smaller than it, not greater).
> 410: maximum_desired_capacity = MAX2(maximum_desired_capacity, _g1h->min_capacity());
Suggestion:
maximum_desired_capacity = MAX2(maximum_desired_capacity, _g1h->min_capacity());
src/hotspot/share/gc/g1/g1HeapSizingPolicy.hpp line 39:
> 37: // For young collections, this heuristics is based on gc time ratio, i.e. trying
> 38: // to change the heap so that current gc time ratio stays approximately as
> 39: // selected by the user.
Suggestion:
// selected by the user.
src/hotspot/share/gc/g1/g1HeapSizingPolicy.hpp line 44:
> 42: // change.
> 43: //
> 44: // Short term tracking is based on the short-term gc time ratio i.e we count
Suggestion:
// Short term tracking is based on the short-term gc time ratio i.e we count
src/hotspot/share/gc/g1/g1HeapSizingPolicy.hpp line 65:
> 63: // Long term behavior is solely managed by regularly comparing actual long term gc
> 64: // time ratio with the boundaries of above range in regular long term intervals.
> 65: // If current long term gc time ratio is outside, expand or shrink respectively.
Suggestion:
// time ratio with the boundaries of above range in regular long term intervals.
// If current long term gc time ratio is outside, expand or shrink respectively.
src/hotspot/share/gc/g1/g1HeapSizingPolicy.hpp line 79:
> 77: uint long_term_count_limit() const;
> 78: // Number of times short-term gc time ratio crossed the lower or upper threshold
> 79: // recently; every time the upper threshold is exceeded, it is incremented, and
Suggestion:
// recently; every time the upper threshold is exceeded, it is incremented, and
-------------
Changes requested by tschatzl (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/25832#pullrequestreview-2952720651
PR Review Comment: https://git.openjdk.org/jdk/pull/25832#discussion_r2163309395
PR Review Comment: https://git.openjdk.org/jdk/pull/25832#discussion_r2163311368
PR Review Comment: https://git.openjdk.org/jdk/pull/25832#discussion_r2163300891
PR Review Comment: https://git.openjdk.org/jdk/pull/25832#discussion_r2163310414
PR Review Comment: https://git.openjdk.org/jdk/pull/25832#discussion_r2163309782
More information about the hotspot-dev
mailing list