<div dir="ltr"><span id="gmail-docs-internal-guid-bf89b17a-7fff-f889-e580-52899a30c04f"><p style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><font color="#000000" face="Arial, sans-serif"><span style="white-space-collapse: preserve;">Hi All,</span></font></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal" id="gmail-docs-internal-guid-b2d000e7-7fff-2b0d-1633-5d85a8a53be2"><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">As Kirk mentioned in his email "</span><a href="https://mail.openjdk.org/pipermail/hotspot-gc-dev/2024-September/049616.html" style="text-decoration:none"><span style="font-family:Arial,sans-serif;color:rgb(17,85,204);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">Aligning the Serial collector with ZGC</span></a><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">", we are also working on adding Adaptable Heap Sizing (AHS) to G1.</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><font color="#000000">I created a </font><a href="https://github.com/openjdk/jdk/pull/20783" style="text-decoration:none"><span style="font-family:Arial,sans-serif;color:rgb(17,85,204);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">draft Pull Request</span></a> and received some comments on it already<span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">, including the following points:</span></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"><br></span></p><ol style="margin-top:0px;margin-bottom:0px"><li dir="ltr" style="list-style-type:decimal;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;margin-left:36pt"><p dir="ltr" style="line-height:1.38;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt" role="presentation"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">I should Convert CurrentMaxExpansionSize to CurrentMaxHeapSize.</span></p></li><li dir="ltr" style="list-style-type:decimal;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;margin-left:36pt"><p dir="ltr" style="line-height:1.38;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt" role="presentation"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">SoftMaxHeapSize, as implemented in the PR, is different from the original intent.</span></p></li><li dir="ltr" style="list-style-type:decimal;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;margin-left:36pt"><p dir="ltr" style="line-height:1.38;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt" role="presentation"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">We need some sort of global memory pressure to enforce heap shrinkage.</span></p></li></ol><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">The first point I already addressed on the pull request, and I agree that CurrentMaxHeapSize works well :) </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Regarding the second point, we had some discussions already outside of this mailing list, but if I were to summarize the main ideas, they are:</span></p><ol style="margin-top:0px;margin-bottom:0px"><li dir="ltr" style="list-style-type:decimal;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre"><p dir="ltr" style="line-height:1.38;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt" role="presentation"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">The intent of SoftMaxHeapSize initially was for the GC to use this value as a guide for when to start concurrent GC.</span></p></li><li dir="ltr" style="list-style-type:decimal;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre"><p dir="ltr" style="line-height:1.38;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt" role="presentation"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Our implementation of SoftMaxHeapSize (in the PR) currently behaves more like a ProposedHeapSize, where whenever we shrink and expand the heap, we try to set the heap size to ProposedHeapSize, regardless of the value of MinHeapSize. </span></p></li><li dir="ltr" style="list-style-type:decimal;font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre"><p dir="ltr" style="line-height:1.38;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt" role="presentation"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">We need to ensure that the heap regularly approaches the value of ProposedHeapSize by introducing some sort of periodic GC, which we have a Google-internal patch for, and is not yet present in the PR. If we are in alignment that this makes sense, I can try adding this as a separate PR.</span></p></li></ol><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(0,0,0);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">For the third point, </span><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> Similar to ZGC's </span><span style="font-family:Arial,sans-serif;color:rgb(24,128,56);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">-XX:ZGCPressure</span><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">, we use </span><span style="font-family:Arial,sans-serif;color:rgb(24,128,56);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">target_gc_cpu_overhead</span><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap"> (along with periodic GC) to control heap shrinkage by adjusting </span><span style="font-family:Arial,sans-serif;color:rgb(24,128,56);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">ProposedHeapSize</span><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">. This allows users to balance RAM and CPU usage. Note that this isn't yet present in the PR, since the PR only includes the JVM changes introducing the CurrentMaxHeapSize and ProposedHeapSize flags. The logic to actually dynamically calculate the value of ProposedHeapSize would be a separate change, and can be iterated on.</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">As a separate point - Kirk mentioned in his email that he aims to introduce an adaptive size policy where "Heap should be large enough to minimize GC overhead but not large enough to trigger OOM". I think from our experience in G1, we don't actively try to minimize GC overhead, as we find that maintaining a higher GC overhead often results in overall RAM savings >> CPU usage. </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">I think as a general summary - the way I see it, there's value in creating a simplified system where we control the majority of JVM behavior simply with two flags - the maximum heap size (to prevent OOMs), and a target heap size, which is our calculation of an "optimal" size based on our understanding of the environment. The exact calculations for this optimal size may change depending on workload/preference, but what we are trying to do at this point in time is allow for a way to pass in some calculation for "optimal heap size" and have G1 react to it in a meaningful way. I acknowledge that the current JVM behavior (as implemented in my PR) may be suboptimal in terms of getting the heap to get to and stay at this "optimal heap size". However, even with the basic implementation of passing this value to shrinks/expands and only triggering resizes on Remarks/Full GCs, we've seen dramatic improvements in heap behavior at Google, compared to the current G1. </span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">I know there was some disagreement about the addition of this new "optimal heap size" flag, and I agree that SoftMaxHeapSize is probably not the right flag to represent this value. But I'd like to get some thoughts on whether the above summary seems like a reasonable way of reasoning about G1 AHS. If we agree, then we can always iteratively improve the JVM logic to better adhere to the optimal heap size. But it's not yet clear to me whether people are onboard the idea of having this "optimal heap size" calculation at all, since perhaps this functionality could be covered in other, existing ways.</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">Thank you!</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><b style="font-weight:normal"><br></b></p><p dir="ltr" style="line-height:1.656;background-color:rgb(255,255,255);margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial,sans-serif;color:rgb(31,31,31);background-color:rgb(255,255,255);font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap">~ Jonathan</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><br><br><br></p></span></div>