-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
🌐
IBM
ibm.com › docs › SSYKE2_8.0.0 › openj9 › xxinitialrampercentage › index.html
-XX:InitialRAMPercentage / -XX:MaxRAMPercentage - IBM Documentation
January 22, 2026 - If your application is running in a container and you have specified -XX:+UseContainerSupport, both the default heap size for containers, the -XX:InitialRAMPercentage option, and the -XX:MaxRAMPercentage option are based on the available container memory.
Discussions

[Bug]: JVM InitialRAMPercentage/MaxRAMPercentage options ignored
Bug Description When we specify InitialRAMPercentage/MaxRAMPercentage JVM options and we don't specify any Xms/Xmx option, then strimzi will dynamically compute values for Xms and Xmx and will ... More on github.com
🌐 github.com
1
August 11, 2023
Out of Memory Error in openjdk Container
I built a docker container for my jboss application. Container ran in AWS EKS Fargate. I found that OutOfMemory error occurred after the application ran for several minutes. However, it would be fine if the root user is used rather than the created user. My Dockerfile: FROM openjdk:8u342-o... More on forums.docker.com
🌐 forums.docker.com
7
0
August 19, 2022
java - Why should we set -XX:InitialRAMPercentage and -XX:MaxRAMPercentage to the same value for cloud environment? - Stack Overflow
I've read multiple articles about best practices for setting the {Min/Max/Initial}RAMPercentage values for java applications in the cloud environment. The purpose of Min and Max RAM Percentage flag... More on stackoverflow.com
🌐 stackoverflow.com
Heap size allocation in SUSE using MinRAMPercentage instead of MaxRAMPercentage values although heap size > 250 MB - SUSE Linux Enterprise Desktop - SUSE
I have a problem when defining usage of heap size using MinRAMPercentage and MaxRAMPercentage. The MaxRAMPercentage value is used when heap size is > 250 MB while the MinRAMPercentage is used when heap size < 250 MB. I… More on forums.suse.com
🌐 forums.suse.com
0
May 2, 2022
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › tools › unix › java.html
java
April 21, 2026 - This document contains reference information for the tools that are installed with Java Development Kit (JDK).
🌐
Medium
medium.com › @marketing_864 › difference-between-initialrampercentage-minrampercentage-maxrampercentage-8c9c0706ec95
Difference between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage | by Ram Lakshmanan | Medium
November 12, 2020 - Say suppose you are configuring -XX:InitialRAMPercentage=25 and overall physical memory (or container memory) is 1GB then your java application’s heap size will be ~250MB (i.e., 25% of 1GB).
🌐
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.
🌐
DZone
dzone.com › coding › java › difference between initialrampercentage, minrampercentage, maxrampercentage
Difference Between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage
November 17, 2020 - Say suppose you are configuring -XX:InitialRAMPercentage=25 and overall physical memory (or container memory) is 1GB then your java application’s heap size will be ~250MB (i.e., 25% of 1GB).
🌐
Eclipse Foundation
eclipse.dev › openj9 › docs › xxinitialrampercentage
-XX:InitialRAMPercentage / -XX:MaxRAMPercentage -
If your application is running in a container and you have specified -XX:+UseContainerSupport, both the default heap size for containers, the -XX:InitialRAMPercentage option, and the -XX:MaxRAMPercentage option are based on the available container memory.
Find elsewhere
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8348278
Trim InitialRAMPercentage to improve startup in default modes
January 22, 2025 - When user does not supply -Xms, ergonomics guesses the initial heap size, based on InitialRAMPercentage (IRAMP), currently set at 1/64 of physical RAM. The initial heap size drives the startup times, because GCs need to initialize their internal data structures, e.g.
🌐
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.
🌐
Reddit
reddit.com › r/kotlin › difference between initialrampercentage, minrampercentage, maxrampercentage jvm arguments
r/Kotlin on Reddit: Difference between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage JVM arguments
December 18, 2020 - 88K subscribers in the Kotlin community. Discussion about Kotlin, a statically typed programming language for the JVM, Android, JavaScript, and…
🌐
Server Fault
serverfault.com › questions › 1080535 › java-large-heap-in-container-environment
kubernetes - Java large heap in container environment - Server Fault
October 14, 2021 - FROM jetty:9.4-jdk11 ENV APP_WAR root.war ENV APP_EXPLODED_WAR root/ ENV APP_DESTINATION_PATH $JETTY_BASE/webapps/ ENV APP_DESTINATION_WAR $APP_DESTINATION_PATH$APP_WAR ENV APP_DESTINATION_EXPLODED_WAR $APP_DESTINATION_PATH$APP_EXPLODED_WAR ADD . $APP_DESTINATION_EXPLODED_WAR ENV JAVA_OPTIONS -XX:+PrintFlagsFinal -XX:MaxRAMPercentage=90 -XX:InitialRAMPercentage=90 -XX:-OmitStackTraceInFastThrow -XX:+UseStringDeduplication -Xlog:gc*,stringdedup*=debug:file=/tmp/gc.log:time
🌐
GitHub
gist.github.com › MihaiBojin › 73186a0e63f7dc5dda58d0abb2388022
JVM heap allocation vs. ResourceQuota configuration in Kubernetes · GitHub
for i in {1..4}; do k run java$i --image=adoptopenjdk:11.0.6_10-jdk-hotspot --requests='memory=100Mi' --limits='memory=1000Mi' --restart=Never -- bash -c 'cat << EOF > Heap.java; javac Heap.java; java -XX:MaxRAMPercentage=90 -XX:MinRAMPercentage=90 -XX:InitialRAMPercentage=10 -XX:+UseConcMarkSweepGC -verbose:gc -XX:+PrintFlagsFinal -XshowSettings:vm Heap import java.util.*; public class Heap{ static final Random r = new Random(); public static void main(String[] args) throws Exception { final List<byte[]> storage = new LinkedList<>(); storage.add(new byte[1024*1024*100]); // pre-allocate 50MB
🌐
Docker Community
forums.docker.com › general
Out of Memory Error in openjdk Container - General - Docker Community Forums
August 19, 2022 - I built a docker container for my jboss application. Container ran in AWS EKS Fargate. I found that OutOfMemory error occurred after the application ran for several minutes. However, it would be fine if the root user is …
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.

🌐
Medium
medium.com › javarevisited › smart-memory-management-in-java-java-21-and-legacy-jvm-518d58421b86
🧠 Smart Memory Management in Java (Java 21+ and Legacy JVM) | by Gopi C K | Javarevisited | Medium
July 31, 2025 - 🧠 Smart Memory Management in Java (Java 21+ and Legacy JVM) When you write Java code, you probably trust the garbage collector to “just handle” memory. And for many apps, that works. But if …
🌐
SUSE
forums.suse.com › suse linux enterprise desktop
Heap size allocation in SUSE using MinRAMPercentage instead of MaxRAMPercentage values although heap size > 250 MB - SUSE Linux Enterprise Desktop - SUSE
May 2, 2022 - I have a problem when defining usage of heap size using MinRAMPercentage and MaxRAMPercentage. The MaxRAMPercentage value is used when heap size is > 250 MB while the MinRAMPercentage is used when heap size < 250 MB. I…
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › developer › java › containers › overview
Containerize your Java Applications - Java on Azure | Microsoft Learn
3 weeks ago - To set a minimum heap size, use -Xms for absolute amounts or -XX:InitialRAMPercentage for percentage amounts.
🌐
Reddit
reddit.com › r/java › how to keep constant heap size with minrampercentage and maxrampercentage options
r/java on Reddit: How to keep constant Heap size with MinRamPercentage and MaxRamPercentage options
September 10, 2021 -

Hi all,

I'm running a JVM application in a containerized environment and I want to maintain a constant heap size. I'd also really like to define that size as a percentage, rather than an absolute number. For example, if the container gets 4G memory, I'd like to be able to specify 75% for the JVM heap, rather than 3G for the JVM heap.

I know that I can do this by setting -Xms and -Xmx to the same absolute value. For example, with -Xms3G -Xmx3G, the memory profile in VisualVM looks like this:

Now I'm struggling to do the same thing with -XX:InitialRamPercentage, -XX:MinRamPercentage, and -XX:MaxRamPercentage. For example, if I set them all to 75 in a 4G container, I get a memory profile where the heap size is actually rapidly changing over time:

I've read through the docs for these params and some tutorials, and it doesn't sound like there's a way to do this with the percentages. Hopefully I'm overlooking something though. Thanks in advance :)