Skip to content

Conversation

@justxuewei
Copy link
Member

@justxuewei justxuewei commented Jul 2, 2025

The first commit only moves code under src to src/fs (fs module),
and corrects the use path for tests. Apart from that, there are no other
changes.

The second commit introduces Manager trait and its implementation
FsManager. The Manager's set() takes OCI LinuxResources, so that
runtimes don't need to do any conversions. It is easy to use for OCI
containers. The FsManager leverages the ability of fs mod to manage
cgroups via cgroupfs.

The third commit introduces systemd module, which manages cgroups through
systemd. 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 is
similar to FsManager, but it manages cgroups through systemd.

The fifth commit adds unit test cases for SystemdClient and methods from
systemd::utils module.

The sixth commit adds unit test cases for FsManager, SystemdManager,
and some of utility methods.

Signed-off-by: Xuewei Niu [email protected]

@justxuewei justxuewei changed the title Introduce manager to deal with OCI linux resource WIP: Introduce manager to deal with OCI linux resource Jul 2, 2025
@justxuewei justxuewei force-pushed the manager branch 7 times, most recently from 0d5b5a9 to b210398 Compare July 8, 2025 02:44
@justxuewei justxuewei changed the title WIP: Introduce manager to deal with OCI linux resource WIP: Introduce FsManager and SystemdManager Jul 8, 2025
@justxuewei justxuewei force-pushed the manager branch 15 times, most recently from 52dac8e to 09579b5 Compare July 11, 2025 08:44
@justxuewei justxuewei changed the title WIP: Introduce FsManager and SystemdManager Introduce FsManager and SystemdManager Jul 11, 2025
@justxuewei justxuewei force-pushed the manager branch 10 times, most recently from 66a8ef0 to cd1fe8b Compare July 18, 2025 07:16
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]>
Copy link

@Champ-Goblem Champ-Goblem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lifupan lifupan merged commit fefbdc8 into main Jul 22, 2025
7 checks passed
@Tim-Zhang Tim-Zhang deleted the manager branch July 22, 2025 10:09
Tim-Zhang added a commit to Tim-Zhang/cgroups-rs that referenced this pull request Jul 22, 2025
@Tim-Zhang Tim-Zhang mentioned this pull request Jul 22, 2025
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