2

I ran this command which I found in this blog.

docker run -m 1GB openjdk:10 java \
-XX:+UseContainerSupport \
-XX:MinRAMPercentage=50 \
-XX:MaxRAMPercentage=80 \
-XshowSettings:vm \
-version

My output is this.

VM settings:
    Max. Heap Size (Estimated): 3.86G
    Using VM: OpenJDK 64-Bit Server VM

openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Debian-2)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Debian-2, mixed mode)

I am little bit confused now is that , when I limit the memory to 1G, why does Java see 3.86G or What needs to be done to make java see container memory limits ?

Note: I am on MAC. docker creates container inside the VM. So not sure if it matters.

3
  • Could you try running with -XX:+UseContainerSupport? It's supposed to be enabled by default, but maybe it's disabled somehow. Commented Jun 12, 2022 at 23:51
  • Updated the command. Still no luck. I am on a mac!. So docker container runs inside a VM. Not sure if it matters Commented Jun 13, 2022 at 0:06
  • What OS is the VM running? How much memory does it have? Commented Jun 13, 2022 at 7:15

1 Answer 1

3

When using Java in containers, one needs to be mindful of to what degree the JVM is aware of the resource limits set for the container it runs in. With Java version 10 (released in 2018) the JVM was first enabled to figure out whether it is running in a container, and if yes, how much memory was allocated to the container. Back then, CGroups V1 was used by the Linux Kernel to curtail the memory available to containers.

In the mean time, CGroups V2 (conceived in 2016) is gaining traction and is increasingly becoming the default for new Linux releases (e.g. Ubuntu and Flatcar Linux made it default in 2021). This means, once again a Java update is required to support CGroups V2 for correct handling of JVM resource limits and Heap configuration, which for OpenJDK came with Java version 15.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.