Skip to content

Support cgroup v2 CPU stats when controller not enabled #347

Open
@jay-mckay

Description

@jay-mckay

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions