Should min and max heap and perm gen space be equal?
Environment
- OpenJDK
- Sun JDK
Issue
- Should minimum and maximum heap size be equal?
- Should minimum and maximum permanent generation size be equal?
- Should -Xmx and -Xms be set to the same value ?
Resolution
PermSize/MaxPermSize settings are N/A for JDK 8+ given it was replaced by metaspace - which is not on the heap;
For production environments, it is recommended to set the minimum heap size (-Xms) and maximum heap size (-Xmx) to equal values and also minimum permanent generation size (-XX:PermSize) and maximum permanent generation size (-XX:MaxPermSize) to equal values for the following reasons:
-
It avoids the major (full) garbage collections the JVM has to do to resize the heap or permanent generation space.
-
When using large pages, memory is reserved for the JVM based on the maximum heap and permanent generation sizes, and there is no expectation that the memory will be used by any other process.
-
When using large pages, it avoids the case when other processes using large pages exhaust the large page memory and the OS reverts to using regular pages when the JVM asks to allocate more memory.
For example:
-Xms1024M -Xmx1024M -XX:PermSize=128M -XX:MaxPermSize=128M
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.