patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Valentin Gagarin <valentin@gagarin.work>
To: Demi Marie Obenour <demiobenour@gmail.com>
Cc: Spectrum OS Development <devel@spectrum-os.org>,
	Alyssa Ross <hi@alyssa.is>
Subject: Re: [PATCH v4 03/20] Documentation: Mention control groups
Date: Tue, 28 Jul 2026 12:41:02 +0200	[thread overview]
Message-ID: <178523526292.177091.4277895723800005859.b4-review@b4> (raw)
In-Reply-To: <20260721-cgroups-v4-3-46b2e5fff7b6@gmail.com>

On Tue, 21 Jul 2026 21:59:08 -0400, Demi Marie Obenour <demiobenour@gmail.com> wrote:
> diff --git a/Documentation/doc/development/control-groups.adoc b/Documentation/doc/development/control-groups.adoc
> new file mode 100644
> index 0000000..6ce33f2
> --- /dev/null
> +++ b/Documentation/doc/development/control-groups.adoc
> @@ -0,0 +1,88 @@
> += Control groups in Spectrum
> +
> +// SPDX-FileCopyrightText: 2026 Demi Marie Obenour <demiobenour@gmail.com>
> +// SPDX-License-Identifier: GFDL-1.3-no-invariants-or-later OR CC-BY-SA-4.0
> +
> +Linux control groups (cgroups) can be used for several purposes:
> +
> +1. They allow waiting for a group of processes to exit.
> +2. They allow terminating a group of processes.
> +3. They allow limiting a group of processes' access to resources.

Not repeating prefixes helps readability.  And a link to upstream
documentation is always good.

    https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html[Linux control groups] (cgroups) can be used for several purposes:
    
    1. Waiting for a group of processes to exit.
    2. Terminating a group of processes.
    3. Limiting a group of processes' access to resources.

> [ ... skip 10 lines ... ]
> +2. The per-VM services for each VM are under `/vm-services.slice/vm-${VM}.slice`,
> +   where `${VM}` is replaced by the VM's ID.
> +3. Each per-VM service is under `/vm-services.slice/vm-${VM}.slice/${SERVICE_NAME}`,
> +   where `${VM}` is replaced by the VM's ID and `${SERVICE_NAME}` is replaced by
> +   the name of the service.
> +4. The VMM runs under `/vm-services.slice/vm-${VM}.slice/vmm`.

I don't think we introduce VMM anywhere else in the documentation, so
let's write it out.

    4. The virtual machine manager (VMM) runs under `/vm-services.slice/vm-${VM}.slice/vmm`.

> +
> +If a cgroup contains child cgroups, it likely contains a `$inner.service`
> +cgroup.  This is where programs that would otherwise run in the cgroup itself
> +are placed.  Generally, these programs are instances of `s6-svscan` and/or
> +`s6-supervise`.

Since we're not discussing s6 anywhere, please link to what these things
mean.  Also I think it's fine to imply logical OR when using "or" with
our audience, and reduce the visual noise (the general recommendation is
to avoid slashes in prose).

    are placed.  Generally, these programs are instances of
    https://skarnet.org/software/s6/s6-svscan.html[`s6-svscan`] or
    https://skarnet.org/software/s6/s6-supervise.html[`s6-supervise`].

> +
> +== Using Control Groups
> +
> +When adding a new s6 service, one should carefully consider whether it
> +should be placed in a control group.  Most services should be placed in
> +a control group, with only a few exceptions:

The first sentence reads as if one now has to make serious decisions,
but the second one amounts to "mostly no".  This was confusing to read,
and took attention away from the relevant parts, which seem to revolve
around "how to do that".  I recommend removing the first sentence.

    Most services should be placed in
    a control group, with only a few exceptions:

> +
> +1. Services, such as `getty`, that spawn background processes.
> +2. Loggers.
> +3. Trivial services that don't do anything.
> +
> +Generally, it's best to set the control group up as the first thing
> +the service does.  To do that, use `cgroup-setup --leaf -- $1 COMMAND_LINE`,
> +where `$1` should be the service name and `COMMAND_LINE` is the program
> +to run in a cgroup.

It took me a while to figure out that this is a new tool that comes
with Spectrum.  Not sure how to handle that best, but here's an attempt:

    Generally, it's best to set the control group up as the first thing
    the service does, with Spectrum's https://spectrum-os.org/git/spectrum/tree/tools/cgroup-setup[`cgroup-setup`].

    Call `cgroup-setup --leaf -- $1 COMMAND_LINE`,
    where `$1` should be the service name and `COMMAND_LINE` is the program
    to run in a cgroup.

> +
> +If you use execline for your run script, this is as simple as:

For example, using https://skarnet.org/software/execline/[execline] for your run script:

> +
> +.run
> +....

But I'd prefer "manually" to make that unambiguous.

> +#!/bin/execlineb -WS1

That renders as a separate paragraph only containing "run".  Let's
remove that, it doesn't make sense visuallyr

> +
> +cgroup-setup --leaf -- $1
> +# rest of script comes here
> +....
> +
> +If the service exits, it's usually best to terminate any programs left
> +behind with SIGKILL and remove the control group.  In Spectrum, this is

To keep the convention of displaying code items in monospace.  Also
shouldn't it be "when a service exits", since it's usually a matter of
time and holds for any service?

    When a service exits, it's usually best to terminate any programs left
    behind with `SIGKILL` and remove the control group.  In Spectrum, this is

This new (sub-)section could use a heading, such as "Purging control
groups".  A separate section also removes the implication that we're
still talking about "the" same service as before.

> +called "purging" the cgroup.  To purge the cgroup when a service exits,
> +make the `finish` script invoke `/usr/bin/cgroup-s6-finish`.  The first
> +two command line arguments must be the first two arguments passed to the
> +`finish` script.  The third argument must be the path to the cgroup to

To purge the cgroup when a service exits,
    make the `finish` script in the https://skarnet.org/software/s6/servicedir.html[s6 service directory]
    invoke Spectrum's `/usr/bin/cgroup-s6-finish`.

This also needs an example.  It took me a couple of times to visualise
that it's just `cgroup-s6-finish $1 $2 $3`.

And is it necessary to say `/usr/bin/...`?  Ideally we'd already
indicate here that `cgroup-s6-finish` is a symlink to `cgroup-setup`.

> +be purged relative to the cgroup the program itself is in.  This is
> +usually, but not always, the third argument to the `finish` script.

This needs more information.  When is it the third argument, when is it
not?  I'd be helpless at this point.

> +
> +When invoked as `cgroup-s6-finish`, `cgroup-setup` checks if
> +the service exited due to a signal that caused it to dump core.  If it
> +did, `cgroup-s6-finish` exits with status 125, ensuring that
> +`s6-supervise` will *not* restart it.  This is intentional: if a service

+crashes due to a fatal signal, this is possibly a sign of memory

> +crashes due to a fatal signal, this is possibly a sign of memory
> +corruption.  Restarting the service in this case can turn an unreliable

This should probably go into reference documentation for that program,
but let's keep it here until we have a place to list it and a way to do
that automatically.

> +memory corruption exploit into a reliable one.  Rust panics do not cause
> +core dumps, so the service will be restarted afterwards.

I don't understand what that last sentence means for me as a user.  This
seems detached from the previous explanations.

> +
> +One can also use `cgroup-purge` to purge a cgroup explicitly.  This is
> +used to stop the VMM and all per-VM services when a VM is shut down.

Do you mean that command is intended to be used manually?  I'm not sure
here, because "explicitly" doesn't intuitively convey that to me.  If
you want to keep the terminology, an example with a bit of introduction
would help, such as:

> +
> +== Future plans
> +
> +Control groups are designed around a single writer process controlling each
> +of them.  Many Linux distros use systemd for this, but Spectrum doesn't use
> +systemd.  The only persistent per-service process is s6-supervise, but that
> +doesn't have control group support.

s/distros/distributions/ and maybe highlight command names with
monospace.

    Control groups are designed around a single writer process controlling each
    of them.  Many Linux distributions use `systemd` for this, but Spectrum doesn't use
    `systemd`.  The only persistent per-service process is `s6-supervise`, but that
    doesn't have control group support.


Generally I strongly recommend one sentence per line for documentation,
a recommendation that apparently goes back to early Unix[1].  That makes
review a lot easier.  As you can observe, otherwise one has to cut
random unrelated pieces from the diff to discuss one word or phrase from
a sentence.  We don't have to introduce it now, but should start this as
a convention.

[1]: https://rhodesmill.org/brandon/2012/one-sentence-per-line/

Reviewed-by: Valentin Gagarin <valentin@gagarin.work>

-- 
Valentin Gagarin <valentin@gagarin.work>

  parent reply	other threads:[~2026-07-28 10:41 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-20 14:23 [PATCH] Set up control groups for most services Demi Marie Obenour
2026-06-20 17:27 ` [PATCH v2] " Demi Marie Obenour
2026-06-24 12:13   ` Alyssa Ross
2026-06-24 12:36     ` Alyssa Ross
2026-06-25  2:03     ` Demi Marie Obenour
2026-06-25  3:03       ` Demi Marie Obenour
2026-06-25  9:55         ` Alyssa Ross
2026-06-25  9:49       ` Alyssa Ross
2026-07-11 20:12   ` [PATCH v3 00/22] Control group support Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 01/22] host/rootfs: Mount filesystems before s6-rc-init Demi Marie Obenour
2026-07-13  9:39       ` Alyssa Ross
2026-07-13 17:27         ` Demi Marie Obenour
2026-07-15 18:28           ` Alyssa Ross
2026-07-22  1:59       ` [PATCH v4 00/20] Control group support Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 01/20] host/rootfs: Mount filesystems before s6-rc-init Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 02/20] tools: Add control group manager Demi Marie Obenour
2026-07-22 16:01           ` Alyssa Ross
2026-07-23 23:07             ` Demi Marie Obenour
2026-07-27 12:10               ` Alyssa Ross
2026-07-30  0:40                 ` Demi Marie Obenour
2026-07-30 14:53                   ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 03/20] Documentation: Mention control groups Demi Marie Obenour
2026-07-27 11:22           ` Alyssa Ross
2026-07-28 10:41           ` Valentin Gagarin [this message]
2026-07-22  1:59         ` [PATCH v4 04/20] Mount cgroup2 filesystem at /sys/fs/cgroup Demi Marie Obenour
2026-07-27 11:23           ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 05/20] host/rootfs: Add helper program for per-VM services Demi Marie Obenour
2026-07-27 11:27           ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 06/20] host/rootfs: Enable controllers in sub-cgroups Demi Marie Obenour
2026-07-27 12:11           ` Alyssa Ross
2026-07-28  2:19             ` Demi Marie Obenour
2026-07-29 14:13               ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 07/20] host/rootfs: Add comments where cgroups are intentionally not used Demi Marie Obenour
2026-07-27 12:12           ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 08/20] host/rootfs: serial-getty-generator: Use cgroups Demi Marie Obenour
2026-07-27 12:14           ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 09/20] host/rootfs: Set up parent cgroup for all per-VM services Demi Marie Obenour
2026-07-27 12:16           ` Alyssa Ross
2026-07-28  3:01             ` Demi Marie Obenour
2026-07-29 14:29               ` Alyssa Ross
2026-07-29 20:20                 ` Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 10/20] host/rootfs: Create per-VM cgroup for all of the VM's services Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 11/20] host/rootfs: run-vmm: Create per-VM cgroup Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 12/20] host/rootfs: run-appimage: Purge the " Demi Marie Obenour
2026-07-27 12:18           ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 13/20] host/rootfs: run-flatpak: " Demi Marie Obenour
2026-07-27 12:19           ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 14/20] host/rootfs: dbus: Run in cgroup Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 15/20] host/rootfs: vhost-user-fs: " Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 16/20] host/rootfs: vhost-user-gpu: " Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 17/20] host/rootfs: xdg-desktop-portal-spectrum-host: " Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 18/20] host/rootfs: systemd-udevd: " Demi Marie Obenour
2026-07-27 12:20           ` Alyssa Ross
2026-07-28  3:11             ` Demi Marie Obenour
2026-07-29 14:15               ` Alyssa Ross
2026-07-29 20:39                 ` Demi Marie Obenour
2026-07-30 14:55                   ` Alyssa Ross
2026-07-22  1:59         ` [PATCH v4 19/20] host/rootfs: weston: " Demi Marie Obenour
2026-07-27 12:23           ` Alyssa Ross
2026-07-28  3:14             ` Demi Marie Obenour
2026-07-22  1:59         ` [PATCH v4 20/20] host/rootfs: spectrum-router: " Demi Marie Obenour
2026-07-31 21:54         ` [PATCH v5 00/19] Control group support Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 01/19] host/rootfs: Mount filesystems before s6-rc-init Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 02/19] tools: Add control group manager Demi Marie Obenour
2026-08-03 12:47             ` Alyssa Ross
2026-08-05  1:36               ` Demi Marie Obenour
2026-08-05 16:39                 ` Alyssa Ross
2026-07-31 21:54           ` [PATCH v5 03/19] Documentation: Mention control groups Demi Marie Obenour
2026-08-03 13:22             ` Alyssa Ross
2026-07-31 21:54           ` [PATCH v5 04/19] Mount cgroup2 filesystem at /sys/fs/cgroup Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 05/19] host/rootfs: Enable controllers in non-root cgroups Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 06/19] host/rootfs: Add comments where cgroups are intentionally not used Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 07/19] host/rootfs: serial-getty-generator: Use cgroups Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 08/19] host/rootfs: systemd-udevd: Run in cgroup Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 09/19] host/rootfs: weston: " Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 10/19] host/rootfs: Set up parent cgroup for all per-VM services Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 11/19] host/rootfs: Create per-VM cgroup for all of the VM's services Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 12/19] host/rootfs: run-vmm: Create per-VM cgroup Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 13/19] host/rootfs: run-appimage: Purge the " Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 14/19] host/rootfs: run-flatpak: " Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 15/19] host/rootfs: dbus: Run in cgroup Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 16/19] host/rootfs: vhost-user-fs: " Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 17/19] host/rootfs: vhost-user-gpu: " Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 18/19] host/rootfs: xdg-desktop-portal-spectrum-host: " Demi Marie Obenour
2026-07-31 21:54           ` [PATCH v5 19/19] host/rootfs: spectrum-router: " Demi Marie Obenour
2026-08-06  1:16           ` [PATCH v6 00/19] Control group support Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 01/19] host/rootfs: Mount filesystems before s6-rc-init Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 02/19] tools: Add control group manager Demi Marie Obenour
2026-08-06  6:58               ` Demi Marie Obenour
2026-08-12 21:10               ` Alyssa Ross
2026-08-06  1:16             ` [PATCH v6 03/19] Documentation: Mention control groups Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 04/19] Mount cgroup2 filesystem at /sys/fs/cgroup Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 05/19] host/rootfs: Enable controllers in non-root cgroups Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 06/19] host/rootfs: Add comments where cgroups are intentionally not used Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 07/19] host/rootfs: serial-getty-generator: Use cgroups Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 08/19] host/rootfs: systemd-udevd: Run in cgroup Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 09/19] host/rootfs: weston: " Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 10/19] host/rootfs: Set up parent cgroup for all per-VM services Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 11/19] host/rootfs: Create per-VM cgroup for all of the VM's services Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 12/19] host/rootfs: run-vmm: Create per-VM cgroup Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 13/19] host/rootfs: run-appimage: Purge the " Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 14/19] host/rootfs: run-flatpak: " Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 15/19] host/rootfs: dbus: Run in cgroup Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 16/19] host/rootfs: vhost-user-fs: " Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 17/19] host/rootfs: vhost-user-gpu: " Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 18/19] host/rootfs: xdg-desktop-portal-spectrum-host: " Demi Marie Obenour
2026-08-06  1:16             ` [PATCH v6 19/19] host/rootfs: spectrum-router: " Demi Marie Obenour
2026-08-12 21:06             ` [PATCH v6 00/19] Control group support Alyssa Ross
2026-07-11 20:12     ` [PATCH v3 02/22] scripts: Support symlinks in s6-rc-compile inputs Demi Marie Obenour
2026-07-13  9:42       ` Alyssa Ross
2026-07-13 14:19         ` Demi Marie Obenour
2026-07-15 18:30           ` Alyssa Ross
2026-07-11 20:12     ` [PATCH v3 03/22] tools: Add control group manager Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 04/22] Documentation: Mention control groups Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 05/22] Mount cgroup2 filesystem at /sys/fs/cgroup Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 06/22] host/rootfs: Add helper program for per-VM services Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 07/22] host/rootfs: Enable controllers in sub-cgroups Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 08/22] host/rootfs: Add comments where cgroups are intentionally not used Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 09/22] host/rootfs: serial-getty-generator: Use cgroups Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 10/22] host/rootfs: Set up parent cgroup for all per-VM services Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 11/22] host/rootfs: Create per-VM cgroup for all of the VM's services Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 12/22] host/rootfs: run-vmm: Create per-VM cgroup Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 13/22] host/rootfs: run-appimage: Purge the " Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 14/22] host/rootfs: run-flatpak: " Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 15/22] host/rootfs: dbus: Run in cgroup Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 16/22] host/rootfs: vhost-user-fs: " Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 17/22] host/rootfs: vhost-user-gpu: " Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 18/22] host/rootfs: xdg-desktop-portal-spectrum-host: " Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 19/22] host/rootfs: systemd-udevd: " Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 20/22] host/rootfs: weston: " Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 21/22] host/rootfs: spectrum-router: " Demi Marie Obenour
2026-07-11 20:12     ` [PATCH v3 22/22] host/rootfs: vm-import: Use elglob -w Demi Marie Obenour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=178523526292.177091.4277895723800005859.b4-review@b4 \
    --to=valentin@gagarin.work \
    --cc=demiobenour@gmail.com \
    --cc=devel@spectrum-os.org \
    --cc=hi@alyssa.is \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).