Skip to content

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

Open
jmtd wants to merge 8 commits into
openjdk:masterfrom
jmtd:8349988-8u
Open

8349988: Change cgroup version detection logic to not depend on /proc/cgroups#779
jmtd wants to merge 8 commits into
openjdk:masterfrom
jmtd:8349988-8u

Conversation

@jmtd

@jmtd jmtd commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

This is a backport of an improvement to cgroup detection logic. This fixes mis-detection on some systems e.g. Debian and Ubuntu systems, or systems running a recent enough mainline kernel which no longer propagates the older /proc/cgroups file with necessary controllers.

This wasn't clean: there are a few C++ changes (nullptr to NULL substitutions, os namespacing on cstd functions); logging mechanism changes; removal of PID controller related stuff.

Cherry-picking note: for reasons unknown git failed to apply the hunks for whitebox.cpp so I did those manually. It also patched the wrong copy of WhiteBox.java. I'm hoping we can pick up JDK-8327993 which should resolve this for future cgroups backports.

The modified CgroupSubsystemFactory.java passes.


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
  • JDK-8347129 needs maintainer approval

Issues

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

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 779

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Mar 24, 2026

Copy link
Copy Markdown

👋 Welcome back jdowland! 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

openjdk Bot commented Mar 24, 2026

Copy link
Copy Markdown

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk

openjdk Bot commented Mar 24, 2026

Copy link
Copy Markdown

⚠️ @jmtd the commit 59c7c8ed4b3392d3c8ee26128aaa71d10f46a595 does not refer to an issue in project JDK.

jerboaa and others added 3 commits March 24, 2026 13:48
…71d10f46a595

For whatever reason, `git cherry-pick` could not resolve the path to
whitebox.cpp in 8u and didn't apply the changes. Here they are. This
wasn't clean: the `validate_cgroup` change had context differences.
I've opted to incorporate 11u's use of CG_INFO_LENGTH for cg_infos.

Signed-off-by: Jonathan Dowland <jdowland@redhat.com>
remove reference to pids controller

remove os namespacing of fopen

replace log_debug with tty->print_cr

Signed-off-by: Jonathan Dowland <jdowland@redhat.com>
@jmtd jmtd changed the title Backport 59c7c8ed4b3392d3c8ee26128aaa71d10f46a595 Backport dd842c440e3f50028fc991b29ea096f0e64e967b Mar 24, 2026
@openjdk openjdk Bot changed the title Backport dd842c440e3f50028fc991b29ea096f0e64e967b 8349988: Change cgroup version detection logic to not depend on /proc/cgroups Mar 24, 2026
@openjdk

openjdk Bot commented Mar 24, 2026

Copy link
Copy Markdown

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 Mar 24, 2026
@jmtd

jmtd commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author
# newfailures.txt
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#digicerttlseccrootg5 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#digicerttlsrsarootg5 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#quovadisrootca1g3 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#quovadisrootca2g3 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#quovadisrootca3g3 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#teliarootcav2 

gut feeling is these will be unrelated but I will investigate further.

@jmtd

jmtd commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

reproduced those failures locally. now trying the master branch. Edit: yes same failures

@gnu-andrew

Copy link
Copy Markdown
Member
# newfailures.txt
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#digicerttlseccrootg5 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#digicerttlsrsarootg5 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#quovadisrootca1g3 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#quovadisrootca2g3 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#quovadisrootca3g3 
security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java#teliarootcav2 

gut feeling is these will be unrelated but I will investigate further.

They are.

I haven't looked at this one in detail yet, but I would wait until the 11u one is in, as I did spot a few issues with that one.

@jmtd

jmtd commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Local testing: hotspot/test/runtime/containers/cgroup/CgroupSubsystemFactory.java passes. Manual check:

before:

    $ /usr/lib/jvm/java-8-openjdk-amd64/bin/java -XX:+UnlockDiagnosticVMOptions -XX:+PrintContainerInfo -version
    OSContainer::init: Initializing Container Support
    One or more required controllers disabled at kernel level.
    openjdk version "1.8.0_482"
    OpenJDK Runtime Environment (build 1.8.0_482-8u482-ga-1-b08)
    OpenJDK 64-Bit Server VM (build 25.482-b08, mixed mode)

after:

    $ ./build/linux-x64/jdk/bin/java -XX:+UnlockDiagnosticVMOptions -XX:+PrintContainerInfo -version
    OSContainer::init: Initializing Container Support
    Detected optional cpuset controller entry in /sys/fs/cgroup/cgroup.controllers
    Detected cgroups v2 unified hierarchy
    Path to /cpu.max is /sys/fs/cgroup/user.slice/user-1000.slice/session-41.scope/cpu.max
    Raw value for CPU quota is: max
    CPU Quota is: -1
    Path to /cpu.max is /sys/fs/cgroup/user.slice/user-1000.slice/session-41.scope/cpu.max
    CPU Period is: 100000
    Path to /cpu.weight is /sys/fs/cgroup/user.slice/user-1000.slice/session-41.scope/cpu.weight
    Raw value for CPU Shares is: 100
    CPU Shares is: -1
    OSContainer::active_processor_count: 24
    CgroupSubsystem::active_processor_count (cached): 24
    total physical memory: 33498771456
    Path to /memory.max is /sys/fs/cgroup/user.slice/user-1000.slice/session-41.scope/memory.max
    Raw value for memory limit is: max
    Memory Limit is: Unlimited
    container memory limit unlimited: -1, using host value 33498771456
    CgroupSubsystem::active_processor_count (cached): 24
    Path to /cpu.max is /sys/fs/cgroup/user.slice/user-1000.slice/session-41.scope/cpu.max
    Raw value for CPU quota is: max
    CPU Quota is: -1
    Path to /cpu.max is /sys/fs/cgroup/user.slice/user-1000.slice/session-41.scope/cpu.max
    CPU Period is: 100000
    Path to /cpu.weight is /sys/fs/cgroup/user.slice/user-1000.slice/session-41.scope/cpu.weight
    Raw value for CPU Shares is: 100
    CPU Shares is: -1
    OSContainer::active_processor_count: 24
    openjdk version "1.8.0_502-internal"
    OpenJDK Runtime Environment (build 1.8.0_502-internal-jon_2026_05_08_09_24-b00)
    OpenJDK 64-Bit Server VM (build 25.502-b00, mixed mode)

@jmtd jmtd marked this pull request as ready for review May 8, 2026 09:38
@openjdk openjdk Bot added the rfr Pull request is ready for review label May 8, 2026
@mlbridge

mlbridge Bot commented May 8, 2026

Copy link
Copy Markdown

Webrevs

@mlbridge

mlbridge Bot commented May 8, 2026

Copy link
Copy Markdown

Mailing list message from Jonathan Dowland on jdk8u-dev:

On Fri May 8, 2026 at 10:45 AM BST, Andrew John Hughes wrote:
(snip)

Skara has posted Andrew's comment today in response to me marking the PR
(which was draft) ready for review: Andrew's original comment was on Apr
3.

This is finally RFR from my POV: GHA tests pass (all bar windows/x84
which is an unrelated failure: CAInterop.java#comodorsaca); modified
test in backport passes; correct behaviour confirmed by hand on affected
machine (see my last comment on the PR, which has not been echoed to the
mailing list); PR up to date with master; and I've incorporated changes
suggested from the 11u backport.

Thanks,

--
👱🏻 Jonathan Dowland
✎ jon@dow.land
🔗 jmtd.net

@bridgekeeper

bridgekeeper Bot commented Jun 5, 2026

Copy link
Copy Markdown

@jmtd This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@jmtd

jmtd commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

/touch

Still RFR. Thanks!

@openjdk

openjdk Bot commented Jun 5, 2026

Copy link
Copy Markdown

@jmtd The pull request is being re-evaluated and the inactivity timeout has been reset.

@jerboaa jerboaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few things need some touch-ups IMO. Let me know what you think.

Comment thread hotspot/src/os/linux/vm/cgroupSubsystem_linux.cpp Outdated
Comment on lines +193 to +194
// cpuset might not be enabled on newer Linux distros (Fedora 41)
bool all_required_controllers_enabled = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment about cpuset is about JDK-8347129 which isn't in 8u. Perhaps this should get added - with /issue add - as after this patch it's essentially optional.

Comment on lines +219 to +221
if (i == CPUSET_IDX && PrintContainerInfo) {
tty->print_cr("Detected optional %s controller entry in %s",
controller, controllers_file);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment regarding JDK-8347129

Comment thread hotspot/src/os/linux/vm/cgroupSubsystem_linux.cpp Outdated
Comment on lines +334 to +335
sysFsCgroupCgroupControllersNoPidsPath = Paths.get(existingDirectory.toString(), "sys_fs_cgroup_cgroup_controllers_no_pids");
Files.write(sysFsCgroupCgroupControllersNoPidsPath, sysFsCgroupCgroupControllersNoPidsContent.getBytes(StandardCharsets.UTF_8));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the pids controller support not present. I'm doubtful this should be included as a test.

Comment on lines +258 to 265
public native int validateCgroup(boolean cgroupsV2Enabled,
String controllersFile,
String procSelfCgroup,
String procSelfMountinfo);
public native void printOsInfo();
public native int validateCgroup(String procCgroups,
String procSelfCgroup,
String procSelfMountinfo);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The public native int validateCgroup() native method should only be there once. It's there twice with different signatures.

Comment thread hotspot/src/os/linux/vm/cgroupSubsystem_linux.cpp
Co-authored-by: Severin Gehwolf <jerboaa@gmail.com>
@jmtd

jmtd commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

/issue add JDK-8354878

@openjdk

openjdk Bot commented Jun 22, 2026

Copy link
Copy Markdown

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

Signed-off-by: Jonathan Dowland <jdowland@redhat.com>
@jmtd

jmtd commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

/issue add JDK-8347129

@openjdk

openjdk Bot commented Jun 22, 2026

Copy link
Copy Markdown

@jmtd
Adding additional issue to issue list: 8347129: cpuset cgroups controller is required for no good reason.

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 rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

3 participants