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

[cgroups v2] Memory and swap limits reported incorrectly

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b19
    • CPU:
      generic
    • OS:
      linux

      Backports

        Description

        The cgroup v2 interface file for swap limits is memory.swap.max. However, in contrast to the cgroup v1 interface file memory.memsw.limit_in_bytes, this file contains only swap limits. The JDKs expectations were written with cgroup v1 interface files in mind.

        For example Metrics.getMemoryAndSwapLimit() has this javadoc:

        """
        Returns the maximum amount of physical memory and swap space, in bytes, that can be allocated in the Isolation Group.
        """

        Yet, the cgroup v2 code only reads memory.swap.max not taking memory.max into account. The results are incorrect. This was previously hiding since the initial crun code seems to have been setting memory.swap.max to the --memory-swap UI option value directly. It's now setting it to $MEMORY_SWAP-$MEMORY so as to mimic cgroups v1 behaviour.

        Example:

        $ podman run --rm -v $(pwd)/build/linux-x86_64-server-release/images/jdk:/jdk -ti --memory=200m --memory-swap=1g fedora:31 /bin/bash
        [root@ce700ea24fd2 /]# /jdk/bin/java -XshowSettings:system -version
        Operating System Metrics:
            Provider: cgroupv2
            Effective CPU Count: 4
            CPU Period: 100000us
            CPU Quota: -1
            CPU Shares: -1
            List of Processors: N/A
            List of Effective Processors: N/A
            List of Memory Nodes: N/A
            List of Available Memory Nodes: N/A
            Memory Limit: 200.00M
            Memory Soft Limit: Unlimited
            Memory & Swap Limit: 824.00M

        openjdk version "16-internal" 2021-03-16
        OpenJDK Runtime Environment (build 16-internal+0-adhoc.sgehwolf.jdk-jdk)
        OpenJDK 64-Bit Server VM (build 16-internal+0-adhoc.sgehwolf.jdk-jdk, mixed mode, sharing)

        This also yields a test failure in jdk/internal/platform/docker/TestDockerMemoryMetrics.java:

         stdout: [[memoryswap, 200m, 1g]
        Exception in thread "main" java.lang.RuntimeException: Memory and swap limit not equal, expected : [209715200, 1073741824], got : [209715200, 864026624]
                at MetricsMemoryTester.testMemoryAndSwapLimit(MetricsMemoryTester.java:150)
                at MetricsMemoryTester.main(MetricsMemoryTester.java:40)

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                sgehwolf Severin Gehwolf
                Reporter:
                sgehwolf Severin Gehwolf
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: