Skip to content

cpuset effective_cpus/effective_mems use wrong file names for cgroup v2 #156

@jfernandez

Description

@jfernandez

Title: cpuset effective_cpus/effective_mems use wrong file names for cgroup v2

Description:

The cpuset controller is reading the wrong files for effective CPUs/mems on cgroup v2 systems.

In src/fs/cpuset.rs lines 282 and 288, the code reads:

  • cpuset.effective_cpus
  • cpuset.effective_mems

However, these file names changed between v1 and v2:

cgroup v1:

  • cpuset.effective_cpus
  • cpuset.effective_mems

cgroup v2:

  • cpuset.cpus.effective
  • cpuset.mems.effective

The current implementation always uses the v1 names even though the controller has a v2 flag. This causes cpuset().effective_cpus to return an empty vector on v2 systems since the file doesn't exist.

Reproduction:

On a system using cgroup v2:

let cg = Cgroup::load(Box::new(V2::new()), PathBuf::from("some/cgroup"));
let cpuset_ctrl: &CpuSetController = cg.controller_of().unwrap();
let cpuset = cpuset_ctrl.cpuset();
// cpuset.effective_cpus will be empty even if CPUs are assigned

Fix:

The cpuset() method should check self.v2 and use the appropriate file names:

effective_cpus: {
    let file = if self.v2 {
        "cpuset.cpus.effective"
    } else {
        "cpuset.effective_cpus"
    };
    self.open_path(file, false)
        .and_then(read_string_from)
        .and_then(parse_range)
        .unwrap_or_default()
},

References:

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