-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 MaxHeapSize is estimated as

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

    MAX(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
🌐
Baeldung
baeldung.com › home › java › jvm › jvm parameters initialrampercentage, minrampercentage, and maxrampercentage
JVM Parameters InitialRAMPercentage, MinRAMPercentage, and MaxRAMPercentage | Baeldung
June 5, 2024 - For instance, if we set-XX:InitialRAMPercentage=50.0 for a physical server of 1 GB full memory, then the initial heap size will be around 500 MB (50% of 1 GB). To start with, let’s check the default value of the IntialRAMPercentage in the JVM: $ docker run openjdk:8 java -XX:+PrintFlagsFinal -version | grep -E "InitialRAMPercentage" double InitialRAMPercentage = 1.562500 {product} openjdk version "1.8.0_292" OpenJDK Runtime Environment (build 1.8.0_292-b10)
🌐
IBM
ibm.com › docs › SSYKE2_8.0.0 › openj9 › xxinitialrampercentage › index.html
-XX:InitialRAMPercentage / -XX:MaxRAMPercentage - IBM Documentation
January 22, 2026 - These Oracle HotSpot options can be used to specify the initial and maximum size of the Java heap as a percentage of the total memory available to the VM. The options are recognized by Eclipse OpenJ9™ and provided for compatibility.
🌐
DZone
dzone.com › coding › java › difference between initialrampercentage, minrampercentage, maxrampercentage
Difference Between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage
November 17, 2020 - ‘-XX:InitialRAMPercentage’ will be used to derive initial heap size only if ‘-Xms’ JVM argument isn’t passed. If the ‘-Xms’ JVM argument is passed, the ‘-XX:InitialRAMPercentage’ will be ignored by the JVM. Both ‘-XX:MaxRAMPercentage’ and ‘-XX:MinRAMPercentage’ are used to determine the maximum Java heap size.
🌐
CloudBees
docs.cloudbees.com › knowledge base › java heap settings best practice
Java Heap settings Best Practice
Since JDK 8u191 XX:+UseContainerSupport is activated by default, the JVM is "container-aware" and can determine its heap size based on the container boundaries. It also introduces -XX:MaxRAMPercentage / -XX:InitialRAMPercentage which takes a value between 0 and 100 (Note: values should be double ...
🌐
ycrash Answers
answers.ycrash.io › question › what-is-memory-tuning--xxinitialrampercentage
What is Memory tuning: -XX:InitialRAMPercentage? - yCrash Answers
October 28, 2022 - -XX:InitialRAMPercentage=x, where x is the desired percentage of heap memory between 0 and 100 of type double. ... This Oracle HotSpot option can be used to specify the initial size of the Java heap as a percentage of the total memory available ...
🌐
Eclipse Foundation
eclipse.dev › openj9 › docs › xxinitialrampercentage
-XX:InitialRAMPercentage / -XX:MaxRAMPercentage -
These Oracle HotSpot options can be used to specify the initial and maximum size of the Java heap as a percentage of the total memory available to the VM. The options are recognized by Eclipse OpenJ9™ and provided for compatibility. Where N is a value between 0 and 100, which can be of type ...
🌐
Bala's Blog
dkbalachandar.wordpress.com › 2022 › 04 › 29 › how-to-set-initial-heap-size-and-max-heap-size-with-initialrampercentage-and-maxrampercentage-and-minrampercentage
How to set Initial heap size and Max Heap size with InitialRAMPercentage and MaxRAMPercentage and MinRAMPercentage | Bala's Blog
April 30, 2022 - Let’s say a java container is running and its memory size is 1GB, then if you want to set the initial heap size to ~250 MB and the max heap size to ~500 MB and also you don’t want to calculate these values by yourself and let the JVM handle these, you should set the XX:InitialRAMPercentage as 25.00 and XX:MaxRAMPercentage as 50.00
🌐
Red Hat
access.redhat.com › solutions › 4886081
Usage of Java flags InitialRAMPercentage and MaxRAMPercentage - Red Hat Customer Portal
June 14, 2024 - How to use InitialRAMPercentage and Min|MaxRAMPercentage? Are these JVM parameters applicable only for container environment or can we use in local machines: InitialRAMPercentage Min|MaxRAMPercentage?
Find elsewhere
🌐
IBM
ibm.com › docs › en › sdk-java-technology › 8
-XX:InitialRAMPercentage / -XX:MaxRAMPercentage
Build, govern, and manage your data for generative AI solutions · Use pre-integrated automation technologies to design, build, and run automation applications and services on the cloud
🌐
yCrash
blog.ycrash.io › home › best practices: java memory arguments for containers
Best practices: Java memory arguments for Containers - yCrash
August 31, 2025 - If you are running *only your Java application* within the container, then set initial heap size (i.e., using either one of ‘-XX:InitialRAMFraction’, ‘-XX:InitialRAMPercentage’, -Xms) to the same size as max heap size. Setting initial heap size and max heap has certain advantages.
🌐
Medium
medium.com › @marketing_864 › best-practices-java-memory-arguments-for-containers-1d704a65f7db
Best practices: Java memory arguments for Containers | by Ram Lakshmanan | Medium
December 17, 2020 - 2. If you are running *only your Java application* within the container, then set initial heap size (i.e., using either one of ‘-XX:InitialRAMFraction’, ‘-XX:InitialRAMPercentage’, -Xms) to the same size as max heap size. Setting initial heap size and max heap has certain advantages.
Top answer
1 of 3
16

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

2 of 3
0

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.

🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8278492
Confusion about parameter -XX:MinRAMPercentage
E.g. when the VM is run with -XX:MinRAMPercentage=X -XX:InitialRAMPercentage -XX:MaxRAMPercentage=X -XX:+AlwaysPreTouch -Xlog:pagesize shows [0.030s][info][pagesize] Heap: min=8M max=3214M base=0x0000000737200000 page_size=4K size=3214M (note the "min=" value!)
🌐
Merikan Blog
merikan.com › 2019 › 04 › jvm-in-a-container
JVM in a Container | Merikan Blog
April 3, 2019 - ➜ docker run -m 1GB openjdk:8u191-alpine java \ -XX:+PrintFlagsFinal -version \ | grep -E "UseContainerSupport | InitialRAMPercentage | MaxRAMPercentage | MinRAMPercentage" double InitialRAMPercentage = 1.562500 {product} double MaxRAMPercentage = 25.000000 {product} double MinRAMPercentage = 50.000000 {product} bool UseContainerSupport = true {product}
🌐
yCrash
blog.ycrash.io › home › benefits of setting initial and maximum memory size to the same value
Optimize Memory: Match Initial & Max Sizes for Java Performance
May 30, 2025 - For the applications that run on JVM (Java Virtual Machine), initial and maximum memory size is specified through ‘-Xms’ and ‘-Xmx’ arguments. If Java applications are running on containers, it’s specified through ‘-XX: InitialRAMPercentage’ and ‘-XX: MaxRAMPercentage’ arguments.
🌐
GC easy
blog.gceasy.io › home › difference between initialrampercentage, minrampercentage, maxrampercentage
Difference between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage
November 8, 2024 - ‘-XX:InitialRAMPercentage’ will be used to derive initial heap size only if ‘-Xms’ JVM argument isn’t passed. If the ‘-Xms’ JVM argument is passed, the ‘-XX:InitialRAMPercentage’ will be ignored by the JVM. Both ‘-XX:MaxRAMPercentage’ and ‘-XX:MinRAMPercentage’ are used to determine the maximum Java heap size.