RFR: 8238687: Investigate memory uncommit during young collections in G1 [v4]
Thomas Schatzl
tschatzl at openjdk.org
Tue Jun 24 15:52:32 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
src/hotspot/share/gc/g1/g1HeapSizingPolicy.cpp line 231:
> 229: const double min_gc_time_ratio_ratio = G1MinimumPercentOfGCTimeRatio / 100.0;
> 230: double upper_threshold = pause_time_threshold * (1 + min_gc_time_ratio_ratio);
> 231: double lower_threshold = pause_time_threshold * (1 - min_gc_time_ratio_ratio);
There are some inconsistencies naming variables in this change: we use `pause_time_threshold`, `pause_time_ratio` and other similar terms that are under(de)fined for, essentially, (parts of) the cpu resources that G1 uses.
Also some things are called "ratio", but are percentages (e.g. `G1MinimumPercentOfGCTimeRatio`), and the comments somewhat interchangeably use cpu usage (in percent) and gctimeratio (the inverse of cpu usage).
I think it is useful to clean this up, also looking forward to making G1 start using actual GC CPU usage (thread user times), e.g.
pause_time_threshold -> gc_cpu_usage_threshold
long_term_pause_time_ratio -> long_term_cpu_usage
[and so on]
I admit that right now `cpu_usage` might be slightly misleading because we only approximate it using pause times and total run times (which do not necessarily reflect actual cpu usage), but it seems good enough for now, and future changes (https://bugs.openjdk.org/browse/JDK-8359348; even with that we might need to fallback to current mechanism).
What do others think?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25832#discussion_r2164372113
More information about the hotspot-dev
mailing list