Skip to content

Conversation

@DanielleMaywood
Copy link
Collaborator

@DanielleMaywood DanielleMaywood commented Nov 7, 2025

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


🤖 PR was written by Claude Sonnet 4.5 Thinking using Coder Mux and reviewed by a human 👩

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
@DanielleMaywood DanielleMaywood marked this pull request as ready for review November 7, 2025 03:19
@DanielleMaywood DanielleMaywood merged commit 9017018 into main Nov 7, 2025
30 checks passed
@DanielleMaywood DanielleMaywood deleted the clistat-cgroup-cpu-max branch November 7, 2025 14:04
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.

2 participants