OpenJDK 1.8.0_242, MaxRAMFraction setting not reflecting

I am running a Springboot application in the alpine-OpenJDK image and facing OutOfMemory issues. Max heap is being capped at 256MB. I tried updating the MaxRAMFraction setting to 1 but did not see it getting reflected in the Java_process. I have an option to increase the container memory limit to 3000m but would prefer to use Cgroup memory with MaxRamfraction=1. Any thoughts?

Java-Version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (IcedTea 3.15.0) (Alpine 8.242.08-r0)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

bash-5.0$ java -XX:+PrintFlagsFinal -version | grep -Ei "maxheapsize|MaxRAMFraction"
    uintx DefaultMaxRAMFraction                     = 4                                   {product}
    uintx MaxHeapSize                              := 262144000                           {product}
    uintx MaxRAMFraction                            = 4                                   {product}
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (IcedTea 3.15.0) (Alpine 8.242.08-r0)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

Container Resource limits
 ports:
        - containerPort: 8080
          name: 8080tcp02
          protocol: TCP
        resources:
          limits:
            cpu: 350m
            memory: 1000Mi
          requests:
            cpu: 50m
            memory: 1000Mi
        securityContext:
          capabilities: {}

Container JAVA_OPTS screenshot

1 answer

  • answered 2020-02-13 03:52 Eugene

    Max heap is being capped at 256MB.

    You mean via -m in docker? If such, this is not the java heap you are specifying, but the total memory.

    I tried updating the MaxRAMFraction setting to 1

    MaxRAMFraction is deprecated and un-used, forget about it.

    UseCGroupMemoryLimitForHeap

    is deprecated and will be removed. Use UseContainerSupport that was ported to java-8 also.

    MaxRAM=2g

    Do you know what this actually does? It sets the value for the "physical" RAM that the JVM is supposed to think you have.

    I assume that you did not set -Xms and -Xmx on purpose here? Since you do not know how much memory the container will have? If such, we are in the same shoes. We do know that the min we are going to get is 1g, but I have no idea of the max, as such I prefer not to set -Xms and -Xmx explicitly.

    Instead, we do:

    -XX:InitialRAMPercentage=70
    -XX:MaxRAMPercentage=70
    -XX:+UseContainerSupport
    -XX:InitialHeapSize=0
    

    And that's it. What this does?

    InitialRAMPercentage is used to calculate the initial heap size, BUT only when InitialHeapSize/Xms are missing. MaxRAMPercentage is used to calculate the maximum heap. Do not forget that a java process needs more than just heap, it needs native structures also; that is why that 70 (%).