I'm running a JVM inside a docker container. I set memory limit for container with a hardcoded value. And I use new -XX:UseCGroupMemoryLimitForHeap option for JVM. In this case JVM should allocate heap memory depending on the container memory.
JVM actually does it, up to some point. If you give 500Mb of container memory JVM allocates 444.5 MB memory as expected.
But then JVM gets stuck at 1.74 Gb of heap memory. Even given 8Gb of container memory, JVM still allocates 1.74 Gb heap memory.
I can allocate 4Gb of heap memory with -Xmx option.
How can I let JVM allocate as much memory as it can?
-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1but i fixed the problem. There was no problem actually. These flags work as expected and JVM allocates as much memory as possible. Problem was my docker memory limit.