8

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?
trincot
  • 317,000
  • 35
  • 244
  • 286
Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
  • 1
    [somehow related](https://stackoverflow.com/questions/61506136/kubernetes-pod-memory-java-gc-logs/61512521#61512521) – Eugene Dec 06 '20 at 14:34

1 Answers1

13

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).

apangin
  • 92,924
  • 10
  • 193
  • 247
  • During the pod scheduling, the container will only take the requested amount of memory and later increase it depending on load. So In the beginning, all the requested memory (ie. 256Mi) will be considered as heap? – Kamol Hasan Dec 06 '20 at 12:45
  • @KamolHasan Yes – apangin Dec 06 '20 at 13:40
  • 1
    Not without `-XX:+UseContainerSupport` https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/openj9/xxinitialrampercentage/index.html – darw Jan 14 '21 at 11:31
  • 9
    isn't `-XX:+UseContainerSupport` enabled by default? – Roberto Manfreda Sep 15 '21 at 15:52