Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why default java max heap is 1/4th of Physical memory?

I have read couples of articles on java heap space and found out that the default max heap for JVM is 1/4th of the actual physical space. But none of the article had reason for this ? Whats the reason of having it as 1/4th of actual memory?

https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gc-ergonomics.html

like image 858
Raj Thakur Avatar asked Sep 13 '25 05:09

Raj Thakur


1 Answers

This dates back to JDK 5, which introduced JVM ergonomics. Prior to this, the JVM would set very small defaults for the heap space. JDK 1.1 had a default of 16Mb for both Xms and Xmx, JDK 1.2 changed this to Xms of 1Mb and Xmx of 64Mb by default. In JDK 1.3, Xms default increased to 2Mb.

Since Java was proving more popular on servers and memory capacities were increasing significantly, Sun introduced the concept of a server-class machine in JDK 5. This is one that has 2 or more physical processors and 2 or more Gb of memory (if I remember rightly, in JDK 5, the machine also had to not be running Windows to count as a server).

On server-class machines by default, the following parameters were set

  • Throughput garbage collector (i.e. the parallel collector)
  • initial heap size of 1/64 of physical memory up to 1Gbyte
  • maximum heap size of 1/4 of physical memory up to 1Gbyte
  • Server runtime compiler

Ergonomics provided two command-line flags that allowed a user to set a performance goal for the JVM; the idea being that the JVM would then figure out internally how to achieve this goal by modifying its parameters. The ultimate goal was to eliminate a lot of the -XX flags that were being used to tune JVM performance manually.

The parameters are:

-XX:MaxGCPauseMillis=nnn which sets the maximum pause time you want for GC in milliseconds.

-XX:GCTimeRatio= which sets the ratio of garbage collection time to application time being 1 / (1 + nnn). This was referred to as the throughput goal.

You can specify either of these goals or both. If the JVM manages to achieve both of these goals it then attempts to reduce the memory being used (the footprint goal).

There's more detail here:

https://www.oracle.com/technetwork/java/ergo5-140223.html

like image 109
Speakjava Avatar answered Sep 15 '25 18:09

Speakjava