<p>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?</p>

<pre><code>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: {}
</code></pre>

<p><a href="https://i.stack.imgur.com/t3mkW.png" rel="nofollow noreferrer">Container JAVA_OPTS screenshot</a></p>

<blockquote>
  <p>Max heap is being capped at 256MB.</p>
</blockquote>

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

<blockquote>
  <p>I tried updating the MaxRAMFraction setting to 1</p>
</blockquote>

<p><code>MaxRAMFraction</code> is deprecated and un-used, forget about it.</p>

<blockquote>
  <p>UseCGroupMemoryLimitForHeap</p>
</blockquote>

<p>is deprecated and will be removed. Use <code>UseContainerSupport</code> that was ported to java-8 also. </p>

<blockquote>
  <p>MaxRAM=2g</p>
</blockquote>

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

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

<p>Instead, we do:</p>

<pre><code>-XX:InitialRAMPercentage=70
-XX:MaxRAMPercentage=70
-XX:+UseContainerSupport
-XX:InitialHeapSize=0
</code></pre>

<p>And that's it. What this does?</p>

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