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 C0439A352; Sun, 30 Aug 2026 06:45:14 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id AB7ECA2CF; Sun, 30 Aug 2026 06:45:11 +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,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 Received: from mail-yx1-xb130.google.com (mail-yx1-xb130.google.com [IPv6:2607:f8b0:4864:20::b130]) by atuin.qyliss.net (Postfix) with ESMTPS id E9E90A2CC for ; Sun, 30 Aug 2026 06:45:10 +0000 (UTC) Received: by mail-yx1-xb130.google.com with SMTP id 956f58d0204a3-66e611e7c05so446369d50.2 for ; Sat, 29 Aug 2026 23:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788072310; x=1788677110; 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=puj2jo3Ms5QK8K9z16sGtlP7ETK62GowVflQIdqahSQ=; b=ojF7zvCsFAmvDh1ectxxmNzLqkypnJKazUowdXegjN8KnWJWN5K0PnVUP87USb1Vpq S/zg6XYFl+h3NYwTYYYyP81V2k51vLs5ZQW8IzMLlAUg461egxFh3dnlMQWWMKGd7+ck beFflpH5WHM6twa9/uHx8yPEQNg6EvYkeQiUTbVeJbiseRE99utkaVjIInm/A0M5GwSa 0pIizaNglHUsQ/exDEru7gC3ltinWtZ9DYY8kP62ZY1PwIfNAhDzAGogiJDcteHhEIEy Ksf99Y3/U7o7MFweoM1cWkSfSdcenxpxIy+P9qmU/JyhzAABFumIt+N4JE5ltkNlb9xv HGog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788072310; x=1788677110; 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=puj2jo3Ms5QK8K9z16sGtlP7ETK62GowVflQIdqahSQ=; b=kmmr6bVOJLqa/cWTm3VRvwAehKYYSvUvPqKRhqCg+7YJrjnvXKTnCn8eI2As7bLtdY B+2Drz1e0FnwgaOMVIF46uxjcWClMoL07NHjIMlVwFlNHaRQ3zJUh+uhuJ2tUqVTXkQZ XzsEDFJha9uVYyjg1FtYnrq4R9vJwCKSiu10WDCZ4jryXhdakgNOX+Vhrpa2Weqpk0Ev aU0yxUTqeL3xUXhA1xTNJigm/h+YNmsJRzNBVxGmh3xiCld6n2ZtZKY19EY2sbKdZH/M bZtd0TAz/wZFMLfaVkD8RVPsKSz1CXts61QACcfSzXgYVzWqokNwtht3MVqAPYwh1NHn SScQ== X-Gm-Message-State: AFuF++l67bb+DAArkkupZozSZhPARvLXT+D+EAjcsSJhO6eeJUfHrSyP U8+oMZOOgex0VZKf09Fd8FAlRXEIb9JR0qZGS/YDNt2RHEGVuekHmkhpXBNVLQ== X-Gm-Gg: AYBFou2VPZMu5ROGe6HOue4fo8YCarpsbF8BruLaxtRqbP9q2DxAtqLbC510KA9qD7Q Wb902wxw3+CQzcvSJe7SQJS8qRA4XOSh4jnD1V587fJvqIsWyH3hXnvmG5GAfvR0keXNcd5XErl xg+nKmEE6u6EKBnwH1MFhjLjor+muFuH6Xmsr35YJPaw/SvRRzbWRfzTXfaQZWB9q98xDvh/DGk kf4gDoYAdbD8B7htybs/snjdG7yENej9qcjTeTZmFUWSXSmA6HT9n4aI6ub+waWXgGlanqmJ6t9 D/8npTtvZK7gJz5rSeT8NKjnz1rFBCKEzQUFrGBWh5ALyayy3Qpk6v7wTF4tcUamZh5NT68MzH2 Kt9cukWWt852CRd4DYLSb2fb0cqJimwUfuXuba7rUlrOy0eCH1e7adQbvTPV98cVHXHqCZykHT9 834n1j8V2Nc26Jh0tBPk4+7WTkdTH05yAPwZ05fU5ea6KQb5TsOrbK2lwIPeODjB0mgCqUrbnnr A== X-Received: by 2002:a05:690e:b89:b0:664:c3aa:66f0 with SMTP id 956f58d0204a3-66e4c564a4dmr5140005d50.39.1788072309696; Sat, 29 Aug 2026 23:45:09 -0700 (PDT) Received: from localhost.localdomain ([185.98.168.14]) by smtp.gmail.com with UTF8SMTPSA id 956f58d0204a3-66e4eb56b6dsm3618860d50.7.2026.08.29.23.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Aug 2026 23:45:08 -0700 (PDT) From: Demi Marie Obenour Date: Sun, 30 Aug 2026 02:06:37 -0400 Subject: [PATCH v8 03/18] Documentation: Mention control groups MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260830-cgroups-v8-3-239b09ba7013@gmail.com> References: <20260830-cgroups-v8-0-239b09ba7013@gmail.com> In-Reply-To: <20260830-cgroups-v8-0-239b09ba7013@gmail.com> To: Spectrum OS Development X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788069995; l=4816; i=demiobenour@gmail.com; s=20250729; h=from:subject:message-id; bh=hbUhH3t0XBoLIy/VRWbdyE3vbLU1nzfvPipq/qPbDd8=; b=2IODt73Wp4PLcVXo9i2h1T2AOrObN1eM77vU8+sGlfOOLNM0AysXxojqWh2qk7jTRrzL/3r1c 3pyV/768zC6D7Z+1+CY8oBDA1ksofOBoXSAH6qnK5cEc9KZfmbQnfKj X-Developer-Key: i=demiobenour@gmail.com; a=ed25519; pk=X57Q4/YQDj9t4SBeKaDwvXYKB6quZJVx/DE2Ly2out0= Message-ID-Hash: BR7C6GM5BGDCNJ7DDTFA2D46KVFFS4B7 X-Message-ID-Hash: BR7C6GM5BGDCNJ7DDTFA2D46KVFFS4B7 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 , Valentin Gagarin 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 --- Cc: Valentin Gagarin --- Documentation/doc/development/control-groups.adoc | 108 ++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/Documentation/doc/development/control-groups.adoc b/Documentation/doc/development/control-groups.adoc new file mode 100644 index 0000000000000000000000000000000000000000..93b8c823e1d1c5a3692faa51ad41d3291d3fb743 --- /dev/null +++ b/Documentation/doc/development/control-groups.adoc @@ -0,0 +1,108 @@ += 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 where cgroups are unnecessary. + +=== 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. + +The most common case is: + +1. The service runs in a cgroup that is a direct child of the parent + cgroup. + +2. If there is a program running in the cgroup, the cgroup manager + should wait for it to exit before spawning a new instance. + +In this case, use `+cgroup-setup -- $1 COMMAND_LINE+`, where `+$1+` +should be the service name and `+COMMAND_LINE+` is the program +to run in a cgroup. + +If you need to put the program in a different cgroup, you can use +a different name. 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. + +If you don't want to wait for existing programs in the cgroup to +exit, use `+--no-wait+`. This is rare. + +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 -- $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