Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4716058

Browse files
committedAug 6, 2021
config-linux: add systemd cgroup path convention
The systemd cgroup path convention currently implemented in runtimes like `runc/crun` should be added to the spec. This patch adds the systemd cgroup convention for `Linux.CgroupsPath` which is in the `slice:prefix:name` form and clarifies the detailed usage. Fixes #1021 Signed-off-by: Kailun Qin <kailun.qin@intel.com>
1 parent 8961758 commit 4716058

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎config-linux.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,31 @@ For more information, see the [kernel cgroups documentation][cgroup-v1].
176176
**`cgroupsPath`** (string, OPTIONAL) path to the cgroups.
177177
It can be used to either control the cgroups hierarchy for containers or to run a new process in an existing container.
178178

179-
The value of `cgroupsPath` MUST be either an absolute path or a relative path.
179+
If the runtime creates cgroups and sets cgroup limits on its own (aka. fs cgroup driver mode), the value of `cgroupsPath` MUST be either an absolute path or a relative path.
180180

181181
* In the case of an absolute path (starting with `/`), the runtime MUST take the path to be relative to the cgroups mount point.
182182
* In the case of a relative path (not starting with `/`), the runtime MAY interpret the path relative to a runtime-determined location in the cgroups hierarchy.
183183

184+
If the runtime use systemd cgroup driver to create cgroups and set cgroup limits, the value of `cgroupsPath` MUST be in the "slice:prefix:name" form (e.g. "system.slice:runtime:434234").
185+
By specifying with the transient systemd unit to create for the container and the containing slice which hosts the unit, the systemd units directly map to objects in the cgroup tree.
186+
When these units are activated, they map directly to cgroup paths built from the unit names.
187+
188+
This form specifies the following systemd cgroup properties:
189+
190+
* `slice` - name of the parent slice systemd unit, under which the container is placed.
191+
Note that `slice` can contain dashes to denote a sub-slice (e.g. `user-1000.slice` is a correct
192+
notation, meaning a subslice of `user.slice`), but it must not contain slashes (e.g.
193+
`user.slice/user-1000.slice` is invalid).
194+
There might be some slices already created by default, for example:
195+
`-.slice` - the root slice;
196+
`system.slice` - the default place for all system services;
197+
`user.slice` - the default place for all user sessions.
198+
* `prefix` - prefix of the scope systemd unit to create for the container.
199+
* `name` - name of the systemd unit to create.
200+
When `name` has `.slice` suffix, in which case `prefix` is ignored and the `name` is used as is,
201+
this describes a unit being created is a slice. Otherwise, `prefix` and `name` are used to
202+
compose the scope unit name, which is `<prefix>-<name>.scope`.
203+
184204
If the value is specified, the runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`.
185205
If the value is not specified, the runtime MAY define the default cgroups path.
186206
Runtimes MAY consider certain `cgroupsPath` values to be invalid, and MUST generate an error if this is the case.

‎specs-go/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ type Linux struct {
162162
// CgroupsPath specifies the path to cgroups that are created and/or joined by the container.
163163
// The path is expected to be relative to the cgroups mountpoint.
164164
// If resources are specified, the cgroups at CgroupsPath will be updated based on resources.
165+
// If systemd cgroup driver is used to create cgroups and set cgroup limits, the path must be
166+
// in the "slice:prefix:name" form (e.g. "system.slice:runtime:434234").
165167
CgroupsPath string `json:"cgroupsPath,omitempty"`
166168
// Namespaces contains the namespaces that are created and/or joined by the container
167169
Namespaces []LinuxNamespace `json:"namespaces,omitempty"`

0 commit comments

Comments
 (0)
Please sign in to comment.