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 AC6D71B94; Sat, 11 Jul 2026 20:14:24 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 896051B37; Sat, 11 Jul 2026 20:14:22 +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-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by atuin.qyliss.net (Postfix) with ESMTPS id 946841B1D for ; Sat, 11 Jul 2026 20:14:20 +0000 (UTC) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-81062fdeaf5so46931187b3.0 for ; Sat, 11 Jul 2026 13:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783800859; x=1784405659; 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=8t6Y6YldC0nDuS84KmdWvjigs3s6vuwdLM9BLkidV4U=; b=P3Z6UDY+MSTpYjRhFrThXETntm9IyXmbtF97sVlE4AX/3iKpkTBHYuUgKGf2anqQMk Io3dAnKuvruzuiIOGgqUEyPx6jRthnV8sJxZfOCSXD6vlKigi1b6ARHNkpwKfqBte2Ri Tl3IlAVozjtQ516oVlsCU0YFOW2OpKFOlMq2zNTBopmdhSVYYzW5EOIk1nCi4e2d3kcg sBAZvp3Ni2ew2U45Hx5WWjvpLqAtNgRNtOsZ7DnKwUNuS/TVyG1Q5SASPQs4C6wToub7 v2zXWzC1OfNDbhy6x8GMA86p6SqJERHrGnppoMPScWJhWZWfmNJBnrBfHo2l+/b9KuB+ XAYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783800859; x=1784405659; 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=8t6Y6YldC0nDuS84KmdWvjigs3s6vuwdLM9BLkidV4U=; b=jgVO2dt904zhdkhPgVoFNS5sDY+JtDuelijpHmE0AJWz/dsxy7PMP0Quc1K6KtQ2z1 wucE96yCCHBsiM9YteZneZeB8+MEdum/xkbn/ECHIj725/rJDJ0UeQ+dSuJV13BrW5GO 0wttqBgc+L44TVbSPYps8i0jJP6KNSnJR4Aai0ab2cmJOQP1x8SEEMkVTmRfQmjAMKVy VZMqboVETqYSBcnu60qWO5w1YYmObIcgkv2++jXgvq+fn8koBaoGyRNnfx5Czm4MuzT9 ZDNf3Bx+PccSBXtk/TZNR+qf4PIkQCSsEjPYE6IltRCAO2dQgj0/HjgF2QgvBWd4adte WqeA== X-Gm-Message-State: AOJu0YyzDyWN/I4W8GffJWLvXc1PNQd0bFJ2FwBbBRFb0ZM16aLJbt3j luKTFZQN46+llkgx8AKvxd2PV8Q7vmKZdEwc6FSFw1TRwpzUIDXKXN7Cqa3zEg== X-Gm-Gg: AfdE7cleswY/HOg3TbabF6fMAIeJZye6HnwMLqVQHJSOvQcmlzX2rh3LKQreYXj1TNm KFzBBXKv+RdaeXyIU1wK5tZ6mA+1ChguW8i4V82sj/fa0J9VLr4RkVXxKX/CygJ3UTSb1kKvkkx EzmiA90PN4UnM8Lj9lIQI4493N6vh+U5M+r4e2VYA6Zdbq+d9XeO11TqYZswAQmr7jveWzj5qjy hyjioYoj2zEmzMTukPdfgqfB8J1J/hyhVjBpkIOPmAKT/EEisWBY2EN+kUy//QDqcLSbIIZEUfb 8OTIgoGS3N+0s3kmqhDHaQcLoNK0R0E03zbG1PDC1JkPL3kkfybymPik8fGJz8CIe/LIBVwF5NU wIdSMaq/o1LJnG/i6JVTtQHsrTj+TIQP3sW6uDdi0Un3GbeUQhN78Jssn5NK+cA8o5vIbgeqWUD 0cs73JSrY7SjFlDN2lzLmt4w4c+A== X-Received: by 2002:a05:690c:6306:b0:80c:ab39:b769 with SMTP id 00721157ae682-81e90835383mr26780487b3.21.1783800859237; Sat, 11 Jul 2026 13:14:19 -0700 (PDT) Received: from localhost.localdomain ([185.98.168.14]) by smtp.gmail.com with UTF8SMTPSA id 00721157ae682-81e7e575f7bsm49685807b3.45.2026.07.11.13.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 13:14:18 -0700 (PDT) From: Demi Marie Obenour Date: Sat, 11 Jul 2026 16:12:08 -0400 Subject: [PATCH v3 04/22] Documentation: Mention control groups MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260711-cgroups-v3-4-5cba61a20cba@gmail.com> References: <20260711-cgroups-v3-0-5cba61a20cba@gmail.com> In-Reply-To: <20260711-cgroups-v3-0-5cba61a20cba@gmail.com> To: Spectrum OS Development X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783800724; l=4039; i=demiobenour@gmail.com; s=20250729; h=from:subject:message-id; bh=PHuNoa+/0KRKB7Iol0LSQBt84/O1KRzHlratio8VzLw=; b=UTg3MeZlTVwstdsrpsBxPErtPUhMZ1zbSscGEclDyAJ1or/WpJR0/IA59dAyCiZZ9DN0wllT3 iH2y0vUo/CmBNk3lOu2sPVo58QO8rnrjaYXvO+DOUrq1863EEZcl6Jb X-Developer-Key: i=demiobenour@gmail.com; a=ed25519; pk=X57Q4/YQDj9t4SBeKaDwvXYKB6quZJVx/DE2Ly2out0= Message-ID-Hash: WPTIDGP64WIDZ3HDAGJIYJBJUKJO4365 X-Message-ID-Hash: WPTIDGP64WIDZ3HDAGJIYJBJUKJO4365 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 | 82 +++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/Documentation/doc/development/control-groups.adoc b/Documentation/doc/development/control-groups.adoc new file mode 100644 index 0000000000000000000000000000000000000000..9866761723ba8c77f9242d4ffdabaebad3f45aa4 --- /dev/null +++ b/Documentation/doc/development/control-groups.adoc @@ -0,0 +1,82 @@ += 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 + +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. + +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 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`. + +== 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: + +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. + +If you use execline for your run script, this is as simple as: + +.run +.... +#!/bin/execlineb -WS1 + +cgroup-setup --leaf -- $1 +# rest of script comes here +.... + +If the services exits, it's usually best to terminate any programs left +behind with SIGKILL and remove the control group. To do that, make +the `finish` script be a symbolic link to `/usr/bin/cgroup-setup`. +`cgroup-setup` recognizes when it has been invoked as `finish` and +purges the cgroup automatically. + +When invoked as `finish`, `cgroup-setup` checks if the service exited +due to a signal that caused it to dump core. If it did, `cgroup-setup` +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 corruption. Restarting the service in this +case can turn an unreliable memory corruption exploit into a reliable one. +Rust panics do not cause core dumps, so the service will be restarted +afterwards. + +== 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