From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 88AAAB93D; Fri, 31 Jul 2026 22:00:31 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 17EEFB875; Fri, 31 Jul 2026 22:00:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DMARC_PASS,FREEMAIL_FROM,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by atuin.qyliss.net (Postfix) with ESMTPS id 64B05B873 for ; Fri, 31 Jul 2026 22:00:26 +0000 (UTC) Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-81ec29f1d07so20482837b3.1 for ; Fri, 31 Jul 2026 15:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785535225; x=1786140025; darn=spectrum-os.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1i0TnrC9Tre3gAVJpXmL04WNEhtmqCO0yt1n8M1dxcA=; b=YdDXwHW9JMf9bUu0le9tVBtffjJrEJc13t75pN4cH0MeIhp2J5OYJwfWYcDV09zL0z kDewmC4gLMoibkzWRwEITku8mQ+Bxjqerh7X5nUpk8D/RbhR42h06HOZwU+gUP3r7mld fjUCSxMIOfnjfllmQafoXikeDCuPlJrLhugY0ExRiz6JQhLZseqIaS53BcWMV8dNFehJ /jH8/qX7lhqeabqRzt5thHk75bcFAGWsk3d6Cg2AJ2S6goRzSm9COuoLeq+0sJ0f/AjG R/WC2/R0eiJTOHGQRgwhoAM4BCiKZ4Mqtr3r9OkpdIoYCmP/iN0U8bmhHyaaLVW1+ZNC wLbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785535225; x=1786140025; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1i0TnrC9Tre3gAVJpXmL04WNEhtmqCO0yt1n8M1dxcA=; b=KH76CpMAqRxXpwga+t9vRM3Viv//XpLJYwrT6nkJzT4Lzh0UFWBQPJDBBRQ3xIvZdi A5ltSD3rbCF1XtkkIduUZJNJNFPwpsDs3/7Py04p/nxt/lEZw42KSVj8j/DRyk8iNL5G o64BFhnqMjGYbwxhCjdK+h0mpxhgFGr2346wcrnfGZocsuQdIhXiT0c60tBuVdMkY5MD rrDyiqaJLu+wm8gf35W9UGg/OUNSur2YmxG5Y+fFUu2nc0YavR6WxyIB8aQlTnNx9n9M rvGSWmLBV5wuQYyctS8azcXF0GRZMv2BlnnJP0RjA1LDeEftp3M2Wb2uEoEjI6EOgHfn 899Q== X-Gm-Message-State: AOJu0YysPrYAXERM90zvAVhRme1gN/1tEKdlQr3b1zWJgEhXpdD9ul4X b1exRfu6C4GZyXi4EZgGzf0v2h3evRLAwytnz7FTPo6iA8UC10rgmo8RIAH05w== X-Gm-Gg: AR+sD13F91OmlRVtqM/X1XSXdMneMVhTBXhpiYTF8OE4E2ybWEj20bRN/+6q5xxCkFA MgKsdZNFRtdSI5betMCNd6eJTsZvJRs+nxSr00t4ow1fM1TzDRDhuRWvOTg9n0VEnw4szzeqEeV 5Bh07FMcqF0R8nKeUkVJZDdKBw+ZM6utnnPG3gT71F8Iakb1W3Ix2JUKoIHLKFXgOWk/3hoWjOk iDoK/QdS/e/yoHzkYn/7gmw8UYUwWNA38OF0c1+M87836OI3qBHE16LVeU5QdnWIinHtgYNmwSa PB7MUtgbrFCq4ONErCHJ6tfk0LCoy0FW0BUjfF5BPDoJxVGhV7dXqBtqStLZB7GOvdTmRx+Imh4 kx5Fc23NTxawh+/A7zhlqMyeHVFGWI5czuJpcKG9mixCWNtfd6IXRIiOUzI9pflk5zeaY6cwG1u G8hUd89pceZd7Dl9EZayYdvdzx37fbNMWlYifLgnGCyCrYrj7i4pmbVBujAvWwoRuP/gIcgdhRB aEGlQjc5PH6 X-Received: by 2002:a05:690c:680d:b0:81f:c307:ff77 with SMTP id 00721157ae682-81fd4b9dbbbmr20657367b3.25.1785535224684; Fri, 31 Jul 2026 15:00:24 -0700 (PDT) Received: from localhost.localdomain ([185.98.168.14]) by smtp.gmail.com with UTF8SMTPSA id 00721157ae682-81fcd0d70besm14243507b3.31.2026.07.31.15.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 15:00:24 -0700 (PDT) From: Demi Marie Obenour Date: Fri, 31 Jul 2026 17:54:43 -0400 Subject: [PATCH v5 03/19] Documentation: Mention control groups MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260731-cgroups-v5-3-b325bac9d34f@gmail.com> References: <20260731-cgroups-v5-0-b325bac9d34f@gmail.com> In-Reply-To: <20260731-cgroups-v5-0-b325bac9d34f@gmail.com> To: Spectrum OS Development X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1785534880; l=4309; i=demiobenour@gmail.com; s=20250729; h=from:subject:message-id; bh=xtuZ1dBmkcGpNSTQfJw2nZLopgUr8H8bswbBNNvVUKs=; b=LuQU6KRPcozwLpg4c+A75KT+2DMu6h8iHdFaJqNAUDyrnGNAg7mXDNop2eNBNbshcNJd9COGq AbpA1ABgBH2B4tQTAMgFW674BnRa5IuHNePgYPQ2mdzhCK9Mh5hdSmr X-Developer-Key: i=demiobenour@gmail.com; a=ed25519; pk=X57Q4/YQDj9t4SBeKaDwvXYKB6quZJVx/DE2Ly2out0= Message-ID-Hash: 356E2CDSJGO3AFA6KHPVKP6PMXQJLO5N X-Message-ID-Hash: 356E2CDSJGO3AFA6KHPVKP6PMXQJLO5N X-MailFrom: demiobenour@gmail.com X-Mailman-Rule-Hits: member-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.spectrum-os.org-0; header-match-devel.spectrum-os.org-1; header-match-devel.spectrum-os.org-2; header-match-devel.spectrum-os.org-3; header-match-devel.spectrum-os.org-4; emergency CC: Demi Marie Obenour , Alyssa Ross X-Mailman-Version: 3.3.10 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Demi Marie Obenour --- Documentation/doc/development/control-groups.adoc | 95 +++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/Documentation/doc/development/control-groups.adoc b/Documentation/doc/development/control-groups.adoc new file mode 100644 index 0000000000000000000000000000000000000000..50bbdcbd79125fcacd229ce41f6337f3fcaa4190 --- /dev/null +++ b/Documentation/doc/development/control-groups.adoc @@ -0,0 +1,95 @@ += Control groups in Spectrum + +// SPDX-FileCopyrightText: 2026 Demi Marie Obenour +// SPDX-License-Identifier: GFDL-1.3-no-invariants-or-later OR CC-BY-SA-4.0 + +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. + +Spectrum currently uses the first two. The third is not yet used, +but will be in the future. + +== Control Group Hierarchy + +Spectrum uses the following cgroup hierarchy: + +1. There is a `+/vm-services.slice+` cgroup that contains all the per-VM + services on the system. +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 virtual machine monitor (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 +https://skarnet.org/software/s6/s6-svscan.html[`s6-svscan`] or +https://skarnet.org/software/s6/s6-supervise.html[`s6-supervise`]. + +== Using Control Groups + +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 do almost nothing. + +=== Setting Up Control Groups + +Generally, it's best to set the control group up as the first thing +the service does using Spectrum's https://spectrum-os.org/git/spectrum/tree/tools/cgroup-setup[`cgroup-setup`] tool. +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. + +If the control group starts with `/`, it is interpreted as a path relative +to `/sys/fs/cgroup`. Otherwise, it is relative to the current control +group the program is in. + +For example, using https://skarnet.org/software/execline/[execline] for your run script: + +[source,execline] +.... +#!/bin/execlineb -WS1 + +# Often, your cgroup is just the parent cgroup +# with the name of the service ($1) appended. +cgroup-setup --leaf -- $1 +# The rest of the script goes here. +.... + +=== Purging Control Groups + +If the service exits, it's usually best to terminate any programs left +behind with `SIGKILL` and remove the control group. To do this, +make the `finish` script invoke `cgroup-purge`. Its sole command-line +argument is the cgroup to remove. + +[source,execline] +.... +#!/bin/execlineb -WS3 + +# Use the same path you used in the run script. +cgroup-purge $3 +# The rest of the script goes here. +.... + +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. + +== 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. + +Instead, the plan is to have a database containing this information. +Whether this will be in the `data/` subdirectory of the service directory +or a separate system-wide database has not yet been determined. -- 2.55.0