If I omit the -Xmxn
option from the Java command line then a default value will be used. According to Java documentation
\"the default v
Finally!
As of Java 8u191 you now have the options:
-XX:InitialRAMPercentage
-XX:MaxRAMPercentage
-XX:MinRAMPercentage
that can be used to size the heap as a percentage of the usable physical RAM. (which is same as the RAM installed less what the kernel uses).
See Release Notes for Java8 u191 for more information. Note that the options are mentioned under a Docker heading but in fact they apply whether you are in Docker environment or in a traditional environment.
The default value for MaxRAMPercentage
is 25%. This is extremely conservative.
My own rule: If your host is more or less dedicated to running the given java application, then you can without problems increase dramatically. If you are on Linux, only running standard daemons and have installed RAM from somewhere around 1 Gb and up then I wouldn't hesitate to use 75% for the JVM's heap. Again, remember that this is 75% of the RAM available, not the RAM installed. What is left is the other user land processes that may be running on the host and the other types of memory that the JVM needs (eg for stack). All together, this will typically fit nicely in the 25% that is left. Obviously, with even more installed RAM the 75% is a safer and safer bet. (I wish the JDK folks had implemented an option where you could specify a ladder)
Setting the MaxRAMPercentage
option look like this:
java -XX:MaxRAMPercentage=75.0 ....
Note that these percentage values are of 'double' type and therefore you must specify them with a decimal dot. You get a somewhat odd error if you use "75" instead of "75.0".