[jdk21u-dev] RFR: 8349988: Change cgroup version detection logic to not depend on /proc/cgroups

Sergey Chernyshev schernyshev at openjdk.org
Fri Oct 24 15:02:45 UTC 2025


Hi all,

This is a clean backport of JDK-8349988 to JDK 21. The only minor context conflict is in src/hotspot/share/prims/whitebox.hpp.

The change improves container detection with newer kernels such as 6.14 HWE ([bug](https://bugs.launchpad.net/ubuntu/+source/linux-hwe-6.14/+bug/2122368)).


podman run -v $TEST_JDK:/opt/jdk --rm -ti --memory 200m --memory-swap 200m ubuntu:24.04 /opt/jdk/bin/java -XshowSettings:system --version



--- before	2025-10-24 16:33:52.000000000 +0200
+++ after	2025-10-24 16:34:19.000000000 +0200
@@ -1,6 +1,18 @@
 Operating System Metrics:
     Provider: cgroupv2
-    System not containerized.
+    Effective CPU Count: 12
+    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: 0.00K
+    Memory & Swap Limit: 200.00M
+    Maximum Processes Limit: 2048
+
 openjdk 21.0.10-internal 2026-01-20
 OpenJDK Runtime Environment (build 21.0.10-internal-adhoc.user.jdk21u)
 OpenJDK 64-Bit Server VM (build 21.0.10-internal-adhoc.user.jdk21u, mixed mode, sharing)



Tests:

No regressions observed in `test/hotspot/jtreg/containers/`, `test/jdk/jdk/internal/platform`

Details:

<details><summary>kernel 6.14 HWE Cgroup v2</summary>
<p>


--- test_results/summaryHotspotOrigCgv2.txt	2025-10-23 18:52:12.000000000 +0200
+++ test_results/summaryHotspotUpdatedCgv2.txt	2025-10-23 18:52:12.000000000 +0200
@@ -2,18 +2,18 @@
 containers/cgroup/TestContainerized.java            Passed. Execution successful
 containers/docker/DockerBasicTest.java              Passed. Execution successful
 containers/docker/ShareTmpDir.java                  Passed. Execution successful
-containers/docker/TestCPUAwareness.java             Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'active_processor_count.*1' missing from stdout/stderr
-containers/docker/TestCPUSets.java                  Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: assertTrue: expected true, was false
-containers/docker/TestContainerInfo.java            Passed. Skipped: jtreg.SkippedException: This test is cgroups v2 specific, skipped on cgroups v1
-containers/docker/TestJFREvents.java                Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'totalSize = 209715200' missing from stdout/stderr
+containers/docker/TestCPUAwareness.java             Passed. Execution successful
+containers/docker/TestCPUSets.java                  Passed. Execution successful
+containers/docker/TestContainerInfo.java            Passed. Execution successful
+containers/docker/TestJFREvents.java                Passed. Execution successful
 containers/docker/TestJFRNetworkEvents.java         Passed. Execution successful
 containers/docker/TestJFRWithJMX.java               Passed. Execution successful
 containers/docker/TestJcmd.java                     Passed. Execution successful
 containers/docker/TestJcmdWithSideCar.java          Passed. Execution successful
-containers/docker/TestLimitsUpdating.java           Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'active_processor_count: 2' missing from stdout/stderr
-containers/docker/TestMemoryAwareness.java          Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'Memory Limit is:.*104857600' missing from stdout/stderr
+containers/docker/TestLimitsUpdating.java           Passed. Execution successful
+containers/docker/TestMemoryAwareness.java          Passed. Execution successful
 containers/docker/TestMemoryWithCgroupV1.java       Passed. Execution successful
-containers/docker/TestMemoryWithSubgroups.java      Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'Lowest limit was:.*104857600' missing from stdout/stderr
-containers/docker/TestMisc.java                     Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'CheckContainerized: Running inside a container' missing from stdout/stderr
-containers/docker/TestPids.java                     Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: assertTrue: expected true, was false
-containers/systemd/SystemdMemoryAwarenessTest.java  Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'Memory Limit is: 536870912' missing from stdout/stderr
+containers/docker/TestMemoryWithSubgroups.java      Passed. Execution successful
+containers/docker/TestMisc.java                     Passed. Execution successful
+containers/docker/TestPids.java                     Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Limit value 9430 is not accepted as unlimited, log line was [0.051s][trace][os,container] Maximum number of tasks is: 9430
+containers/systemd/SystemdMemoryAwarenessTest.java  Passed. Execution successful
--- test_results/summaryJdkOrigCgv2.txt	2025-10-23 18:52:12.000000000 +0200
+++ test_results/summaryJdkUpdatedCgv2.txt	2025-10-23 18:52:12.000000000 +0200
@@ -4,12 +4,12 @@
 jdk/internal/platform/cgroup/TestCgroupSubsystemController.java    Passed. Execution successful
 jdk/internal/platform/cgroup/TestCgroupSubsystemFactory.java       Passed. Execution successful
 jdk/internal/platform/cgroup/TestSystemSettings.java               Passed. Execution successful
-jdk/internal/platform/docker/TestDockerBasic.java                  Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'Memory Limit: 300.00M' missing from stdout/stderr
+jdk/internal/platform/docker/TestDockerBasic.java                  Passed. Execution successful
 jdk/internal/platform/docker/TestDockerCpuMetrics.java             Passed. Execution successful
-jdk/internal/platform/docker/TestDockerMemoryMetrics.java          Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [1]
+jdk/internal/platform/docker/TestDockerMemoryMetrics.java          Passed. Execution successful
 jdk/internal/platform/docker/TestDockerMemoryMetricsSubgroup.java  Passed. Execution successful
 jdk/internal/platform/docker/TestGetFreeSwapSpaceSize.java         Passed. Execution successful
-jdk/internal/platform/docker/TestLimitsUpdating.java               Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'Runtime.availableProcessors: 2' missing from stdout/stderr
-jdk/internal/platform/docker/TestPidsLimit.java                    Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: assertTrue: expected true, was false
-jdk/internal/platform/docker/TestSystemMetrics.java                Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [1]
+jdk/internal/platform/docker/TestLimitsUpdating.java               Passed. Execution successful
+jdk/internal/platform/docker/TestPidsLimit.java                    Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Limit value 9430 is not accepted as unlimited, log line was Maximum Processes Limit: 9430
+jdk/internal/platform/docker/TestSystemMetrics.java                Passed. Execution successful
 jdk/internal/platform/docker/TestUseContainerSupport.java          Passed. Execution successful


</p>
</details> 

<details><summary>kernel 6.14 HWE Cgroup v1</summary>
<p>


no differences

</p>
</details> 

<details><summary>kernel 6.11 Cgroup v2</summary>
<p>

One test failed below: jdk/internal/platform/docker/TestDockerMemoryMetrics.java
The test fails intermittently, it is unrelated to this backport: the `failcount` test is either being OOM-killed, likely because the total process allocation is bigger than `-Xmx` size, or because the memory fail count left unchanged when `--memory` is made greater than `-Xmx` size. [JDK-8334771](https://bugs.openjdk.org/browse/JDK-8334771) is the attempt to fix the test, (it still fails in my environment, also with the proposed patch).


--- test_results_no_hwe/noHweHotspotOrigCgv2.txt	2025-10-24 01:21:16.000000000 +0200
+++ test_results_no_hwe/noHweHotspotUpdatedCgv2.txt	2025-10-24 01:21:16.000000000 +0200
@@ -3,17 +3,17 @@
 containers/docker/DockerBasicTest.java              Passed. Execution successful
 containers/docker/ShareTmpDir.java                  Passed. Execution successful
 containers/docker/TestCPUAwareness.java             Passed. Execution successful
 containers/docker/TestCPUSets.java                  Passed. Execution successful
 containers/docker/TestContainerInfo.java            Passed. Execution successful
 containers/docker/TestJFREvents.java                Passed. Execution successful
 containers/docker/TestJFRNetworkEvents.java         Passed. Execution successful
 containers/docker/TestJFRWithJMX.java               Passed. Execution successful
 containers/docker/TestJcmd.java                     Passed. Execution successful
 containers/docker/TestJcmdWithSideCar.java          Passed. Execution successful
 containers/docker/TestLimitsUpdating.java           Passed. Execution successful
 containers/docker/TestMemoryAwareness.java          Passed. Execution successful
 containers/docker/TestMemoryWithCgroupV1.java       Passed. Execution successful
 containers/docker/TestMemoryWithSubgroups.java      Passed. Execution successful
 containers/docker/TestMisc.java                     Passed. Execution successful
-containers/docker/TestPids.java                     Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Limit value 9431 is not accepted as unlimited, log line was [0.064s][trace][os,container] Maximum number of tasks is: 9431
+containers/docker/TestPids.java                     Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Limit value 9431 is not accepted as unlimited, log line was [0.051s][trace][os,container] Maximum number of tasks is: 9431
 containers/systemd/SystemdMemoryAwarenessTest.java  Passed. Execution successful
--- test_results_no_hwe/noHweJdkOrigCgv2.txt	2025-10-24 01:21:16.000000000 +0200
+++ test_results_no_hwe/noHweJdkUpdatedCgv2.txt	2025-10-24 01:21:16.000000000 +0200
@@ -1,15 +1,15 @@
 jdk/internal/platform/cgroup/CgroupV1SubsystemControllerTest.java  Passed. Execution successful
 jdk/internal/platform/cgroup/CgroupV2SubsystemControllerTest.java  Passed. Execution successful
 jdk/internal/platform/cgroup/TestCgroupMetrics.java                Passed. Execution successful
 jdk/internal/platform/cgroup/TestCgroupSubsystemController.java    Passed. Execution successful
 jdk/internal/platform/cgroup/TestCgroupSubsystemFactory.java       Passed. Execution successful
 jdk/internal/platform/cgroup/TestSystemSettings.java               Passed. Execution successful
 jdk/internal/platform/docker/TestDockerBasic.java                  Passed. Execution successful
 jdk/internal/platform/docker/TestDockerCpuMetrics.java             Passed. Execution successful
-jdk/internal/platform/docker/TestDockerMemoryMetrics.java          Passed. Execution successful
+jdk/internal/platform/docker/TestDockerMemoryMetrics.java          Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [137]
 jdk/internal/platform/docker/TestDockerMemoryMetricsSubgroup.java  Passed. Execution successful
 jdk/internal/platform/docker/TestGetFreeSwapSpaceSize.java         Passed. Execution successful
 jdk/internal/platform/docker/TestLimitsUpdating.java               Passed. Execution successful
 jdk/internal/platform/docker/TestPidsLimit.java                    Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Limit value 9431 is not accepted as unlimited, log line was Maximum Processes Limit: 9431
 jdk/internal/platform/docker/TestSystemMetrics.java                Passed. Execution successful
 jdk/internal/platform/docker/TestUseContainerSupport.java          Passed. Execution successful

</p>
</details> 

<details><summary>kernel 6.11 Cgroup v1</summary>
<p>


--- test_results_no_hwe/noHweHotspotOrigCgv1.txt	2025-10-24 14:24:27.000000000 +0200
+++ test_results_no_hwe/noHweHotspotUpdatedCgv1.txt	2025-10-24 14:24:27.000000000 +0200
@@ -1,19 +1,19 @@
 containers/cgroup/CgroupSubsystemFactory.java       Passed. Execution successful
 containers/cgroup/TestContainerized.java            Passed. Execution successful
 containers/docker/DockerBasicTest.java              Passed. Execution successful
 containers/docker/ShareTmpDir.java                  Passed. Execution successful
 containers/docker/TestCPUAwareness.java             Passed. Execution successful
 containers/docker/TestCPUSets.java                  Passed. Execution successful
 containers/docker/TestContainerInfo.java            Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 containers/docker/TestJFREvents.java                Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 containers/docker/TestJFRNetworkEvents.java         Passed. Execution successful
 containers/docker/TestJFRWithJMX.java               Passed. Execution successful
 containers/docker/TestJcmd.java                     Passed. Execution successful
 containers/docker/TestJcmdWithSideCar.java          Passed. Execution successful
-containers/docker/TestLimitsUpdating.java           Error. Program `/home/user/work/repos/jdk21u/build/linux-x86_64-server-release/images/jdk/bin/java' timed out (timeout set to 600000ms, elapsed time including timeout handling was 600273ms).
+containers/docker/TestLimitsUpdating.java           Error. Program `/home/user/work/repos/jdk21u/build/linux-x86_64-server-release/images/jdk-updated/bin/java' timed out (timeout set to 600000ms, elapsed time including timeout handling was 600281ms).
 containers/docker/TestMemoryAwareness.java          Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 containers/docker/TestMemoryWithCgroupV1.java       Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 containers/docker/TestMemoryWithSubgroups.java      Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 containers/docker/TestMisc.java                     Passed. Execution successful
 containers/docker/TestPids.java                     Passed. Execution successful
 containers/systemd/SystemdMemoryAwarenessTest.java  Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: 'Memory Limit is: 536870912' missing from stdout/stderr
--- test_results_no_hwe/noHweJdkOrigCgv1.txt	2025-10-24 14:24:27.000000000 +0200
+++ test_results_no_hwe/noHweJdkUpdatedCgv1.txt	2025-10-24 14:24:27.000000000 +0200
@@ -1,15 +1,15 @@
 jdk/internal/platform/cgroup/CgroupV1SubsystemControllerTest.java  Passed. Execution successful
 jdk/internal/platform/cgroup/CgroupV2SubsystemControllerTest.java  Passed. Execution successful
 jdk/internal/platform/cgroup/TestCgroupMetrics.java                Passed. Execution successful
 jdk/internal/platform/cgroup/TestCgroupSubsystemController.java    Passed. Execution successful
 jdk/internal/platform/cgroup/TestCgroupSubsystemFactory.java       Passed. Execution successful
 jdk/internal/platform/cgroup/TestSystemSettings.java               Passed. Execution successful
 jdk/internal/platform/docker/TestDockerBasic.java                  Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 jdk/internal/platform/docker/TestDockerCpuMetrics.java             Passed. Execution successful
 jdk/internal/platform/docker/TestDockerMemoryMetrics.java          Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 jdk/internal/platform/docker/TestDockerMemoryMetricsSubgroup.java  Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 jdk/internal/platform/docker/TestGetFreeSwapSpaceSize.java         Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
-jdk/internal/platform/docker/TestLimitsUpdating.java               Error. Program `/home/user/work/repos/jdk21u/build/linux-x86_64-server-release/images/jdk/bin/java' timed out (timeout set to 600000ms, elapsed time including timeout handling was 600296ms).
+jdk/internal/platform/docker/TestLimitsUpdating.java               Error. Program `/home/user/work/repos/jdk21u/build/linux-x86_64-server-release/images/jdk-updated/bin/java' timed out (timeout set to 600000ms, elapsed time including timeout handling was 600254ms).
 jdk/internal/platform/docker/TestPidsLimit.java                    Passed. Execution successful
 jdk/internal/platform/docker/TestSystemMetrics.java                Failed. Execution failed: `main' threw exception: java.lang.RuntimeException: Expected to get exit value of [0], exit value is: [127]
 jdk/internal/platform/docker/TestUseContainerSupport.java          Passed. Execution successful



</p>
</details>

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

Commit messages:
 - 8349988: Change cgroup version detection logic to not depend on /proc/cgroups

Changes: https://git.openjdk.org/jdk21u-dev/pull/2390/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk21u-dev&pr=2390&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8349988
  Stats: 385 lines in 6 files changed: 291 ins; 23 del; 71 mod
  Patch: https://git.openjdk.org/jdk21u-dev/pull/2390.diff
  Fetch: git fetch https://git.openjdk.org/jdk21u-dev.git pull/2390/head:pull/2390

PR: https://git.openjdk.org/jdk21u-dev/pull/2390


More information about the jdk-updates-dev mailing list