Java 澄清新JVM内存参数InitialRAMPercentage和MinRAMPercentage的含义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54292282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:00:51  来源:igfitidea点击:

Clarification of meaning new JVM memory parameters InitialRAMPercentage and MinRAMPercentage

javadockerjvm

提问by Rubin Simons

Reference: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8186315

参考:https: //bugs.java.com/bugdatabase/view_bug.do?bug_id=8186315

I'm really struggling to find out what MinRAMPercentage does, especially compared to InitialRAMPercentage.

我真的很难找出 MinRAMPercentage 的作用,尤其是与 InitialRAMPercentage 相比。

I assumed that InitialRAMPercentage sets the amount of heap at startup, that MinRAMPercentage and MaxRAMPercentage set the bottom and top limit of heap that the JVM is allowed to shrink/grow to.

我假设 InitialRAMPercentage 在启动时设置堆的数量,MinRAMPercentage 和 MaxRAMPercentage 设置允许 JVM 收缩/增长到的堆的底部和顶部限制。

Apparently that is not the case. When I start a JVM (with UseContainerSupport, having these new memory setting parameters) like so:

显然情况并非如此。当我启动 JVM(使用 UseContainerSupport,具有这些新的内存设置参数)时,如下所示:

java -XX:+UseContainerSupport -XX:InitialRAMPercentage=40.0 -XX:MinRAMPercentage=20.0 -XX:MaxRAMPercentage=80.0 -XX:+PrintFlagsFinal -version | grep Heap

InitialHeap and MaxHeap get set, there is no "Minimum Heap Size" value that I can find; Consequently, that MinRAMPercentage never seems to get used.

InitialHeap 和 MaxHeap 已设置,我找不到“最小堆大小”值;因此,MinRAMPercentage 似乎从未被使用过。

Super confused, and apparently, I'm not the only one; the OpenJ9 dudes seem to also not fully parse the intent of these options, as I've gathered hereand here. They seem to have opted to simply not implement MinRAMPercentage afaics.

超级困惑,显然,我不是唯一一个;OpenJ9 的家伙似乎也没有完全解析这些选项的意图,正如我在这里这里收集的。他们似乎选择不实施 MinRAMPercentage afaics。

So: What is the real intended usage and effect of setting MinRAMPercentage?

那么:设置 MinRAMPercentage 的真正用途和效果是什么?

采纳答案by apangin

-XX:InitialRAMPercentageis used to calculate initial heap sizewhen InitialHeapSize/ -Xmsis not set.

-XX:InitialRAMPercentage用于在未设置/时计算初始堆大小InitialHeapSize-Xms

It sounds counterintuitive, but both -XX:MaxRAMPercentageand -XX:MinRAMPercentageare used to calculate maximum heap sizewhen MaxHeapSize/ -Xmxis not set:

这听起来违反直觉的,但两者-XX:MaxRAMPercentage-XX:MinRAMPercentage用来计算最大堆尺寸MaxHeapSize/-Xmx未设置:

  • For systems with small physical memory MaxHeapSizeis estimated as

    phys_mem * MinRAMPercentage / 100  (if this value is less than 96M)
    
  • Otherwise (non-small physical memory) MaxHeapSizeis estimated as

    MAX(phys_mem * MaxRAMPercentage / 100, 96M)
    
  • 对于物理内存较小的系统,MaxHeapSize估计为

    phys_mem * MinRAMPercentage / 100  (if this value is less than 96M)
    
  • 否则(非小物理内存)MaxHeapSize估计为

    MAX(phys_mem * MaxRAMPercentage / 100, 96M)
    

The exact formulais a bit more complicated as it also takes other factors into account.

确切的公式有点复杂,因为它还考虑了其​​他因素。

Note: the algorithm for calculating initial and maximum heap size depends on the particular JVM version. The preferred way to control the heap size is to set Xmxand Xmsexplicitly.

注意:计算初始和最大堆大小的算法取决于特定的 JVM 版本。控制堆大小的首选方法是设置XmxXms显式。

See also this question.

另请参阅此问题