Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cgroup v2 CPU stats when controller not enabled #347

Open
jay-mckay opened this issue Aug 28, 2024 · 1 comment · May be fixed by #348
Open

Support cgroup v2 CPU stats when controller not enabled #347

jay-mckay opened this issue Aug 28, 2024 · 1 comment · May be fixed by #348

Comments

@jay-mckay
Copy link

manager.Stat() iterates over enabled controllers to construct statistics, namely for memory and CPU. If a controller is not enabled, the statistics are not provided.

cgroups/cgroup2/manager.go

Lines 565 to 575 in 0c03de4

for _, controller := range controllers {
switch controller {
case "cpu", "memory":
if err := readKVStatsFile(c.path, controller+".stat", out); err != nil {
if os.IsNotExist(err) {
continue
}
return nil, err
}
}
}

However, regardless of whether the cpu controller is enabled, cgroups v2 always provides the following statistics in cpu.stat :

  • usage_usec
  • user_usec
  • system_usec

Systemd no longer enables this controller when the property CPUAccounting=True, meaning these statistics are not provided when they probably should be. Stat() should be modified to fix this.

See https://docs.kernel.org/admin-guide/cgroup-v2.html#cpu-interface-files, systemd/systemd#10507

@jay-mckay
Copy link
Author

I believe this straightforward. If this behavior is desired, I can work on the fix.

jay-mckay added a commit to jay-mckay/cgroups that referenced this issue Sep 3, 2024
The unified hierarchy provides the cpu.stat file for every cgroup,
regardless if the CPU controller is enabled (in fact, setting the
systemd property CPUAccounting=True does not enable this controller
because of this fact). It provides the usage_usec, user_usec,
and system_usec by default. Instead of reading the stat for each
enabled controller (CPU and memory), just attempt to read them
each time the Stat() function is called.

Attempting to read the memory.stat file even if memory accounting
is not enabled seems insignificant (some other files always have
a read attempt, such as memory.current), and eliminates finding and
looping over enabled controllers.

Resolves: containerd#347

Signed-off-by: Jackson McKay  <jackjaymckay@gmail.com>
@jay-mckay jay-mckay linked a pull request Sep 3, 2024 that will close this issue
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 a pull request may close this issue.

1 participant