Skip to content

8238687: Investigate memory uncommit during young collections in G1 #25832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

walulyai
Copy link
Member

@walulyai walulyai commented Jun 16, 2025

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 Tier 1-7


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-8238687: Investigate memory uncommit during young collections in G1 (Enhancement - P4)
  • JDK-8247843: Reconsider G1 default GCTimeRatio value (Enhancement - P4)
  • JDK-8248324: G1: Remove resizing during Remark (Enhancement - P4)

Contributors

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25832/head:pull/25832
$ git checkout pull/25832

Update a local copy of the PR:
$ git checkout pull/25832
$ git pull https://git.openjdk.org/jdk.git pull/25832/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25832

View PR using the GUI difftool:
$ git pr show -t 25832

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25832.diff

Using Webrev

Link to Webrev Comment

@walulyai
Copy link
Member Author

/contributor add tschatzl

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 16, 2025

👋 Welcome back iwalulya! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 16, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Jun 16, 2025

@walulyai
Contributor Thomas Schatzl <[email protected]> successfully added.

@walulyai
Copy link
Member Author

/issue add JDK-8247843

@openjdk
Copy link

openjdk bot commented Jun 16, 2025

@walulyai The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk
Copy link

openjdk bot commented Jun 16, 2025

@walulyai
Adding additional issue to issue list: 8247843: Reconsider G1 default GCTimeRatio value.

@walulyai
Copy link
Member Author

/issue add JDK-8248324

@openjdk
Copy link

openjdk bot commented Jun 16, 2025

@walulyai
Adding additional issue to issue list: 8248324: G1: Remove resizing during Remark.

@walulyai walulyai marked this pull request as ready for review June 16, 2025 14:32
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 16, 2025
@mlbridge
Copy link

mlbridge bot commented Jun 16, 2025

Webrevs

@walulyai
Copy link
Member Author

/label add hotspot-gc

@openjdk
Copy link

openjdk bot commented Jun 16, 2025

@walulyai
The hotspot-gc label was successfully added.

@openjdk
Copy link

openjdk bot commented Jun 17, 2025

@walulyai this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout G1HeapResizePolicyV2
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Jun 17, 2025
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Jun 17, 2025
Comment on lines 164 to 170
product(size_t, G1ShrinkByPercentOfAvailable, 50, EXPERIMENTAL, \
"When shrinking, maximum % of free space to claim.") \
range(0, 100) \
\
product(size_t, G1MinimumPercentOfGCTimeRatio, 25, EXPERIMENTAL, \
"Percentage of GCTimeRatio G1 will try to avoid going below.") \
range(0, 100) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are in [0,100], maybe uint is enough?

@@ -47,7 +47,7 @@ class AbsSeq: public CHeapObj<mtInternal> {
void init(double alpha);

protected:
int _num; // the number of elements in the sequence
uint _num; // the number of elements in the sequence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All int -> uint changes in this class/file are good; can they be extracted out to its own PR/ticket?

expand(resize_bytes, _workers);
} else {
shrink(resize_bytes);
uncommit_regions_if_necessary();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's more symmetric if this uncommit logic is inlined to shrink.

@@ -127,6 +128,8 @@ class TruncatedSeq: public AbsSeq {
double oldest() const; // the oldest valid value in the sequence
double predict_next() const; // prediction based on linear regression

virtual void reset();
bool is_full() const { return _length == _num; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unused.

AbsSeq(alpha), _length(length), _next(0) {
_sequence = NEW_C_HEAP_ARRAY(double, _length, mtInternal);
for (int i = 0; i < _length; ++i)
_sequence[i] = 0.0;
TruncatedSeq::reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why a new method (reset) is needed inside this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants