containerd / cgroups

cgroups package for Go
https://containerd.io
Apache License 2.0
1.08k stars 235 forks source link

Support cgroup v2 CPU stats when controller not enabled #347

Open jay-mckay opened 3 weeks ago

jay-mckay commented 3 weeks ago

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.

https://github.com/containerd/cgroups/blob/0c03de4a3d82a5f02f455ccc8174cb0dc9c2a532/cgroup2/manager.go#L565-L575

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

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 commented 3 weeks ago

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