ibmruntimes / ci.docker

Dockerfiles and build scripts for generating various Docker Images related to IBM Runtimes
Apache License 2.0
45 stars 35 forks source link

Memory management is not correct when using cgroup v2 #124

Closed lgrateau closed 1 year ago

lgrateau commented 2 years ago

With:

The computation of the memory of the JVM is not correct and cause Out Of Memory:

 docker run -m 4GB --rm ibmjava:8-jre java -XshowSettings:vm -version
VM settings:
    Max. Heap Size (Estimated): 512.00M
    Ergonomics Machine Class: client
    Using VM: IBM J9 VM

This is not the case with openjdk :

docker run -m 4GB --rm openjdk:8-jre java -XshowSettings:vm -version
VM settings:
    Max. Heap Size (Estimated): 2.49G
    Ergonomics Machine Class: server
    Using VM: OpenJDK 64-Bit Server VM

The root cause is probably due to the CGroup V2 support.

If we force use of cgroup v1 in Docker Desktop (with dev build listed on https://github.com/docker/for-mac/issues/6073#issuecomment-993274406) it works again fine:

 docker run -m 4GB  --rm  ibmjava:8-jre java  -XshowSettings:vm  -version
VM settings:
    Max. Heap Size (Estimated): 3.00G
    Ergonomics Machine Class: client
    Using VM: IBM J9 VM
java version "1.8.0_311"
Java(TM) SE Runtime Environment (build 8.0.7.0 - pxa6480sr7-20211025_01(SR7))
PYLochou commented 2 years ago

Some additional tests on different types of VM; RHEL 7 runs with cgroup (Podman 1.6.4) and RHEL 8 runs with cgroupv2 (Podman 3.3.1). I instanciated VMs with 2 and 8 GB but always ran the same command (podman run -m 4g --rm -XshowSettings:vm -version) to emphasize the fact that the IBM Java image does not compute Max Heap Size the same way as Oracle JRE and OpenJRE do:

RHEL 7 2GB RHEL 7 8GB RHEL 8 2GB RHEL 8 8GB
ibmjava:8-jre 512.00M 3.00G 512.00M 512.00M
store/oracle/serverjre:8 910.50M 910.50M 405.50M 1.69G
openjdk:8-jre 910.50M 910.50M 405.50M 1.69G

The most problematic result is of course Max Heap Size = 512MB in cgroupv2, even in the case of a fat VM :( OOME are raised fast with our product using IBM Java.

zhangs-ibm commented 2 years ago

If this issue connect with: https://github.com/docker/for-mac/issues/6118 ? The /sys/fs/cgroup/memory/memory.limit_in_bytes is missing at the new version of Mac docker container, while eclipse ORM project (which J9 JVM depends on) read this file to know if it's running at the container environment, code ref: https://github.com/eclipse/omr/blob/b5643d019207e22e3a6bcb49d09069200289b639/port/unix/omrsysinfo.c#L5941-L5945

zhangs-ibm commented 2 years ago

@lgrateau , Hi Laurent, I found open JDK has the same issue, the test result is not same with yours:

docker run -m 4GB --rm openjdk:8-jre java -XshowSettings:vm -version
Unable to find image ‘openjdk:8-jre’ locally
8-jre: Pulling from library/openjdk
0e29546d541c: Pull complete 
9b829c73b52b: Pull complete 
cb5b7ae36172: Pull complete 
99ce012bef04: Pull complete 
22dc2a72d098: Pull complete 
9c69a57e10d9: Pull complete 
Digest: sha256:c0ab1c0631266ef9420a414726a790733a2561efc5f4fa2f9b8186f4d6b00d53
Status: Downloaded newer image for openjdk:8-jre
VM settings:
  Max. Heap Size (Estimated): 665.00M
  Ergonomics Machine Class: server
  Using VM: OpenJDK 64-Bit Server VM
openjdk version “1.8.0_312”
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
lgrateau commented 2 years ago

Thanks for the feeback we will follow the docker issue too.

lgrateau commented 1 year ago

seem fixed closing it.