<p>I am starting a <code>Java</code> app as follows</p>

<pre><code>JAVA_OPTS=-Xmx7g -Xms512m -Xss1m -XX:+UseCompressedOops -XX:-OmitStackTraceInFastThrow

</code></pre>

<p>The pod I am using for this, has</p>

<pre><code>        resources:
          limits:
            cpu: 4096m
            memory: 9Gi
          requests:
            cpu: 1024m
            memory: 512Mi
</code></pre>

<p>However, I see once and then, pods being killed with</p>

<pre><code>"Memory cgroup out of memory: Kill process 3284727 (java) score 1982 or sacrifice child
Killed process 3284727 (java) total-vm:15318320kB, anon-rss:9380388kB, file-rss:20180kB, shmem-rss:0kB" 
</code></pre>

<p>Why does this take place?</p>

<p>How come the memory usage surpasses <code>9G</code> given that I set <code>Xmx=7G</code></p>

pkaramol
<p>With <code>-Xmx</code> you only specify the Java heap size - there is a lot of other memory that the JVM uses (like stack, native memory for the JVM, direct buffers, etc.). </p>

<p>In our experience the correct size for total usage of the JVM is 1.5 to 2 times the heap size but this depends heavily on your use case (for example some applications using direct buffers may have 32GB of RAM using only 1GB of heap).</p>

<p>So run your app with more limits, check the actual usage and then define that + 5% as a container limit.</p>

<p>You should also adapt your request to at least <code>1Gi</code> with <code>-Xms512m</code>.</p>
