Java 8 和 11 ParallelGC 是否遵循这些 JVM 设置 MinHeapFreeRatio 和 MaxHeapFreeRatio?
我们有一个 Java 应用程序,其中应用了 MinHeapFreeRatio=20 和 MaxHeapFreeRatio=40,并使用 ParallelGC。然而,有些文章说,这些 JVM 设置(最小和最大空闲堆比率)不适用于 ParallelGC。然而,使用 JDK8 和 ParallelGC,我们注意到空闲堆比率在我们设置的限制内。然而,在 JDK 11 和 ParallelGC 中,我们注意到空闲堆比率并未得到满足。 鼓励 JVM 进行 GC 而不是增加堆?< /a>
对于无论 JDK 版本如何的 ParallelGC 是否遵循这些设置,我们都存在一些困惑?这些设置是否适用于 G1GC 和 CMS GC? 您能否分享您的专家对此问题的看法?
We have a Java application where we have applied the MinHeapFreeRatio=20 and MaxHeapFreeRatio=40, and using ParallelGC. However some of articles says that, these JVM settings (Min and Max free heap ratio) is not applicable for ParallelGC. However, with JDK8 and with ParallelGC we noticed that free heap ratio were within the limit we had set. However with JDK 11 and with ParallelGC, we are noticing that free heap ratio is not getting honored.
Encourage the JVM to GC rather than grow the heap?
We have some confusions around whether ParallelGC with irrespective of JDK version honors these settings or not? are these settings applicable for G1GC and CMS GC?
Can you please share your experts views around this query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于不同JDK版本的ParallelGC
我确信Jdk11也支持ParallelGC,并且还支持Min/MaxHeapFreeRatio参数。
代码。 (源代码链接)
因此,我可以确认
Min/MaxHeapFreeRatio
参数可以正常使用通过不同JDK版本的ParallelGC。关于参数设置在JDK11中不生效
这个参数在某些情况下确实会失效,但在解释之前,我想先解释一下
Min/MaxHeapFreeRatio
到底做了什么。该参数直接作用于Old Gen,用于控制老年代中剩余空间在整个老年代中的比例,而不是整个堆中剩余空间在整个堆中的比例!我尝试用图来详细解释。下图是ParallelGC堆内存的结构图:
通过下面的公式,我们可以计算出old gen中剩余空间占old gen总空间的比例。
HeapFreeRatio = (Free Size) / (Old Gen Size) * 100
ParallelGC 通过在 GC 后动态调整 Old Gen 的大小,使 HeapFreeRatio 满足
Min/MaxHeapFreeRatio
要求。Old Gen Size = Free Size + Use Size
特殊情况
当Use Size太大时,Min/MaxHeapFreeRatio确实会失败。
随着Use Size变大,ParallelGC必须通过扩大Old Gen来继续满足Min/MaxHeapFreeRatio的要求。又因为
当前堆大小 = Young Gen + Old Gen
,所以扩大Old Gen的大小会使得Current Heap Size扩大,但是Heap Size是有最大上限的。于是就会出现下图(Current == Max):
此时,ParallelGC 已经无法通过扩展 Old Gen 来满足 Min/MaxHeapFreeRatio 的要求,但如果 Use Size 继续增长时,会出现以下情况:
在上述情况下,Use Size 太大而 Free Size 变小,因此 (Free Size / Old Gen) * 100 <最小堆空闲比率。此时,就会出现与你的预期不符的现象。
总之,
当当前堆大小
时,Min/MaxHeapFreeRatio 是一个软限制。 Max Heap Size
,ParallelGC可以保证HeapFreeRatio满足要求。但当
Current Heap Size == Max Heap Size
时,ParallelGC无法保证HeapFreeRatio满足要求。如果您对此仍有疑问,希望与您进一步沟通。About ParallelGC for different JDK versions
I am sure that Jdk11 also supports ParallelGC, and also supports
Min/MaxHeapFreeRatio
parameters.code. (source code link)
Therefore, I can confirm that the
Min/MaxHeapFreeRatio
parameters can be used normally by ParallelGC of different JDK versions.About parameter settings do not take effect in JDK11
This parameter does fail under certain circumstances, but before explaining that, I would like to explain what
Min/MaxHeapFreeRatio
really does. This parameter acts directly on Old Gen, and is used to control the proportion of the remaining space in the old generation in the entire old generation, rather than the proportion of the remaining space in the entire heap in the entire heap!I tried to explain in detail with a diagram. The following diagram is a structure diagram of ParallelGC heap memory:
Through the following formula, we can calculate the proportion of the remaining space in the old generation to the total old generation space.
HeapFreeRatio = (Free Size) / (Old Gen Size) * 100
ParallelGC makes HeapFreeRatio meet the
Min/MaxHeapFreeRatio
requirement by dynamically adjusting the size of Old Gen after GC.Old Gen Size = Free Size + Use Size
special case
When the Use Size is too large, Min/MaxHeapFreeRatio will indeed fail.
As the Use Size becomes larger, ParallelGC has to continue to meet the requirements of Min/MaxHeapFreeRatio by expanding the Old Gen. And because
Current Heap Size = Young Gen + Old Gen
, so expanding the size of the Old Gen will make the Current Heap Size expand, but the Heap Size has a maximum upper limit. So the following picture will appear (Current == Max):
At this time, ParallelGC can no longer meet the requirements of Min/MaxHeapFreeRatio by expanding Old Gen, but if the Use Size continues to grow, the following situation will occur:
In the above case, the Use Size is too large and the Free Size becomes smaller, so that (Free Size / Old Gen) * 100 < MinHeapFreeRatio. At this point, there will be a phenomenon that does not match your expectations.
in conclusion
Min/MaxHeapFreeRatio is a soft limit, when
Current Heap Size < Max Heap Size
, ParallelGC can guarantee HeapFreeRatiofulfil requirements. But when
Current Heap Size == Max Heap Size
, ParallelGC cannot guarantee that HeapFreeRatio meets the requirements. If you still have doubts about this, I hope to communicate with you further.