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 621299182; Thu, 06 Aug 2026 01:19:49 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 532C8910C; Thu, 06 Aug 2026 01:19:45 +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-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by atuin.qyliss.net (Postfix) with ESMTPS id 8BA6F9105 for ; Thu, 06 Aug 2026 01:19:44 +0000 (UTC) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-80e2cfe6918so18767297b3.0 for ; Wed, 05 Aug 2026 18:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785979183; x=1786583983; 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=3Hm9qwRJYH12KZicowX5ynclew1Z1yLRBMhssUNtvEI=; b=javygMZu0GUyoALMgw+E5oy8vgLb1AHsM8CMfx4a0k5eJULNj12Rn90PNOIT1P0TLJ wKjSivfFIV3S8toWnVBu6PNEoxzWpJTLIvfHovHiHxZW5BS7Pi3YZ/SUibTL27HMLwsf KfappN5agii13+0zgRxa1Yk8I1yf6brj7ozEMUSYt+J3v9nmr5ZHQfQjOHsuVPm+Z0Cu x9yySWjgiU0s1iAm9s6V33GQfkXnJwFIQXf5puk20dfOWT6nMf9kIC/Yh1e49zQ63LjP 6LqficV5XuT8NJCyx0FiBFbZjHI10PYlIqtMKS6W6/rw1eRhOq34sGDHpqs21hc6TVoR Xt2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785979183; x=1786583983; 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=3Hm9qwRJYH12KZicowX5ynclew1Z1yLRBMhssUNtvEI=; b=irVM8LbESBu5n30zQybuxqv2ZHIQ6FJN7U00v/vdHT2Atp8C+cnSVNesrxCZyRu1Cn elhrs6F41N0+DAj1JEcR2xv6pD/Jh15YV3HcFJaJtUFr3qF1m7OPXWvdLYbTmFQHGhNr yHbDxb2nFUNfqlZ2foXPhiOH03BTRfICK20gjusc0UOSKKR6SpSE/lEv7sXSahKvxO9B Hq4iKeopf14nLe06enwOU3aQBCdnkPqw5uOeDadPh4xeCVxUVn8DT5QAO0tRYAY8PFC2 dwkNogRDbNfWgxrSdRR6MS9m7QXmcqpaT5HoQ6UzSmWP7hNg3k3E2f78fBMHm7DIMySI PCmQ== X-Gm-Message-State: AOJu0Yz5cd179Jprs4vlY9kS49UdZOYP4gtpOpvHw+P2Pr5E2LR9fMPA IqSfdciy+D0MR8dpvvhrRm41TOJnZXSSPqmxdTGPyDcOyo/PIoTmj0hqtnuebQ== X-Gm-Gg: AR+sD12utw9VFJPqJsgGOcihIGJQp8RyOZuwvRqq8PK/ep++TabDHBbdRqZe4iGzzYk OM1cuRpxZA7nK5jtatSRUq7iTaqhW1akuG2pLaGbbI7S8jPoUtjsUSy3+WDGFp3V7D9p1AJoE7d 4OOuIOta2E6ZQLE/XQ18WF31G9H9sWUl+9eA0mwsyujw6SgYU+TFC7VOGc/Etxldb/Vp0pzxgyZ DkC2hvQTcJA/t53KKuDSqRaHnFrbEttb/uiMGCTkWis9ErBgXvVF8sY+a0lNyhbPzN/yJIiy5/+ nZDQTnPmXl7OyrckAeG2om+sOSqbjw3w17aKy8OXNuqvLXWeXH0JTzK0SZ8me6M+mSE7REMW6Hh 7S1rQbDU3TSwGMkrm8c528i+m0XKqOnVi7mbtnjKetCRa9dLCun3ErFw9N/rXWrve3/TvkTmRei FD4w3ErGo2pH8cFaHbsaBBdMVnRhjOd7R6kV9+TDJOrvwWijxAiG/O4bqv2Lr39fqDrLLVE06p5 A== X-Received: by 2002:a05:690c:6a0b:b0:81e:fe1c:2de8 with SMTP id 00721157ae682-8201bccfb48mr72488977b3.3.1785979183291; Wed, 05 Aug 2026 18:19:43 -0700 (PDT) Received: from localhost.localdomain ([185.98.168.14]) by smtp.gmail.com with UTF8SMTPSA id 00721157ae682-8201323eb78sm30088717b3.17.2026.08.05.18.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 18:19:42 -0700 (PDT) From: Demi Marie Obenour Date: Wed, 05 Aug 2026 21:16:10 -0400 Subject: [PATCH v6 03/19] Documentation: Mention control groups MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260805-cgroups-v6-3-086c0f00f55f@gmail.com> References: <20260805-cgroups-v6-0-086c0f00f55f@gmail.com> In-Reply-To: <20260805-cgroups-v6-0-086c0f00f55f@gmail.com> To: Spectrum OS Development X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1785978967; l=4367; i=demiobenour@gmail.com; s=20250729; h=from:subject:message-id; bh=0BDRvtoyTU9ar+n+g4u5wsuT3IowvvtDct6NoDfYk5M=; b=B21R8+ef0qTR1Tnj4e+DE0eE6oyW9ih+KOiG8lCcU8Fk6GgGJ8Stqsi/c6qxktUWuvcifD/47 wxPRbAU08v+CzOG5tlIXHLxYyHj+OctYd+ZojcHzS092FhVaSoLMJ5u X-Developer-Key: i=demiobenour@gmail.com; a=ed25519; pk=X57Q4/YQDj9t4SBeKaDwvXYKB6quZJVx/DE2Ly2out0= Message-ID-Hash: TQ2CKYR677GBDK6JCXEZK7RUIZVS46HZ X-Message-ID-Hash: TQ2CKYR677GBDK6JCXEZK7RUIZVS46HZ 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 | 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..fcf6f82f755b8cd542e5d45db4d1f3b3d43a375e --- /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 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. +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