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

memory_and_swap_limit() reporting wrong values on systems with swapaccount=0

XMLWordPrintable

    • b11
    • generic
    • linux

        JDK-8250984 and JDK-8253797 fixed this on the Java side of container support code. If reading file memory.memsw.limit_in_bytes returns an error Metrics.getMemoryAndSwapLimit() returns the memory limit (i.e. no swap). Same for cg2's memory.swap.max. Yet, on the hotspot side this isn't being treated the same way. Swap reporting is off, which yields to confusing trace output:

        # podman run --rm -ti [...] --memory=200M --memory-swap=250M fedora:37
        Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
        [root@dc3a44d5100a /]# cd /testclasses/
        [root@dc3a44d5100a testclasses]# /opt/jdk/bin/java -Xlog:os+container=trace -Xbootclasspath/a:whitebox.jar -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI PrintContainerInfo | grep os,container | grep -A1 memsw.limit_in_bytes
        [0.099s][trace][os,container] Path to /memory.memsw.limit_in_bytes is /sys/fs/cgroup/memory/memory.memsw.limit_in_bytes
        [0.099s][debug][os,container] Open of file /sys/fs/cgroup/memory/memory.memsw.limit_in_bytes failed, No such file or directory
        [0.099s][trace][os,container] Memory and Swap Limit is: 18446744073709551614

        It also shows up via VM.info or hs_err files like so:

        [root@dc3a44d5100a testclasses]# /opt/jdk/bin/java -Xbootclasspath/a:whitebox.jar -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI PrintContainerInfo | grep -A20 cgroup
        container (cgroup) information:
        container_type: cgroupv1
        cpu_cpuset_cpus: 0-3
        cpu_memory_nodes: 0
        active_processor_count: 4
        cpu_quota: no quota
        cpu_period: 100000
        cpu_shares: no shares
        memory_limit_in_bytes: 204800 k
        memory_and_swap_limit_in_bytes: not supported
        memory_soft_limit_in_bytes: unlimited
        memory_usage_in_bytes: 28504 k
        memory_max_usage_in_bytes: 28908 k
        kernel_memory_usage_in_bytes: 1196 k
        kernel_memory_max_usage_in_bytes: unlimited
        kernel_memory_limit_in_bytes: 1324 k
        maximum number of tasks: 2048
        current number of tasks: 15

        KVM virtualization detected
        Steal ticks since vm start: 0
        Steal ticks percentage since vm start: 0.000

        These:
        memory_limit_in_bytes: 204800 k
        memory_and_swap_limit_in_bytes: not supported

        Should be:
        memory_limit_in_bytes: 204800 k
        memory_and_swap_limit_in_bytes: 204800 k


        # cat /proc/cmdline | grep swapaccount
        BOOT_IMAGE=(hd0,gpt2)/vmlinuz-5.19.7-300.fc37.x86_64 root=UUID=fcdabdd6-70cf-4a94-905d-86c966fed17d ro rootflags=subvol=root rhgb quiet systemd.unified_cgroup_hierarchy=0 swapaccount=0


        Comparing this to the java level which we can see with -XshowSettings:system we see:

        # /opt/jdk/bin/java -XshowSettings:system -version
        Operating System Metrics:
            Provider: cgroupv1
            Effective CPU Count: 4
            CPU Period: 100000us
            CPU Quota: -1
            CPU Shares: -1
            List of Processors, 4 total:
            0 1 2 3
            List of Effective Processors, 4 total:
            0 1 2 3
            List of Memory Nodes, 1 total:
            0
            List of Available Memory Nodes, 1 total:
            0
            Memory Limit: 200.00M
            Memory Soft Limit: Unlimited
            Memory & Swap Limit: 200.00M
            Maximum Processes Limit: 2048

        openjdk version "21-internal" 2023-09-19
        OpenJDK Runtime Environment (fastdebug build 21-internal-adhoc.sgehwolf.jdk-jdk)
        OpenJDK 64-Bit Server VM (fastdebug build 21-internal-adhoc.sgehwolf.jdk-jdk, mixed mode, sharing)

        I.e. memory and swap limit match. Both are 200.00M. I.e. no swap.

              sgehwolf Severin Gehwolf
              sgehwolf Severin Gehwolf
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: