🤖 fix: cpu.max file not found error in init.scope cgroup#27
Merged
DanielleMaywood merged 4 commits intomainfrom Nov 7, 2025
Merged
🤖 fix: cpu.max file not found error in init.scope cgroup#27DanielleMaywood merged 4 commits intomainfrom
DanielleMaywood merged 4 commits intomainfrom
Conversation
On systems running RKE2 with sysbox where /proc/self/cgroup reports 0::/init.scope, the code was failing because /sys/fs/cgroup/init.scope/cpu.max doesn't exist. The error occurred because cpuUsed() and cpuTotal() tried to read the CPU period directly from the missing file without falling back to parent cgroups. Changes: - Added cpuPeriod() helper method that follows the same pattern as cpuQuota() - The new method handles fs.ErrNotExist and strconv.ErrSyntax errors - Falls back to parent cgroup when cpu.max is missing (common in system-level cgroups like init.scope) - Updated cpuUsed() to use cpuPeriod() instead of directly reading - Updated cpuTotal() to use cpuPeriod() instead of directly reading - Added test case fsContainerCgroupV2InitScope to verify the fix The fix ensures consistent parent fallback behavior across all values read from cpu.max (quota, period, and usage calculations). Fixes issue where systems report: /sys/fs/cgroup/init.scope/cpu.max file does not exist
Per Linux kernel documentation, cpu.max has a default value of "max 100000" where 100000 microseconds (100ms) is the default period. The file exists on non-root cgroups, but in practice may be missing in certain scenarios. When cpu.max cannot be found anywhere in the cgroup hierarchy, instead of returning an error, we now use the documented default period of 100000 microseconds. This makes the code more robust and aligns with kernel behavior. Changes: - Added cgroupV2DefaultPeriodUs constant (100000) - Updated cpuPeriod() to return default period instead of error when no parent exists - Added test fixture fsContainerCgroupV2InitScopeNoCPUMax - Added test case CPU/InitScopeDefaultPeriod to verify default period behavior Ref: https://docs.kernel.org/admin-guide/cgroup-v2.html#cpu-interface-files
johnstcn
approved these changes
Nov 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On systems running RKE2 with sysbox where /proc/self/cgroup reports 0::/init.scope, the code was failing because /sys/fs/cgroup/init.scope/cpu.max doesn't exist. The error occurred because cpuUsed() and cpuTotal() tried to read the CPU period directly from the missing file without falling back to parent cgroups.
Changes:
The fix ensures consistent parent fallback behavior across all values read from cpu.max (quota, period, and usage calculations).
Fixes issue where systems report: /sys/fs/cgroup/init.scope/cpu.max file does not exist
🤖 PR was written by Claude Sonnet 4.5 Thinking using Coder Mux and reviewed by a human 👩