-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.
🌐
Medium
medium.com › @marketing_864 › difference-between-initialrampercentage-minrampercentage-maxrampercentage-8c9c0706ec95
Difference between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage | by Ram Lakshmanan | Medium
November 12, 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
Add -XX:InitialRAMPercentage=50.0 -XX:MaxRAMPercentage=50.0 Java arguments as per How to add Java arguments to Jenkins.
🌐
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.
🌐
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 ...
Find elsewhere
🌐
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.
🌐
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 ...
🌐
Azul
docs.azul.com › prime › Heap-Size
Recommended Heap Size
-XX:InitialRAMPercentage=<value> This is an alternative to -Xms and defines the initial heap size as percentage of the RAM of the machine, container or cgroup. With JDK 8, a decimal number is required as value, like 5.0. On JDK 11 and later integer numbers are also accepted.
🌐
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?
Top answer
1 of 1
3

It is not a hard and fast rule, and whether you should do this depends a lot on your application.

Setting them the same will mean that your application will always use the same heap size, which means the memory use will (ignoring fluctuations in native memory usage) be stable. This means that you can generally configure your pod quotas (i.e. limits.memory and requests.memory) easily, and thus have stable costs, and this also reduces the chance of your application getting killed if the node needs to make resources available to another pod (which can happen if you exceed your (memory) requests, even if you're still within your limits)

On the other hand, if your application has a varying workload and thus varying memory needs, setting them differently may reduce costs if you use a garbage collector that returns memory to the OS. For example, at a previous job, we were able to save quite some money for one application by configuring the requests.memory and -XX:InitialRAMPercentage at a certain minimum need, while setting limits.memory and -XX:MaxRAMPercentage a lot higher for bursty processing needs. The downside of this was that this increased the chance of our pod(s) being chosen to be rescheduled to a different node if memory pressure increased, but in our situation that was an acceptable trade-off.

To be clear, whether this actually saves money also depends on your actual Kubernetes cluster configuration and whether or not nodes are spun up and down depending on total load, however in our case, we saved costs on our team budget because we were virtually billed for the usage of our applications, and given the size of our company and the dynamic scaling up and down of the number of pods and nodes, it probably also saved money on the company level.

In addition, setting -XX:InitialRAMPercentage and -XX:MaxRAMPercentage may take away some flexibility in the heuristic configuration of the garbage collector, which may mean you have to do more explicit tuning yourself to get the best performance.

Also, -XX:InitialRAMPercentage specifies the percentage of memory that the heap will be when you start your application, so it cannot "be scaled up automatically during the application lifetime". Its default is 1.562500%, which is quite low. If your application needs a lot of memory, then setting it at its actual needs avoids a number of full GC cycles during the startup, and thus setting this correctly reduces the start up time of your application.

🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8278492
Confusion about parameter -XX:MinRAMPercentage
The parameter -XX:MinRAMPercentage is used to set the maximum heap size for small heaps (<200M). This is a bit confusing as it does not correspond to what Initial/MaxRAMPercentage does. E.g. when the VM is run with -XX:MinRAMPercentage=X -XX:InitialRAMPercentage -XX:MaxRAMPercentage=X ...
🌐
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.
🌐
CodingTechRoom
codingtechroom.com › question › understanding-jvm-memory-parameters-initialrampercentage-minrampercentage
Understanding JVM Memory Parameters: InitialRAMPercentage vs MinRAMPercentage - CodingTechRoom
In JVM, the memory management parameters InitialRAMPercentage, MinRAMPercentage, and MaxRAMPercentage are crucial for optimizing heap size. Here's an explanation of how each behaves and interacts. ... java -XX:+UseContainerSupport -XX:InitialRAMPercentage=40.0 -XX:MinRAMPercentage=20.0 -XX:MaxRAMPercentage=80.0 -XX:+PrintFlagsFinal -version | grep Heap # Expected Output: InitialHeapSize: 17179869184 # (40% of total RAM) MaxHeapSize: 85899345920 # (80% of total RAM)
🌐
Jenkins
jenkins.io › blog › 2026 › 02 › 06 › tuning-java-settings-for-higher-performance
Tuning Jenkins Java Settings For Responsiveness and Stability with Large Instances
February 6, 2026 - JAVA_OPTS=" -XX:+UseG1GC -XX:MaxRAMPercentage=60.0 -XX:InitialRAMPercentage=20.0 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/var/log/jenkins/gc.log "
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-8348278
Trim InitialRAMPercentage to improve startup in default modes
January 22, 2025 - Affects Version/s: 21, 25 · Component/s: hotspot · Labels: amazon-interest · release-note=no · Subcomponent: gc · Resolved In Build: b17 · When user does not supply -Xms, ergonomics guesses the initial heap size, based on InitialRAMPercentage (IRAMP), currently set at 1/64 of physical RAM.