DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • All You Need To Know About Garbage Collection in Java
  • Heap Memory In Java Applications Performance Testing
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • JVM Memory Architecture and GC Algorithm Basics

Trending

  • Rust, WASM, and Edge: Next-Level Performance
  • Event Driven Architecture (EDA) - Optimizer or Complicator
  • Build a Simple REST API Using Python Flask and SQLite (With Tests)
  • Monolith: The Good, The Bad and The Ugly
  1. DZone
  2. Coding
  3. Java
  4. Difference Between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage

Difference Between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage

This article attempts to clarify the difference between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage JVM arguments.

By 
Ram Lakshmanan user avatar
Ram Lakshmanan
DZone Core CORE ·
Nov. 17, 20 · Opinion
Likes (5)
Comment
Save
Tweet
Share
25.4K Views

Join the DZone community and get the full member experience.

Join For Free

This article attempts to clarify the difference between InitialRAMPercentage, MinRAMPercentage, MaxRAMPercentage JVM arguments. These arguments have been introduced since Java 8 update 191. They are used to configure your Java application’s heap size when you are running it in the Physical server or in the container. In this article, let’s review their differences.

InitialRAMPercentage

‘-XX:InitialRAMPercentage’ is used to compute the initial heap size of your java application. 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).

‘-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.

MaxRAMPercentage, MinRAMPercentage

Both ‘-XX:MaxRAMPercentage’ and ‘-XX:MinRAMPercentage’ are used to determine the maximum Java heap size. JDK development team could have given a better name than ‘-XX:MinRAMPercentage’. This name makes us think, ‘-XX:MinRAMPercentage’ argument is used to configure minimum heap size. But it’s not true. 

‘-XX:MinRAMPercentage’ JVM argument will be used to compute Java heap size only if your overall available memory’s size in the physical server (or in the container) is less than 250MB (approximately). Say suppose you are configuring -XX:MinRAMPercentage=50 and overall physical memory (or container) memory is 100MB, then your java application’s max heap size will be set to 50MB (i.e., 50% of 100MB).

‘-XX:MaxRAMPercentage’ JVM argument will be used to compute Java heap size only if your overall available memory’s size in the physical server (or in container) is more than 250MB(approximately). Say suppose you are configuring -XX:MaxRAMPercentage=75 and overall physical server (or container) memory is 1GB, then your java application’s max heap size will be set to 750MB (i.e., 75% of 1GB).

To prove this theory, consider the below two examples.

Example 1: Small Memory Size

Let’s configure the container’s memory size to be 100MB, MaxRAMPercentage to be 25, and MinRAMPercentage to be 50. Since the container’s memory size is 100MB (which is less than the 250MB limit), JVM uses ‘MinRAMPercentage’ to derive the heap’s size. You can notice JVM reporting max heap size for this configuration to be 48.38M (i.e., 50% of the 100MB). You can see ‘MaxRAMPercentage’ JVM argument to be ignored.

# docker run -m 100MB openjdk:10 java -XX:MaxRAMPercentage=25

-XX:MinRAMPercentage=50 -XshowSettings:vm -version VM settings:

Max. Heap Size (Estimated): 48.38M     Using VM: OpenJDK 64-Bit Server VM

Example 2: Large Memory Size

Let’s configure the container’s memory size to be 1GB, MaxRAMPercentage to be 25, and MinRAMPercentage to be 50. Since the container’s memory size is 1GB (which is greater than the 250MB limit), JVM uses ‘MaxRAMPercentage’ to derive the heap’s size. You can notice JVM reporting max heap size for this configuration to be 247.50M (i.e. 25% of the 1GB). You can see the ‘MinRAMPercentage’ JVM argument to be ignored.

# docker run -m 1GB openjdk:10 java -XX:MaxRAMPercentage=25

-XX:MinRAMPercentage=50 -XshowSettings:vm -version VM settings:

Max. Heap Size (Estimated): 247.50M     Using VM: OpenJDK 64-Bit Server VM

‘-XX:MaxRAMPercentage’ and ‘-XX:MinRAMPercentage’ will be used to derive maximum heap size only if ‘-Xmx’ JVM argument isn’t passed. If the ‘-Xmx’ JVM argument is passed, the JVM will ignore these two arguments.

In the below example you can see ‘-XX:MaxRAMPercentage=25’, ‘-XX:MinRAMPercentage=25’ and ‘-Xmx512m’ are configured. You can see the max heap size is set to 512M, it’s indicating value specified in the ‘-Xmx’ is taking effect. 

# docker run -m 1GB openjdk:10 java -XX:MaxRAMPercentage=25

-XX:MinRAMPercentage=25 -Xmx512m -XshowSettings:vm -version VM settings:

Max. Heap Size: 512.00M     Using VM: OpenJDK 64-Bit Server VM

Best Practice: When you are starting to use ‘’, ‘’, ‘’ JVM arguments it has potential to impact your garbage collection, performance characteristics of your application. You can use free tools like GCeasy, IBM GC & Memory Visualizer, HP jmeter to study this behavior.

Conclusion

Thus, in a nutshell:

  1. To set the initial heap size for your application use ‘-XX:InitialRAMPercentage’
  2. ‘-XX:InitialRAMPercentage’ will not take effect to determine the initial heap size if ‘-Xms’ is configured.
  3. Both ‘-XX:MinRAMPercentage’ and ‘-XX:MaxRAMPercentage’ are used to set the application’s max heap size.
  4. ‘-XX:MinRAMPercentage’ and ‘-XX:MaxRAMPercentage’ will not take effect to determine max heap size if ‘-Xmx’ is configured.
  5. If your overall physical server (or container) memory size is more than 250MB, then you don’t have to configure ‘-XX:MinRAMPercentage’, it’s sufficient if you just configure ‘-XX:MaxRAMPercentage’. Most enterprise grade Java applications will be running with more than 250MB (unless you are building IoT or network device applications in Java).
garbage collection Java (programming language) Java virtual machine Memory (storage engine) application Container

Opinions expressed by DZone contributors are their own.

Related

  • All You Need To Know About Garbage Collection in Java
  • Heap Memory In Java Applications Performance Testing
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • JVM Memory Architecture and GC Algorithm Basics

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!