Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-Xms: Initial heap size or minimum heap size?

-Xms is to specify initial heap size or minimum heap size? I see differing viewpoints. Some like second answer here, say that it is for initial heap and some others say that it is minimum heap size.

Or is it that the minimum size itself is the initial size?

like image 741
Suraj Chandran Avatar asked Dec 23 '09 08:12

Suraj Chandran


People also ask

What is initial heap size and maximum heap size?

Initial heap size is 1/64th of the computer's physical memory or reasonable minimum based on platform (whichever is larger) by default. The initial heap size can be overridden using -Xms. Maximum heap size is 1/4th of the computer's physical memory or 1 GB (whichever is smaller) by default.

Is it good to set the max and min JVM heap size the same?

Larger heap size will cause less frequent, but bigger and more disruptive garbage collection if using the traditional oracle garbage collection algorithm. So bigger is not better. The exact behavior will depend on the JVM implementation.

What is initial heap size in JVM?

By default, the JVM heap size is 1GB, which is usually enough to accommodate the data used by Task Engine. However, larger heap size may be required under some circumstances, for example, when the average size of the parameters in a task is very large.

How do I choose heap size?

It is recommended to increase the Java heap space only up to one-half of the total RAM available on the server. Increasing the Java heap space beyond that value can cause performance problems. For example, if your server has 16 GB of RAM available, then the maximum heap space you should use is 8 GB.


2 Answers

The initial heap size is the minimum heap size. It won't get smaller than the initial heap size.

From Tuning Garbage Collection with the 5.0 Java[tm] Virtual Machine:

By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range. This target range is set as a percentage by the parameters -XX:MinHeapFreeRatio= and -XX:MaxHeapFreeRatio=, and the total size is bounded below by -Xms and above by -Xmx .

like image 194
Thomas Jung Avatar answered Sep 24 '22 23:09

Thomas Jung


From running java -X:

-Xms<size>        set initial Java heap size -Xmx<size>        set maximum Java heap size -Xss<size>        set java thread stack size 

Note that -X options are not guaranteed to exist on all VMs or behave the same on all VMs. For example -Xms could format your hard drive depending on the VM (it would not - but strictly speaking it could :-) (typing java by itself gives the help with this line: "-X print help on non-standard options").

like image 31
TofuBeer Avatar answered Sep 23 '22 23:09

TofuBeer