Skip to content

Commit 0ef325d

Browse files
committed
doc: improve cgroups documentation
- Grammar - Clarity - Examples Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 2c94f4e commit 0ef325d

1 file changed

Lines changed: 61 additions & 15 deletions

File tree

doc/config/cgroups.md

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
There are three major cgroup configuration directives:
1+
Finit provides three different cgroup directives for controlling resource allocation:
22

3-
1. Global top-level group: `init`, `system`, `user`, or a custom group
4-
2. Selecting a top-level group for a set of run/task/services
5-
3. Per run/task/service limits
3+
1. **Top-level cgroup definition**: `cgroup NAME settings`
4+
- Defines a top-level cgroup (e.g., `init`, `system`, `user`) with default settings
5+
- Space-separated syntax
6+
- Example: `cgroup system cpu.weight:9700`
7+
8+
2. **Global cgroup selector**: `cgroup.NAME[,options]` (standalone directive)
9+
- Sets the default cgroup for subsequent services in a `.conf` file
10+
- Dot-separated with optional comma-separated options
11+
- Example: `cgroup.maint` or `cgroup.system,delegate`
12+
13+
3. **Per-service cgroup option**: `cgroup.NAME[,options]` or `cgroup:options`
14+
- Overrides the cgroup for a specific service
15+
- Part of the service directive line
16+
- Example: `service [...] cgroup.maint,mem.max:1G /path/to/cmd`
617

718
> [!NOTE]
819
> Linux cgroups and details surrounding values are not explained in the
9-
> Finit documentation. The Linux admin-guide cover this well:
20+
> Finit documentation. The Linux admin-guide covers this well:
1021
> <https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html>
1122
12-
Top-level Group Configuration
13-
-----------------------------
23+
Top-level Cgroup Definition
24+
----------------------------
25+
26+
**Syntax:** `cgroup NAME settings`
1427

1528
# Top-level cgroups and their default settings. All groups mandatory
1629
# but more can be added, max 8 groups in total currently. The cgroup
@@ -34,22 +47,37 @@ By default, the `system/` cgroup is selected for almost everything. The
3447
`init/` cgroup is reserved for PID 1 itself and its closest relatives.
3548
The `user/` cgroup is for local TTY logins spawned by getty.
3649

37-
Selecting Cgroups
38-
------------------
50+
Global Cgroup Selector
51+
----------------------
52+
53+
**Syntax:** `cgroup.NAME[,options]` (standalone directive)
3954

40-
To select a different top-level cgroup, e.g. `maint/`, one can either
41-
define it for a group of run/task/service directives in a `.conf` or per
42-
each stanza:
55+
To select a different top-level cgroup, e.g. `maint/`, for a group of
56+
run/task/service directives in a `.conf` file, use the `cgroup.NAME`
57+
directive as a standalone line:
4358

4459
cgroup.maint
4560
service [...] <...> /path/to/foo args -- description
4661
service [...] <...> /path/to/bar args -- description
4762

48-
or
63+
Both services will run in the `maint/` cgroup.
64+
65+
You can also include options with the global selector:
66+
67+
cgroup.system,delegate
68+
service [...] <...> /path/to/foo args -- description
69+
70+
Per-Service Cgroup Option
71+
--------------------------
72+
73+
**Syntax:** `cgroup.NAME[,options]` or `cgroup:options` (service option)
74+
75+
To override the cgroup for a specific service, use the `cgroup.NAME`
76+
option within the service directive:
4977

5078
service [...] <...> cgroup.maint /path/to/foo args -- description
5179

52-
The latter form also allows per-stanza limits. Two syntaxes are supported:
80+
This form also allows per-service limits. Two syntaxes are supported:
5381

5482
**New comma-separated syntax (recommended):**
5583

@@ -59,6 +87,11 @@ The latter form also allows per-stanza limits. Two syntaxes are supported:
5987

6088
service [...] <...> cgroup.maint:cpu.max:10000,mem.max:655360 /path/to/foo args -- description
6189

90+
You can also apply options to the current default cgroup (without changing it)
91+
using the `cgroup:options` syntax:
92+
93+
service [...] <...> cgroup:cpu.max:10000,mem.max:655360 /path/to/foo args -- description
94+
6295
Both syntaxes work identically. The new comma-separated syntax is recommended
6396
as it's more consistent with other option parsing in Finit.
6497

@@ -92,7 +125,7 @@ Or with delegation:
92125
cgroup.containers,name:podman,delegate,mem.max:4G \
93126
/usr/bin/podman system service -- Podman API
94127

95-
A daemon using `SCHED_RR` currently need to run outside the default cgroups.
128+
A daemon using `SCHED_RR` currently needs to run outside the default cgroups.
96129

97130
service [...] <...> cgroup.root /path/to/daemon arg -- Real-Time process
98131

@@ -143,6 +176,19 @@ When delegation is enabled, Finit:
143176

144177
Both examples delegate the cgroup while also setting a 4GB memory limit.
145178

179+
**Container template example:**
180+
181+
Here's a real-world example from [Infix OS](https://github.com/kernelkit/infix)
182+
for running rootful podman container instances using delegation:
183+
184+
sysv log:prio:local1,tag:%i kill:30 pid:!/run/container:%i.pid \
185+
pre:0,/usr/sbin/container cleanup:0,/usr/sbin/container \
186+
cgroup.system,delegate \
187+
[2345] <!> :%i container -n %i -- container %i
188+
189+
This template uses `sysv` type with delegation, demonstrating that cgroup
190+
delegation works with different service types, not just `service`.
191+
146192
**Cgroup structure with delegation:**
147193

148194
Initially, the service process runs directly in the cgroup root:

0 commit comments

Comments
 (0)