InitialHeapSize java is set to Zero and yet the application run, How is that?

1/16/2020

I try to run an java application with this jvm option inside a docker orchestrated by k8s:

-XX:InitialHeapSize=0 -XX:InitialRAMPercentage=0 -XX:MaxRAMPercentage=80

and this is my limits on cpu and on memory:

resources:
          limits:
            cpu: 900m
            memory: 900M
          requests:
            cpu: 900m
            memory: 900M

when I apply for the changes, the application run even I give her a 0 for InitialRAMPercentage and 0 for XX:InitialHeapSize.

When I go inside my pod and I run ps ax

It's give me this:

PID TTY      STAT   TIME COMMAND
    1 ?        Ssl    0:53 java -XX:InitialHeapSize=0 -XX:InitialRAMPercentage=0 -XX:MaxRAMPercentage=80 

As I may understand, When I pass 0 as percentage, the application will not run because there is no memory are allowed. Is that true ?

Have you any explanation of it ?

-- Hamdy
java
jvm
kubernetes

1 Answer

1/16/2020

The initial heap size just tells the JVM the starting heap size, it will grow it as necessary (until maximum heap size is reached). Also coincidentally, setting the initial size to 0 is the same as not setting it at all and lets the JVM judge the starting heap size by itself.

See for example this SO answer and the links provided in it.

-- kidney
Source: StackOverflow