Skip to content

Conversation

DanielShaulov
Copy link

The first commit adds cgroup v2 support for load_with_relative_paths - since get_cgroups_relative_paths already stores the path for the unified hierarchy in cgroup v2 under the empty "" key - we can look that key up in load_with_relative_paths and prepend it to the passed path for all subsystems and for the "path" field in the Cgroup struct itself.
Some other changes in load_with_relative_paths are:

  1. Accept relative_paths by reference so it can be reused without copying
  2. Accept an empty path - to create a cgroup that represents the "current" cgroup if used with the relative paths from get_cgroups_relative_paths

The second commit adds the ability to "create" a cgroupv2 hierarchy without enabling subtree_control. This is crucial, because in cgroupv2, due to the rule that processes can only appear in leafs, if you want to create a subdirectory of existing cgroup with a process in it you need the following order of operations:

  1. create the subfolder
  2. move all processes to the subfolder cgroup.procs
  3. enable subtree_control on the parent

So with the changes in this PR - the following code creates a directory "foo" under the existing cgroup, moves all processes from current cgroup into "foo" and then enables subtree_control on the parent.

If this is merged I will open another PR for Builder to expose this from builder as well.

let relative_paths = get_cgroups_relative_paths().unwrap();
let cg_parent =
    Cgroup::load_with_relative_paths(crate::hierarchies::auto(), "", &relative_paths);
let cg =
    Cgroup::load_with_relative_paths(crate::hierarchies::auto(), "foo", &relative_paths);

cg.create_disabled().unwrap();
for pid in cg_parent.procs() {
    cg.add_task_by_tgid(pid).unwrap();
}
cg.create().unwrap();

@DanielShaulov
Copy link
Author

@Tim-Zhang any chance for a review?

@fidencio fidencio closed this May 28, 2025
@fidencio fidencio reopened this May 28, 2025
@fidencio
Copy link
Member

@DanielShaulov, please, could you make sure we have the Clippy Check happy?

@DanielShaulov
Copy link
Author

@fidencio fixed - can you approve the workflow please?

@Tim-Zhang
Copy link
Member

@DanielShaulov sorry, I have't been paying attention to this repo recently. how about resolving the confit first?

@DanielShaulov
Copy link
Author

@Tim-Zhang - done, and make test and make clippy both pass for me

@justxuewei
Copy link
Member

@DanielShaulov Please rebase your code, we don't allow merge commits.

@DanielShaulov
Copy link
Author

@justxuewei done

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.

4 participants