RFR: 8322420: [Linux] cgroup v2: Limits in parent nested control groups are not detected [v15]

Severin Gehwolf sgehwolf at openjdk.org
Mon Jul 22 13:51:41 UTC 2024


On Thu, 18 Jul 2024 14:48:02 GMT, Jan Kratochvil <jkratochvil at openjdk.org> wrote:

>> The testcase requires root permissions.
>> 
>> Fix by  Severin Gehwolf.
>> Testcase by Jan Kratochvil.
>
> Jan Kratochvil has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Unify 4 copies of adjust_controller()

test/hotspot/jtreg/containers/cgroup/NestedCgroup.java line 161:

> 159:             System.err.println(LINE_DELIM + " " + (isCgroup2 ? "cgroup2" : "cgroup1") + " mount point: " + sysFsCgroup);
> 160:             memory_max_filename = isCgroup2 ? "memory.max" : "memory.limit_in_bytes";
> 161:             Files.writeString(Path.of(sysFsCgroup + "/" + CGROUP_OUTER + "/" + memory_max_filename), "" + MEMORY_MAX_OUTER);

This logic doesn't seem to detect `cgv1` and `cgv2` correctly. When I run this on a cgv1 system (hybrid) then I get a failure that looks like this:


----------System.err:(33/2506)----------
-------------------------------------------------------------------------------- command: cgdelete -r -g memory:jdktest150899
-------------------------------------------------------------------------------- stdout
-------------------------------------------------------------------------------- stderr
cgdelete: cannot remove group 'jdktest150899': No such file or directory
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------- command: cgcreate -g memory:jdktest150899/inner
-------------------------------------------------------------------------------- stdout
-------------------------------------------------------------------------------- stderr
--------------------------------------------------------------------------------
isCgroup2 = true
-------------------------------------------------------------------------------- cgroup2 mount point: /sys/fs/cgroup/unified
java.nio.file.NoSuchFileException: /sys/fs/cgroup/unified/jdktest150899/memory.max
        at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
        at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:262)
        at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:482)
        at java.base/java.nio.file.Files.newOutputStream(Files.java:228)
        at java.base/java.nio.file.Files.write(Files.java:3516)
        at java.base/java.nio.file.Files.writeString(Files.java:3738)
        at java.base/java.nio.file.Files.writeString(Files.java:3678)
        at NestedCgroup$Test.<init>(NestedCgroup.java:161)
        at NestedCgroup$TestTwoLimits.<init>(NestedCgroup.java:190)
        at NestedCgroup.main(NestedCgroup.java:221)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:588)
        at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
        at java.base/java.lang.Thread.run(Thread.java:1575)

JavaTest Message: Test threw exception: java.nio.file.NoSuchFileException: /sys/fs/cgroup/unified/jdktest150899/memory.max
JavaTest Message: shutting down test


I suggest to use code similar to other tests which use the metrics API to figure out which cgroup version is in use. For example `TestMemoryWithCgroupV1` has this code snippet which should work just fine here as well:


Metrics metrics = Metrics.systemMetrics();
        if (metrics == null) {
            System.out.println("TEST PASSED!!!");
            return;
        }
        if ("cgroupv1".equals(metrics.getProvider())) {
           // cg v1 branch
        } else {
           // cg v2 branch
        }

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17198#discussion_r1686587070


More information about the core-libs-dev mailing list