javajvmheap-memory

What is the difference between xmx and MaxRAM JVM parameters?


MaxRAM:

based on the amount of memory on the machine. The proportion of memory to use for the heap is controlled by the command-line options InitialRAMFraction and MaxRAMFraction [...] The value of MaxRAM is platform-dependent.

Xmx:

-Xmxn Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts.

As I understand both define heap size. No? What is recommended to use: Xmx or MaxRAM? If I use both which one ovverides another?


Solution

  • -Xmx specifies the precise upper limit for the heap. It is the preferred way to set the heap size.

    -XX:MaxRAM does not define the heap size directly. Instead this parameter overrides the actual amount of physical RAM when calculating the heap limits basing on ergonomics.

    If -Xmx is set, MaxRAM is never used. Otherwise the maximum heap size is estimated1 as

    MaxHeapSize = MaxRAM * MaxRAMPercentage / 100% (default MaxRAMPercentage=25)
    

    1 The actual algorithm is a bit more complicated and depends on other parameters.