Unable to set MinHeapSize elastically in Red OpenJDK UBI images
Environment
- OpenJDK
Issue
- Unable to set MinHeapSize elastically in ubi images.
- Moving from an older UBI8 image to a newer image results in many more GCs, due to the JVM trying to resize the heap down to a tiny
MinHeapSize.
Resolution
For use cases where the container is used like a VM, where memory is dedicated to the java process (e.g. InitialHeapSize = MaxHeapSize), add -XX:MaxHeapFreeRatio=100 to avoid resizing the heap down.
For use cases where MinHeapSize must be set elastically, a custom environment variable could be used to calculate the -Xms setting and pass it to the image.
This builds on top of the solution Usage of Java flags InitialRAMPercentage and MaxRAMPercentage regarding OpenJDK image default behaviors and this directly impacts products such as EAP, such as Using JAVA_MAX_MEM_RATIO on container JBoss EAP 7/8 image.
Root Cause
| Version | Behavior |
|---|---|
| For UBI8, prior to :1.15 | JAVA_INITIAL_MEM_RATIO set -Xms, which sets both MinHeapSize and InitialHeapSize to the same value. |
| For UBI8 :1.15+ | JAVA_INITIAL_MEM_RATIO sets -XX:MaxRAMPercentage which only sets InitialHeapSize. JVM ergonomics will set to send MinHeapSize to a very small value. |
| For UBI9 | The env variable JAVA_INITIAL_MEM_RATIO is removed in UBI9. User can set -XX:InitialRAMPercentage JVM flag to JAVA_OPTS/JAVA_OPTS_APPEND to achieve similar UBI8 functionality. |
For example:
$ /etc/alternatives/java_sdk_17/bin/java -XX:+UseParallelGC -XX:MaxRAM=1g -XX:InitialRAMPercentage=50 -XX:+PrintFlagsFinal -version | grep -E " (Initial|Min)HeapSize"
size_t InitialHeapSize = 268435456 {product} {ergonomic}
size_t MinHeapSize = 8388608 {product} {ergonomic}
The result is that there is no way to set MinHeapSize elastically (based on a memory limit).
The issue is captured upstream here:
Content from bugs.openjdk.org is not included.JDK-8278492: Confusion about parameter-XX:MinRAMPercentage
Diagnostic Steps
- Verify VM.info for JVM details in container.
- Verify inspect for deployment details and JVM settings such as
JAVA_INITIAL_MEM_RATIOand JAVA_OPTS/JAVA_OPTS_APPEND.
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.