Usually I set -Xms512m
and -Xmx1g
so that when JVM starts it allocates 512MB and gradually increases heap to 1GB as necessary. But I see these values s
AFAIK One more reason, is that expansion of heap is a stop-the-world
event; setting those to the same value will prevent that.
From Oracle Java SE 8 docs:
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/sizing.html 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=<minimum>
and-XX:MaxHeapFreeRatio=<maximum>
, and the total size is bounded below by -Xms<min>
and above by-Xmx<max>
. Setting-Xms
and-Xmx
to the same value increases predictability by removing the most important sizing decision from the virtual machine. However, the virtual machine is then unable to compensate if you make a poor choice.
if the value of -Xms and -Xmx is same JVM will not have to adjust the heap size and that means less work by JVM and more time to your application. but if the chosen value is a poor choice for -Xms then some of the memory allocated will never be used because the heap will never shrink and if it is a poor choice for -Xmx you will get OutOfMemoryError.
There are some advantages.
In general, I would make the Xms a value I am confident it will use, and the double this for head room for future use cases or situations we haven't tested for. i.e. a size we don't expect but it might use.
In short, the maximum is the point you would rather the program fail than use any more.
Well there are couple of things.
It is very nicely answered here - https://developer.jboss.org/thread/149559?_sscc=t