forked from levex/cgroups-rs
-
Notifications
You must be signed in to change notification settings - Fork 57
Introduce FsManager and SystemdManager #148
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0d5b5a9 to
b210398
Compare
52dac8e to
09579b5
Compare
66a8ef0 to
cd1fe8b
Compare
Prepare to implement FsManager, which should be done in the following-up commits. Apart from that, no code is not modified. Signed-off-by: Xuewei Niu <[email protected]>
`Manager` is a trait to unify the interface of cgroups. It is designed for OCI containers. Its `set()` takes Linux resources of the OCI spec to set cgroups. The `FsManager`, the concrete implementation of `Manager`, manipulates cgroups through cgroupfs, and supports both cgroups v1 and v2. Signed-off-by: Xuewei Niu <[email protected]>
`SystemdCgroup` takes a `parent`, which is the name of a slice, and a `unit`, which is the name of a slice or a scope unit, and provides methods to start, kill the unit, as well as set properties for the unit. The mods, `cpu`, `memory`, `cpuset`, and `pids`, are designed to generate properties quickly. It hides the difference between cgroups v1 and v2, and does simple checks for the systemd version and arguments. Signed-off-by: Xuewei Niu <[email protected]>
Systemd manager takes cgroups path in the format of "parent:scope_prefix:name" to create and manipulate cgroups through systemd. It does value conversions for resources defined in the Linux resources from the OCI spec, such as CPU quota, period, etc. Signed-off-by: Xuewei Niu <[email protected]>
The tests cover `SystemdClient` and methods from `utils` mods. Please note that the `SystemdClient` tests do not run well in parallel, but work well in sequence. Please run them with `--test-threads=1`. Signed-off-by: Xuewei Niu <[email protected]>
The tests cover the methods of `conv` mod, `FsManager`, and `SystemdManager`. Since we have to manipulate the cgroups during testing, the tests related to this part are set to be run in sequence. Signed-off-by: Xuewei Niu <[email protected]>
Champ-Goblem
approved these changes
Jul 21, 2025
Champ-Goblem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
lifupan
approved these changes
Jul 22, 2025
Tim-Zhang
added a commit
to Tim-Zhang/cgroups-rs
that referenced
this pull request
Jul 22, 2025
Changelog: - kata-containers#148 - kata-containers#149 Signed-off-by: Tim Zhang <[email protected]>
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first commit only moves code under
srctosrc/fs(fsmodule),and corrects the
usepath for tests. Apart from that, there are no otherchanges.
The second commit introduces
Managertrait and its implementationFsManager. TheManager'sset()takes OCILinuxResources, so thatruntimes don't need to do any conversions. It is easy to use for OCI
containers. The
FsManagerleverages the ability offsmod to managecgroups via cgroupfs.
The third commit introduces
systemdmodule, which manages cgroups throughsystemd. It communicates with systemd via D-Bus, and provides a set of
methods to start/kill a unit, set cgroup resources, and so on. Plus, it
encapsulates some methods to help generate systemd cgroup properties. The
subsystems supported by systemd cgroups cover cpu, cpuset, memory and pids.
The fourth commit introduces
SystemdManager. As the name implied, it issimilar to
FsManager, but it manages cgroups through systemd.The fifth commit adds unit test cases for
SystemdClientand methods fromsystemd::utilsmodule.The sixth commit adds unit test cases for
FsManager,SystemdManager,and some of utility methods.
Signed-off-by: Xuewei Niu [email protected]