<p>Java 10 <a href="https://www.atamanroman.dev/articles/jvm-memory-settings-container-environment/#fn:13" rel="noreferrer">introduced</a> the corresponding <code>-XX:{Initial|Min|Max}RAMPercentage</code> flags to configure heap in container environment.</p>
<p>I'm running Elasticsearch in a k8s cluster. The Elaticsearch container has the following resources configuration:</p>
<pre><code>resources:
  limits:
    memory: 512Mi
  requests:
    memory: 256Mi
</code></pre>
<p><strong>Question:</strong> If I set <code>-XX:MaxRAMPercentage</code> to 50%, what will be the value?</p>
<ul>
<li><code>128Mi</code>: 50% of the requested memory?</li>
<li><code>256Mi</code>: 50% of the limit?</li>
<li>variable in range <code>128Mi-256Mi</code>: 50% of the realtime memory?</li>
</ul>

Kamol Hasan
<p>In a container, <code>MaxRAMPercentage</code> is calculated basing on cgroup <code>memory.limit_in_bytes</code> value.</p>
<p>It is <code>limits</code> Kubernetes configuration that affects cgroup memory limit. So, in your case, the maximum heap size will be set to 256M (50% of the limit).</p>
