Skip to content

8349988: Change cgroup version detection logic to not depend on /proc/cgroups#4271

Closed
jerboaa wants to merge 2 commits intoopenjdk:masterfrom
jerboaa:JDK-8347811_cgroups_vers_backport
Closed

8349988: Change cgroup version detection logic to not depend on /proc/cgroups#4271
jerboaa wants to merge 2 commits intoopenjdk:masterfrom
jerboaa:JDK-8347811_cgroups_vers_backport

Conversation

@jerboaa
Copy link
Copy Markdown
Contributor

@jerboaa jerboaa commented Feb 16, 2026

Please review this backport of the cgroup version detection logic which affects JDK 17 as well. Newer systems which are affected, like Ubuntu 2025-XX, get more commonly used. Therefore, I propose to backport it there too. The JDK 21 backport got shipped with the 21.0.10 update in January. The patch is not clean due to nullptr vs NULL differences and more context changes (e.g. JDK-8261242 not in JDK 17). Since the patch is not clean anyway, I've included the one-liner of JDK-8354878 right away.

Testing:

  • GHA
  • Container tests on cg v1 and cg v2 on Linux x86_64 (RHEL 8 and Fedora 42). Manual testing on an affected cg v2 system that container limits are detected.

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • JDK-8354878 needs maintainer approval
  • JDK-8347811 needs maintainer approval
  • JDK-8349988 needs maintainer approval

Issues

  • JDK-8349988: Change cgroup version detection logic to not depend on /proc/cgroups (Sub-task - P3 - Approved)
  • JDK-8347811: Container detection code for cgroups v2 should use cgroup.controllers (Enhancement - P3 - Approved)
  • JDK-8354878: File Leak in CgroupSubsystemFactory::determine_type of cgroupSubsystem_linux.cpp:300 (Bug - P3 - Approved)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk17u-dev.git pull/4271/head:pull/4271
$ git checkout pull/4271

Update a local copy of the PR:
$ git checkout pull/4271
$ git pull https://git.openjdk.org/jdk17u-dev.git pull/4271/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4271

View PR using the GUI difftool:
$ git pr show -t 4271

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk17u-dev/pull/4271.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Feb 16, 2026

👋 Welcome back sgehwolf! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Feb 16, 2026

@jerboaa This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8349988: Change cgroup version detection logic to not depend on /proc/cgroups
8347811: Container detection code for cgroups v2 should use cgroup.controllers
8354878: File Leak in CgroupSubsystemFactory::determine_type of cgroupSubsystem_linux.cpp:300

Reviewed-by: fitzsim, stuefe, andrew

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk Bot changed the title Backport dd842c440e3f50028fc991b29ea096f0e64e967b 8349988: Change cgroup version detection logic to not depend on /proc/cgroups Feb 16, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Feb 16, 2026

This backport pull request has now been updated with issues from the original commit.

@openjdk openjdk Bot added the backport Port of a pull request already in a different code base label Feb 16, 2026
@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Feb 16, 2026

/issue add JDK-8347811
/issue add JDK-8354878

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Feb 16, 2026

@jerboaa
Updating description of additional solved issue: 8347811: Container detection code for cgroups v2 should use cgroup.controllers.

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Feb 16, 2026

@jerboaa
Adding additional issue to issue list: 8354878: File Leak in CgroupSubsystemFactory::determine_type of cgroupSubsystem_linux.cpp:300.

@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Feb 16, 2026

I've included JDK-8354878 - a one-liner - directly in here so as to not regress.

@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Feb 17, 2026

On an affected system (Ubuntu 2025-10) we have this before/after.

Before

$ podman run --rm -ti --cpus 2 --memory 200m --memory-swap=200m -v $(pwd)/jdk-17.0.18+8:/opt/jdk ubuntu:latest /opt/jdk/bin/java -Xlog:os+container=trace --version
[0.000s][trace][os,container] OSContainer::init: Initializing Container Support
[0.000s][debug][os,container] Detected optional pids controller entry in /proc/cgroups
[0.001s][debug][os,container] controller cpuset is not enabled

[0.001s][debug][os,container] controller memory is not enabled

[0.001s][debug][os,container] One or more required controllers disabled at kernel level.
openjdk 17.0.18 2026-01-20
OpenJDK Runtime Environment Temurin-17.0.18+8 (build 17.0.18+8)
OpenJDK 64-Bit Server VM Temurin-17.0.18+8 (build 17.0.18+8, mixed mode, sharing)

After

$ podman run --rm -ti --cpus 2 --memory 200m --memory-swap=200m -v $(pwd)/jdk17-jdk:/opt/jdk ubuntu:latest /opt/jdk/bin/java -Xlog:os+container=trace --version
[0.000s][trace][os,container] OSContainer::init: Initializing Container Support
[0.000s][debug][os,container] Detected optional pids controller entry in /sys/fs/cgroup/cgroup.controllers
[0.000s][debug][os,container] controller cpuset is not enabled
[0.000s][debug][os,container] Detected cgroups v2 unified hierarchy
[0.000s][trace][os,container] Path to /cpu.max is /sys/fs/cgroup/cpu.max
[0.000s][trace][os,container] Raw value for CPU quota is: 200000
[0.000s][trace][os,container] CPU Quota is: 200000
[0.000s][trace][os,container] Path to /cpu.max is /sys/fs/cgroup/cpu.max
[0.000s][trace][os,container] CPU Period is: 100000
[0.000s][trace][os,container] CPU Quota count based on quota/period: 2
[0.000s][trace][os,container] OSContainer::active_processor_count: 2
[0.001s][trace][os,container] CgroupSubsystem::active_processor_count (cached): 2
[0.001s][trace][os,container] total physical memory: 7687462912
[0.001s][trace][os,container] Path to /memory.max is /sys/fs/cgroup/memory.max
[0.001s][trace][os,container] Raw value for memory limit is: 209715200
[0.001s][trace][os,container] Memory Limit is: 209715200
[0.001s][trace][os,container] CgroupSubsystem::active_processor_count (cached): 2
[0.032s][trace][os,container] Path to /cpu.max is /sys/fs/cgroup/cpu.max
[0.032s][trace][os,container] Raw value for CPU quota is: 200000
[0.032s][trace][os,container] CPU Quota is: 200000
[0.032s][trace][os,container] Path to /cpu.max is /sys/fs/cgroup/cpu.max
[0.032s][trace][os,container] CPU Period is: 100000
[0.032s][trace][os,container] CPU Quota count based on quota/period: 2
[0.032s][trace][os,container] OSContainer::active_processor_count: 2
openjdk 17.0.19-internal 2026-04-21
OpenJDK Runtime Environment (fastdebug build 17.0.19-internal+0-adhoc.sgehwolf.jdk17u-dev)
OpenJDK 64-Bit Server VM (fastdebug build 17.0.19-internal+0-adhoc.sgehwolf.jdk17u-dev, mixed mode, sharing)

@jerboaa jerboaa marked this pull request as ready for review February 17, 2026 13:22
@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Feb 17, 2026

@fitzsim Could you please take a look? Thank you!

@openjdk openjdk Bot added the rfr Pull request is ready for review label Feb 17, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented Feb 17, 2026

Webrevs

@fitzsim
Copy link
Copy Markdown
Contributor

fitzsim commented Feb 17, 2026

@jerboaa taking a look...

@fitzsim
Copy link
Copy Markdown
Contributor

fitzsim commented Feb 17, 2026

/reviewer credit @fitzsim

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Feb 17, 2026

@fitzsim Only the author (@jerboaa) is allowed to issue the reviewer command.

@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Feb 17, 2026

/reviewer credit @fitzsim

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Feb 17, 2026

@jerboaa
Reviewer fitzsim successfully credited.

@fitzsim
Copy link
Copy Markdown
Contributor

fitzsim commented Feb 17, 2026

This looks good to me. I no longer have the virtual machines at hand to test, so I didn't test it. I confirmed the changes versus the original patch seem fine though:

  • copyright date updated, OK
  • fclose addition per JDK-8354878, good fix
  • context differences around match_mount_info, expected
  • double-space to single-space change in comment, fine
  • comment differences due to JDK-8261242 not having been backported, expected

At least make test TEST=test/hotspot/jtreg/containers/cgroup/CgroupSubsystemFactory.java succeeds for me on Fedora 43 x86-64.

Copy link
Copy Markdown
Contributor

@fitzsim fitzsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Feb 17, 2026

Thanks for the review!

@jmtd
Copy link
Copy Markdown

jmtd commented Feb 24, 2026

On my host (Debian, kernel 6.16.9+deb14-amd64), with the parent PID (the shell) memory.max set to 200MiB.

before:

$ ./build/linux-x64/jdk/bin/java -Xlog:os+container=trace -XshowSettings:system -version
...
[0.000s][debug][os,container] controller memory is not enabled
[0.000s][debug][os,container] One or more required controllers disabled at kernel level.

after:

$ ./build/linux-x64/jdk/bin/java -Xlog:os+container=trace -XshowSettings:system -version
...
[0.004s][trace][os,container] Raw value for memory limit is: 209715200
...
    Memory Limit: 200.00M

i.e., the warning about missing memory controller has gone.

@jmtd
Copy link
Copy Markdown

jmtd commented Feb 24, 2026

I'm not sure how useful this is, but CgroupSubsystemFactory.java on master passes for me (prior to this change) so it doesn't seem a useful way to demonstrate the bug being fixed.
The modified version of the test in this PR fails against a build from master but not for a useful reason (java.lang.UnsatisfiedLinkError: 'int jdk.test.whitebox.WhiteBox.validateCgroup(boolean, java.lang.String, java.lang.String, java.lang.String)'). I recall a different test failing for me due to missing mem controller in /proc/cgroups, I'm going to see if I can figure out which one it was.

@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Mar 23, 2026

I'm not sure how useful this is, but CgroupSubsystemFactory.java on master passes for me (prior to this change) so it doesn't seem a useful way to demonstrate the bug being fixed.
The modified version of the test in this PR fails against a build from master but not for a useful reason (java.lang.UnsatisfiedLinkError: 'int jdk.test.whitebox.WhiteBox.validateCgroup(boolean, java.lang.String, java.lang.String, java.lang.String)').

In order to get past that you'd need the whitebox changes from this patch as well. Finally you'd have to change the underlying function it calls to also take a boolean (since the test relies on a hint from the filesystem type of /sys/fs/cgroup). Then the test should fail, without the product fix.

Alternatively run container tests on Ubuntu 2025.10 before this fix and after.

Comment thread src/hotspot/os/linux/cgroupSubsystem_linux.cpp
Comment thread src/hotspot/os/linux/cgroupSubsystem_linux.cpp
Comment thread src/hotspot/os/linux/cgroupSubsystem_linux.cpp
Copy link
Copy Markdown
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Mar 23, 2026

⚠️ @jerboaa This change is now ready for you to apply for maintainer approval. This can be done directly in each associated issue or by using the /approval command.

Copy link
Copy Markdown
Member

@gnu-andrew gnu-andrew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a pretty clean backport, with the only real difference between NULL and nullptr.

I was confused by the cgroupSubsystem_linux.cpp changes at first but I now see they are coming from a second change. It would have been a bit clearer to have these in their own commit.

@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Mar 23, 2026

/approval request Please approve this enhancement to change the cgroups version detection in Hotspot based on the filesystem type of /sys/fs/cgroup and using cgroup.controllers file over the deprecated /proc/cgroups file (which is cg v1 only). This change is needed to properly handle container detection on newer cgroup v2 systems with specific kernels which might no longer expose cg v2 controllers in the legacy file /proc/cgroups. One such system is Ubuntu 2025.10. The patch isn't clean since some later backports aren't in JDK 17u. It got reviewed by Thomas Fitzsimmons, Thomas Stüfe and Andrew Hughes. The one-liner follow-up of JDK-8354878 is included in the patch. Risk is low to medium. Changes container detection code. Linux-only change. Tested with container tests on cg v1 and cg v2 as well as affected system (all pass). Patch is included in later JDKs (21.0.10, 25 GA) for a while now with no known bug-tail.

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Mar 23, 2026

@jerboaa
8349988: The approval request has been created successfully.
8347811: The approval request has been created successfully.
8354878: The approval request has been created successfully.

@openjdk openjdk Bot added the approval Requires approval; will be removed when approval is received label Mar 23, 2026
@gnu-andrew
Copy link
Copy Markdown
Member

/approve yes

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Mar 23, 2026

@gnu-andrew
8349988: The approval request has been approved.
8347811: The approval request has been approved.
8354878: The approval request has been approved.

@openjdk openjdk Bot added ready Pull request is ready to be integrated and removed approval Requires approval; will be removed when approval is received labels Mar 23, 2026
@jerboaa
Copy link
Copy Markdown
Contributor Author

jerboaa commented Mar 23, 2026

/integrate

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Mar 23, 2026

Going to push as commit 4376c27.

@openjdk openjdk Bot added the integrated Pull request has been integrated label Mar 23, 2026
@openjdk openjdk Bot closed this Mar 23, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Mar 23, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Mar 23, 2026

@jerboaa Pushed as commit 4376c27.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Port of a pull request already in a different code base integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants