Search code examples
javaelasticsearchkubernetesjvmheap-memory

JAVA 10+ -XX:MaxRAMPercentage flag in Kubernetes container


Java 10 introduced the corresponding -XX:{Initial|Min|Max}RAMPercentage flags to configure heap in container environment.

I'm running Elasticsearch in a k8s cluster. The Elaticsearch container has the following resources configuration:

resources:
  limits:
    memory: 512Mi
  requests:
    memory: 256Mi

Question: If I set -XX:MaxRAMPercentage to 50%, what will be the value?

  • 128Mi: 50% of the requested memory?
  • 256Mi: 50% of the limit?
  • variable in range 128Mi-256Mi: 50% of the realtime memory?

Solution

  • In a container, MaxRAMPercentage is calculated basing on cgroup memory.limit_in_bytes value.

    It is limits Kubernetes configuration that affects cgroup memory limit. So, in your case, the maximum heap size will be set to 256M (50% of the limit).