How is the default max Java heap size determined?

前端 未结 10 1705
旧巷少年郎
旧巷少年郎 2020-11-22 03:50

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

相关标签:
10条回答
  • 2020-11-22 04:29

    On Windows, you can use the following command to find out the defaults on the system where your applications runs.

    java -XX:+PrintFlagsFinal -version | findstr HeapSize

    Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

    On a Unix/Linux system, you can do

    java -XX:+PrintFlagsFinal -version | grep HeapSize

    I believe the resulting output is in bytes.

    0 讨论(0)
  • 2020-11-22 04:30

    This is changed in Java 6 update 18.

    Assuming that we have more than 1 GB of physical memory (quite common these days), it's always 1/4th of your physical memory for the server vm.

    0 讨论(0)
  • 2020-11-22 04:30

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

    0 讨论(0)
  • 2020-11-22 04:33

    For the IBM JVM, the command is the following:

    java -verbose:sizes -version
    

    For more information about the IBM SDK for Java 8: http://www-01.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.lnx.80.doc/diag/appendixes/defaults.html?lang=en

    0 讨论(0)
提交回复
热议问题