Skip to content

Cgroup cpu usage#1029

Merged
VegetarianOrc merged 17 commits intomasterfrom
cgroup-cpu-usage
Oct 21, 2025
Merged

Cgroup cpu usage#1029
VegetarianOrc merged 17 commits intomasterfrom
cgroup-cpu-usage

Conversation

@VegetarianOrc
Copy link
Copy Markdown
Contributor

@VegetarianOrc VegetarianOrc commented Oct 8, 2025

What was changed

Update RealSysInfo to read cgroupv2 CPU limits when the sysinfo crate has cgroup memory limits available.

Why?

When running in a container it's more appropriate to report the CPU usage as a factor of it's limit rather than the host system.

Checklist

  1. Closes [Feature Request] Support CPU Cgroup Limits in Resource-based tuner / Confirm memory functionality #903

  2. How was this tested:

  • Added unit tests for reading the cgroupv2 CPU files and calculating usage based on their contents.
  • Added unit tests that confirm RealSysInfo respects cgroup limits. These tests skip when not running in a cgroup. A small helper script is included at docker-cgroup-tests.sh to cross-compile tests and execute only cgroup tests via docker.
  1. Any docs updates needed?

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 8, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@VegetarianOrc VegetarianOrc marked this pull request as ready for review October 20, 2025 22:57
@VegetarianOrc VegetarianOrc requested a review from a team as a code owner October 20, 2025 22:57
Comment thread core/src/worker/tuner/resource_based.rs Outdated
Comment on lines +516 to +518
//there won't be a cgroup cpu usage if there is no limit applied to the cgroup
//or if an error is encountered when reading cpu.stat or cpu.max
//in these cases, fallback to global cpu usage
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: I'm vaguely surprised this isn't a cargo fmt thing, but, the lack a space after your // freaks me out

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.

//boo

Comment on lines +1020 to +1023
#[test]
fn cgroup_realsysinfo_uses_cgroup_limits_cpu() {
let sys_info = RealSysInfo::new();
let cgroup_info = CGroupCpuInfo::new(CgroupV2CpuFileSystem);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Honestly this is one of the few spots where I don't like Rust - really this should be an integ test. It could be its own binary and only run in CI. Having to have the skips in a unit test feels a little awkward, but having to pub all this or put it in its own crate is even stupider.

I don't have any actual suggestion here, just whining.

... Actually maybe I do - let's protect these with explicit env vars saying to run the tests. That way they also won't silently succeed when they're supposed to be able to read stuff but can't

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I actually had this as an integ test at first, but couldn't stomach adding the pub so I undid that and moved these to unit tests 😅.

Added the env var though!

Copy link
Copy Markdown
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for the work on this

@VegetarianOrc VegetarianOrc merged commit 35e021b into master Oct 21, 2025
19 checks passed
@VegetarianOrc VegetarianOrc deleted the cgroup-cpu-usage branch October 21, 2025 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Support CPU Cgroup Limits in Resource-based tuner / Confirm memory functionality

4 participants