Tuning Java heap size, metaspace size and other such items

This section explains how to tune Java heap size, metaspace size and other such items.

The following areas need to be considered for size tuning in relation to the areas that a Java process uses in the memory space.

  • Java heap

    Space that manages Java objects

  • Metaspace

    Space that manages class information

  • Other spaces

    Stack space, and the C-heap space used by the Java VM and native methods

The following two methods can be used to tune the sizes of the above spaces:

  1. Specifying using the memory attribute of the manifest file Use the memory attribute of the manifest file to specify the maximum size of the entire area described above. (This is referred to as maxSizeOfAllSpaces below.)

    The value of the maximum size specified in the memory attribute minus 100 MB is allocated to each space proportionally as shown below. 100 MB is allocated for the space that manages Java application processes.

    Space Maximum size that can be allocated
    Java heap 75% of (maxSizeOfAllSpaces - 100 MB)
    Metaspace 10% of (maxSizeOfAllSpaces - 100 MB)
    Other spaces 15% of (maxSizeOfAllSpaces - 100 MB)
  2. Specifying using the JAVA_OPTS environment variable Specify a Java option that sets the size of each space in the JAVA_OPTS environment variable.

    Estimate the maximum size required for each space and set them using the Java option so that the total size of the spaces does not exceed the result of (maxSizeOfAllSpaces (default is 1 GB) - 300 MB) (refer to note 1). 300 MB is allocated for the space that manages Java application processes.

    Users should verify and be responsible for selecting the correct Java options other than -Xmx and -XX:MaxMetaspaceSize in JAVA_OPTS.