Skip to content

JDK-8293472: Incorrect container resource limit detection if manual cgroup fs mounts present#10193

Closed
casparcwang wants to merge 13 commits intoopenjdk:masterfrom
casparcwang:JDK-8293472
Closed

JDK-8293472: Incorrect container resource limit detection if manual cgroup fs mounts present#10193
casparcwang wants to merge 13 commits intoopenjdk:masterfrom
casparcwang:JDK-8293472

Conversation

@casparcwang
Copy link
Copy Markdown
Contributor

@casparcwang casparcwang commented Sep 7, 2022

Similar to JDK-8253435, when setting the mount path of cgroup controller "memory/cpu/cpuacct/pids", it should also discard duplicate items.


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

Issue

  • JDK-8293472: Incorrect container resource limit detection if manual cgroup fs mounts present

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10193/head:pull/10193
$ git checkout pull/10193

Update a local copy of the PR:
$ git checkout pull/10193
$ git pull https://git.openjdk.org/jdk pull/10193/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10193

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10193.diff

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Sep 7, 2022

👋 Welcome back casparcwang! 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 added the rfr Pull request is ready for review label Sep 7, 2022
@openjdk
Copy link
Copy Markdown

openjdk bot commented Sep 7, 2022

@casparcwang The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Sep 7, 2022
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Sep 7, 2022

@casparcwang casparcwang changed the title JDK-8293472: Cgroup: 'stomping of _mount_path' crash if manually mounted cpusets exist JDK-8293472: Cgroup: 'stomping of _mount_path' crash if manually mounted cg controller exist Sep 7, 2022
Copy link
Copy Markdown
Contributor

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

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

Looks mostly good. https://bugs.openjdk.org/browse/JDK-8270087 seems to be an early sighting of this. It mentions a reproducer, manually mount /sys/fs/cgroup from the host into the container. Please write a container test asserting that no warnings get produced. Perhaps use test/hotspot/jtreg/containers/docker/DockerBasicTest.java and write a new test method javaVersionWithCgMounts or some such, which verifies no warning shows up on stdout.

Comment thread src/hotspot/os/linux/cgroupSubsystem_linux.cpp Outdated
Comment thread src/hotspot/os/linux/cgroupSubsystem_linux.cpp Outdated
@jerboaa
Copy link
Copy Markdown
Contributor

jerboaa commented Sep 7, 2022

My testing on cgv2 and cgv1 indicates that we might have a container resource limit detection problem depending on the order of mountinfo entries are observed at runtime. Please add memory and cpu limit container detection tests which do -v /sys/fs/cgroup:/cgroups-in:ro as a volume mount in addition. Thanks!

@casparcwang casparcwang changed the title JDK-8293472: Cgroup: 'stomping of _mount_path' crash if manually mounted cg controller exist JDK-8293472: Potentially incorrect container resource limit detection if manual cgroup fs mounts present Sep 8, 2022
@casparcwang
Copy link
Copy Markdown
Contributor Author

Looks mostly good. https://bugs.openjdk.org/browse/JDK-8270087 seems to be an early sighting of this. It mentions a reproducer, manually mount /sys/fs/cgroup from the host into the container. Please write a container test asserting that no warnings get produced. Perhaps use test/hotspot/jtreg/containers/docker/DockerBasicTest.java and write a new test method javaVersionWithCgMounts or some such, which verifies no warning shows up on stdout.

Thank you very much for the reviewing. I have not noticed JDK-8270087 before, sorry about filing a duplicate jdk bug.

My testing on cgv2 and cgv1 indicates that we might have a container resource limit detection problem depending on the order of mountinfo entries are observed at runtime. Please add memory and cpu limit container detection tests which do -v /sys/fs/cgroup:/cgroups-in:ro as a volume mount in addition. Thanks!

The container resource limit detection problem is also fixed when there are multiple cgroup fs mount entries, it is caused by multiple setting of root mount path in function CgroupSubsystemFactory::determine_type.

Copy link
Copy Markdown
Contributor

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

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

We definitely need regression tests for memory/cpu limits with those additional cgroup mounts.
Please take a look at test/hotspot/jtreg/containers/docker/TestCPUAwareness.java and test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java

For cgroups v2 the issues isn't fixed. The paths for cg v2 are being set here:
https://github.com/openjdk/jdk/blob/98da03af50e2372817a7b5e381eea5ee6f2cb919/src/hotspot/os/linux/cgroupSubsystem_linux.cpp#L303..L313.

Example of running (with your patch on a cg v2 system):

$ sudo podman run --rm -ti --memory=300M --memory-swap=300M -v /sys/fs/cgroup:/cgroup-in:ro -v $(pwd)/jdk20-jdk:/opt/jdk:z fedora:36 /opt/jdk/bin/java -Xlog:os+container=trace -version 2>&1 | grep 'Memory Limit'
[0.001s][trace][os,container] Memory Limit is: -2
[0.055s][trace][os,container] Memory Limit is: -2

Expected:

[0.001s][trace][os,container] Memory Limit is: 314572800
[0.068s][trace][os,container] Memory Limit is: 314572800

Comment thread test/hotspot/jtreg/containers/docker/DockerBasicTest.java Outdated
Comment thread test/hotspot/jtreg/containers/docker/DockerBasicTest.java
@casparcwang
Copy link
Copy Markdown
Contributor Author

We definitely need regression tests for memory/cpu limits with those additional cgroup mounts. Please take a look at test/hotspot/jtreg/containers/docker/TestCPUAwareness.java and test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java

For cgroups v2 the issues isn't fixed. The paths for cg v2 are being set here: https://github.com/openjdk/jdk/blob/98da03af50e2372817a7b5e381eea5ee6f2cb919/src/hotspot/os/linux/cgroupSubsystem_linux.cpp#L303..L313.

Example of running (with your patch on a cg v2 system):

$ sudo podman run --rm -ti --memory=300M --memory-swap=300M -v /sys/fs/cgroup:/cgroup-in:ro -v $(pwd)/jdk20-jdk:/opt/jdk:z fedora:36 /opt/jdk/bin/java -Xlog:os+container=trace -version 2>&1 | grep 'Memory Limit'
[0.001s][trace][os,container] Memory Limit is: -2
[0.055s][trace][os,container] Memory Limit is: -2

Expected:

[0.001s][trace][os,container] Memory Limit is: 314572800
[0.068s][trace][os,container] Memory Limit is: 314572800

I have add a cgroup v2 test with duplicate mount info, now it's working for cgroup v2.

Copy link
Copy Markdown
Contributor

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! A few more thoughts.

Comment thread src/hotspot/os/linux/cgroupSubsystem_linux.cpp Outdated
Comment thread src/hotspot/os/linux/cgroupSubsystem_linux.cpp Outdated
Comment thread test/hotspot/jtreg/containers/docker/TestCPUAwareness.java Outdated
Comment thread test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java Outdated
Copy link
Copy Markdown
Contributor

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

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

Looks good to me. Feel free to add the suggestion.

Comment thread src/hotspot/os/linux/cgroupSubsystem_linux.cpp
@casparcwang casparcwang changed the title JDK-8293472: Potentially incorrect container resource limit detection if manual cgroup fs mounts present JDK-8293472: Incorrect container resource limit detection if manual cgroup fs mounts present Sep 14, 2022
@openjdk
Copy link
Copy Markdown

openjdk bot commented Sep 14, 2022

⚠️ @casparcwang the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout JDK-8293472
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link
Copy Markdown

openjdk bot commented Sep 14, 2022

@casparcwang 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:

8293472: Incorrect container resource limit detection if manual cgroup fs mounts present

Reviewed-by: sgehwolf, iklam

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 105 new commits pushed to the master branch:

  • 1caba0f: 8292948: JEditorPane ignores font-size styles in external linked css-file
  • eeb625e: 8290169: adlc: Improve child constraints for vector unary operations
  • 2057070: 8293815: P11PSSSignature.engineUpdate should not print debug messages during normal operation
  • 7376c55: 8293769: RISC-V: Add a second temporary register for BarrierSetAssembler::load_at
  • d191e47: 8293768: Add links to JLS 19 and 20 from SourceVersion enum constants
  • a75ddb8: 8293122: (fs) Use file cloning in macOS version of Files::copy method
  • 95c7c55: 8293402: hs-err file printer should reattempt stack trace printing if it fails
  • 211fab8: 8291669: [REDO] Fix array range check hoisting for some scaled loop iv
  • 7f3250d: 8293787: Linux aarch64 build fails after 8292591
  • 2a38791: 8292755: Non-default method in interface leads to a stack overflow in JShell
  • ... and 95 more: https://git.openjdk.org/jdk/compare/ef20ffe4d222d48f0bdba81a0b864d9fb455e9a6...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jerboaa, @iklam) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 14, 2022
@casparcwang
Copy link
Copy Markdown
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 14, 2022
@openjdk
Copy link
Copy Markdown

openjdk bot commented Sep 14, 2022

@casparcwang
Your change (at version 380054b) is now ready to be sponsored by a Committer.

@casparcwang
Copy link
Copy Markdown
Contributor Author

Is it OK to be pushed? Or shall we wait for one more review?

@jerboaa
Copy link
Copy Markdown
Contributor

jerboaa commented Sep 14, 2022

Is it OK to be pushed? Or shall we wait for one more review?

A second review would be good. Perhaps @iklam has some cycles?

Copy link
Copy Markdown
Member

@iklam iklam left a comment

Choose a reason for hiding this comment

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

Looks good to me. Just a small nit on the test,

Comment thread test/hotspot/jtreg/containers/docker/DockerBasicTest.java Outdated
@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Sep 15, 2022
Copy link
Copy Markdown
Contributor

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

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

Still good for me.

@jerboaa
Copy link
Copy Markdown
Contributor

jerboaa commented Sep 15, 2022

@casparcwang Feel free to issue /integrate again and I'll sponsor. Thanks!

@casparcwang
Copy link
Copy Markdown
Contributor Author

/integrate

@casparcwang
Copy link
Copy Markdown
Contributor Author

@casparcwang Feel free to issue /integrate again and I'll sponsor. Thanks!

Thank you very much!

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 15, 2022
@openjdk
Copy link
Copy Markdown

openjdk bot commented Sep 15, 2022

@casparcwang
Your change (at version 8170214) is now ready to be sponsored by a Committer.

@jerboaa
Copy link
Copy Markdown
Contributor

jerboaa commented Sep 15, 2022

/sponsor

@openjdk
Copy link
Copy Markdown

openjdk bot commented Sep 15, 2022

Going to push as commit 8f3bbe9.
Since your change was applied there have been 105 commits pushed to the master branch:

  • 1caba0f: 8292948: JEditorPane ignores font-size styles in external linked css-file
  • eeb625e: 8290169: adlc: Improve child constraints for vector unary operations
  • 2057070: 8293815: P11PSSSignature.engineUpdate should not print debug messages during normal operation
  • 7376c55: 8293769: RISC-V: Add a second temporary register for BarrierSetAssembler::load_at
  • d191e47: 8293768: Add links to JLS 19 and 20 from SourceVersion enum constants
  • a75ddb8: 8293122: (fs) Use file cloning in macOS version of Files::copy method
  • 95c7c55: 8293402: hs-err file printer should reattempt stack trace printing if it fails
  • 211fab8: 8291669: [REDO] Fix array range check hoisting for some scaled loop iv
  • 7f3250d: 8293787: Linux aarch64 build fails after 8292591
  • 2a38791: 8292755: Non-default method in interface leads to a stack overflow in JShell
  • ... and 95 more: https://git.openjdk.org/jdk/compare/ef20ffe4d222d48f0bdba81a0b864d9fb455e9a6...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 15, 2022
@openjdk openjdk bot closed this Sep 15, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Sep 15, 2022
@openjdk
Copy link
Copy Markdown

openjdk bot commented Sep 15, 2022

@jerboaa @casparcwang Pushed as commit 8f3bbe9.

💡 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

hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants