-XX:InitialRAMPercentage is used to calculate initial heap size when InitialHeapSize / -Xms is not set.
It sounds counterintuitive, but both -XX:MaxRAMPercentage and -XX:MinRAMPercentage are used to calculate maximum heap size when MaxHeapSize / -Xmx is not set:
For systems with small physical memory
MaxHeapSizeis estimated asphys_mem * MinRAMPercentage / 100 (if this value is less than 96M)Otherwise (non-small physical memory)
MaxHeapSizeis estimated asMAX(phys_mem * MaxRAMPercentage / 100, 96M)
The exact formula is 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 Xmx and Xms explicitly.
See also this question.
Answer from apangin on Stack Overflow-XX:InitialRAMPercentage is used to calculate initial heap size when InitialHeapSize / -Xms is not set.
It sounds counterintuitive, but both -XX:MaxRAMPercentage and -XX:MinRAMPercentage are used to calculate maximum heap size when MaxHeapSize / -Xmx is not set:
For systems with small physical memory
MaxHeapSizeis estimated asphys_mem * MinRAMPercentage / 100 (if this value is less than 96M)Otherwise (non-small physical memory)
MaxHeapSizeis estimated asMAX(phys_mem * MaxRAMPercentage / 100, 96M)
The exact formula is 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 Xmx and Xms explicitly.
See also this question.
Depends on your container memory also, So lets suppose you have container memory as 1 GB then in this case -XX:MaxRAMPercentage=80 will be used to determine the max heap ~ 800mb heap memory will be used
And suppose you have container memory less than 250mb then -XX:MinRAMPercentage=20.0 will be used ~ 50mb heap memory will be used
use this article to understand more XX:MinRAMPercentage,XX:MaxRAMPercentage
Videos
A common misconception is that the initial heap size is the minimum heap size. They are actually different and can be configured separately: -XX:InitialHeapSize vs. -XX:MinHeapSize.
In JDK 17, -Xms is a shortcut to set both InitialHeapSize and MinHeapSize to the same value. In contrast, -XX:InitialRAMPercentage affects InitialHeapSize only, and therefore heap may shrink below the initial size.
If you want to prevent heap from resizing at runtime, disable heap shrinking with -XX:MaxHeapFreeRatio=100, or disable adaptive size policy altogether: -XX:-UseAdaptiveSizePolicy.
Note: -XX:MinRAMPercentage does not help. Its name is confusing: the argument configures MaxHeapSize, not MinHeapSize - see JDK-8278492
Probably you need to add this flag as well:
-XX:+UseContainerSupport
From docs you will see that this will work only with Linux x64 platforms:
-XX:-UseContainerSupport The VM now provides automatic container detection support, which allows the VM to determine the amount of memory and number of processors that are available to a Java process running in docker containers. It uses this information to allocate system resources. This support is only available on Linux x64 platforms. If supported, the default for this flag is true, and container support is enabled by default. It can be disabled with -XX:-UseContainerSupport.
This flag can help also:
-XX:+AlwaysPreTouch
-XX:+AlwaysPreTouch Requests the VM to touch every page on the Java heap after requesting it from the operating system and before handing memory out to the application. By default, this option is disabled and all pages are committed as the application uses the heap space.