Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8264596

Java does not report correct memory (ram) availability in a containerd container

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      ADDITIONAL SYSTEM INFORMATION :
      using containerd 1.4.4

      A DESCRIPTION OF THE PROBLEM :
      When using containerd to run java in a container the total physical memory should be based on the cgroup's limit in bytes as described here: https://bugs.openjdk.java.net/browse/JDK-8146115

      This works correctly when the container is run using docker but not when it is run using containerd

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      # Running on a machine with 4GB of RAM

      docker run --rm --memory 1000000000 --entrypoint bash docker.io/library/openjdk:15-jdk-slim -c "echo 'System.out.println(\"TotalPhysicalMemorySize: \" + ((com.sun.management.OperatingSystemMXBean)java.lang.management.ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize())' | jshell -"

      > TotalPhysicalMemorySize: 999997440
      # This is correct!!

      sudo ctr run --rm --memory-limit 1000000000 docker.io/library/openjdk:15-jdk-slim java bash -c "echo 'System.out.println(\"TotalPhysicalMemorySize: \" + ((com.sun.management.OperatingSystemMXBean)java.lang.management.ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize())' | jshell -"

      > TotalPhysicalMemorySize: 4126633984
      # This incorrect - it is the machine's memory, not the container's

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The reported physical memory size should be the same when using containerd with a memory limit or docker with a memory limit
      ACTUAL -
      when using containerd the host machine's memory is reported not the docker container's memory

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            hseigel Harold Seigel
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: