From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YZVvASjZdGHN8QAAgWs5BA (envelope-from ) for ; Sun, 24 Oct 2021 05:55:20 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id uEtGOCfZdGEYdwAA1q6Kng (envelope-from ) for ; Sun, 24 Oct 2021 03:55:19 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C7DF528C9A for ; Sun, 24 Oct 2021 05:55:18 +0200 (CEST) Received: from localhost ([::1]:35396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meUbN-0006Rb-PQ for larch@yhetil.org; Sat, 23 Oct 2021 23:55:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meUb9-0006RO-VB for guix-patches@gnu.org; Sat, 23 Oct 2021 23:55:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:54366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1meUb9-0005cK-4r for guix-patches@gnu.org; Sat, 23 Oct 2021 23:55:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1meUb9-0005f4-4B for guix-patches@gnu.org; Sat, 23 Oct 2021 23:55:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51346] [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags Resent-From: Tobias Geerinckx-Rice Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 24 Oct 2021 03:55:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51346 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Josselin Poiret Cc: 51346@debbugs.gnu.org X-Debbugs-Original-Cc: 51346@debbugs.gnu.org, guix-patches@gnu.org Received: via spool by 51346-submit@debbugs.gnu.org id=B51346.163504769921724 (code B ref 51346); Sun, 24 Oct 2021 03:55:03 +0000 Received: (at 51346) by debbugs.gnu.org; 24 Oct 2021 03:54:59 +0000 Received: from localhost ([127.0.0.1]:37675 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meUb1-0005dx-Lp for submit@debbugs.gnu.org; Sat, 23 Oct 2021 23:54:59 -0400 Received: from tobias.gr ([80.241.217.52]:53682) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meUax-0005dY-2a for 51346@debbugs.gnu.org; Sat, 23 Oct 2021 23:54:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=2018; bh=i17HGVfzDSfHC ztu+Mk9oi6MXQ7cIqnx0o68biTgwBQ=; h=in-reply-to:date:subject:cc:to: from:references; d=tobias.gr; b=ffu3x1vLDpGVjylqc4DQXrb0jaaDOOiWlTrWdx ircf5crM19lhC0/i0WHaFhQTm6VtYbKevCLgT2zDaSxe7ENs6TGwwARkYTbM3cCGNb67zW PopjLoyQcF4pbRJy9SlTTPKy0URkIpIpib5kb2stw6Fv1m2AFrmXLroVo0vtCQQyjzIroj GT0VoTnU4DsXiGUQ4iAPAVTjhUpc/Lr1Y7UQYkrC+zikBan1rqnu4as0+Z8/tChvEy0cOF lzLj0nyv0BpoBrXl/jdXsXP6KzHfpO1lDHL/VQterTOvVkbiIHz8CnR5oV8C2xIthYNOlJ fqDsNq8JfLeJOImIOUg13Mrg== Received: by submission.tobias.gr (OpenSMTPD) with ESMTPSA id 6e0234f3 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 24 Oct 2021 03:54:45 +0000 (UTC) References: <87fsssdqg2.fsf@jpoiret.xyz> Date: Sun, 24 Oct 2021 04:05:30 +0200 In-reply-to: <87fsssdqg2.fsf@jpoiret.xyz> BIMI-Selector: v=BIMI1; s=default; Message-ID: <8735orjcvb.fsf@nckx> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Tobias Geerinckx-Rice X-ACL-Warn: , Tobias Geerinckx-Rice via Guix-patches From: Tobias Geerinckx-Rice via Guix-patches via X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635047719; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=i17HGVfzDSfHCztu+Mk9oi6MXQ7cIqnx0o68biTgwBQ=; b=cSI4BFVJQqRsAer5DjLTZcmBasPWonLN18QSRsJjF/Z7dL3P2w6QDcsU5iebKn1ii4O0rX 3fSD6bhUPcP07ni0O3bSjaeawUvTq0LSaQG2gAB18GLthF1AjKhmDcGeQyLs5ZBKNpKlJh Hy02rMcC6pEOpxalI9rJoBL8QgB0sA2GWTyz11eVF4GZYOMTy6aOMkRZuJeZxe+hck7sEX AsRgPm2qjC2QzMmnsjQGKmNSZnEhX1J2ABkIquOm0v2YyjcrC8lIUU/H79edCQsQCSlP9H yL20oJrkWpnzKDj9OUnDQrCBcwdZF7j5l+la/mmz/e/28Bgg+l8XsGaNnqEdOQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635047719; a=rsa-sha256; cv=none; b=JEw9AXpiZx9+peKmK0nFwuZY3phweu4tEs4yPvLGq5RAuAUv4zwAS7Mpu19q9/1dHyR0Gn 1PG+CR9B6ren0Ckx5Z9ezML2WitWfX6BpfJtSay3Me9/QHyYS3t6WH+FgJl2F/B/MlO0Fu OvMFHprP5zQhnyjbgvyd7haGgs5CoMsG59DrhcjrT44oI1l2EfdJ8+POmXoEfUQvJ8U0oH NsNdZENm6v/KmK2nSGtUjNB3Uuosvb3lxwGSyi1+Y/fLXfNF2qVC2D8UMvhbimWf52QZIh lK1GCMNclBYBBBHUlQWjMs8dyqOw0mDo/E0EXQOB/RJA1temkvP8t7IRH2GTiA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tobias.gr header.s=2018 header.b=ffu3x1vL; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -3.42 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tobias.gr header.s=2018 header.b=ffu3x1vL; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: C7DF528C9A X-Spam-Score: -3.42 X-Migadu-Scanner: scn1.migadu.com X-TUID: PPoajdlP8Ku7 --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Josselin, Josselin Poiret via Guix-patches via =E5=86=99=E9=81=93=EF=BC=9A > This patchset adds new record types swap-partition and=20 > swap-file, to be used in the swap-devices field of=20 > operating-system. Thank you so much for this. Do you happen to know anything about how the Hurd handles swap? > in the manual I refer to 'man 2 swapon' for the description of=20 > these flags. I think we should document the basics ourselves. We can still=20 refer to the man page if you think it's needed. WDYT? Pity that there's no (libc) Info node to which we can link. > This works well on my laptop, whereas my swap file used to never=20 > be swapon on boot because it wasn't available yet (on BTRFS on=20 > LUKS). I don't have a swap partition lying around though so=20 > testers welcome! Also boots fine with my plain swap partition: (swap-devices (list (swap-partition (device hibernation-device)))) Not having to explicitly manage HIBERNATION-DEVICE, as you suggest=20 below, sounds nice too :-) > I hope this can make it in time for the core-updates-frozen=20 > merge. As noted on IRC, I don't see a reason to involve core-updates at=20 all. We should take the time to define solid interfaces but, once done,=20 this can go straight to master. > I also plan to add swap file hibernation support eventually,=20 > where the file offsets are automatically determined by guix (or=20 > we could even write our own suspend/resume script in guile, see=20 > https://www.kernel.org/doc/html/latest/power/userland-swsusp.html). Okay. As also implied on IRC=E2=80=A6 I have a very low opinion of=20 uswsusp. It's brittle, gimmicky, and introduces many ways for=20 bugs to hide and boots to break. We'll have to carefully track=20 incompatible format changes and kernel/initrd generations. If it is added, we shouldn't involve early userspace in cases=20 where it's not strictly needed. But that for later :-) > +++ b/doc/guix.texi > +* Swap Space:: Adding swap space. You're following existing precedent here, but I just read the same=20 thing twice. I suggest =E2=80=98Swap Space:: Adding virtual memory to free up precious=20 RAM.=E2=80=99. > +@cindex swap devices > +A list of @code{} or @code{} objects > +(@pxref{Swap Space}), to be used for ``swap space''=20 > (@pxref{Memory > +Concepts,,, libc, The GNU C Library Reference Manual}). At the risk of leaving this very stubby, I think the (libc) ref=20 should be moved to the Swap Space node, which readers might visit=20 directly without reading the above. > +@node Swap Space > +@section Swap Space > +@cindex swap space =E2=80=A6so, here. I'm missing a short intro sentence that mentions what swap is for,=20 and that it comes in 2 common forms. The libc explanation is quite technical, doesn't actually define=20 =E2=80=98swap space=E2=80=99 except by implication, and immediately rambles= on=20 about zeroes that don't even exist. As a new user, I think I'd=20 feel lost. > +@deftp {Data Type} swap-partition > +Objects of this type represent swap partitions. They contain=20 > the following > +members: (What are =E2=80=98swap partitions=E2=80=99? Maybe explain the pros/cons o= f both=20 in each @deftp intro. Mostly a reminder to myself, but if you=20 want to write more docs: be my guest.) Always double-space after full stops in prose. > +@item @code{flags} (default: @code{'()}) > +A list of flags. The supported flags are @code{'delayed} and > +@code{('priority n)}, see @command{man 2 swapon} in the kernel=20 > man pages > +(@code{man-pages} guix package) for more information. 'delayed? To? When? I'm unenthusiastic about this interface. On the one hand, exposing this tiny and ossified list of 2.5=20 =E2=80=98flags=E2=80=99 (what even is that priority=E2=80=A6 thing=E2=80=A6= ) this way feels like=20 exposing users to an ugly C implementation detail for no benefit:=20 why not (swap-partition (priority 5) ; or #f distinct from 0 (discard? #t) =E2=80=A6) instead? On the other hand: perhaps other kernels expose different flags=20 and this model might make sense. I'm not convinced, but I'm=20 willing to be. > +A string, specifying the file path of the swap file to use. s/file path/name/ > +@item @code{fs} s/fs/file-system/ As a rule, avoid such pointless abbreviation. GNU's not unix,=20 thankfully. That said, why does this field exist at all? The example given=20 here: > +@item (swap-file (path "/swapfile") (fs root-fs)) > +Use the file @file{/swapfile} as swap space, which is present=20 > on the > +@var{root-fs} filesystem. =E2=80=A6rather side-steps the question of how this is supposed to work,=20 or in which situation it makes sense. I feel like it's papering=20 over a bug. > +(define (swap-flags->bit-mask flags) So I made the mistake of looking at how util-linux does this. Firstly, it silently clamps (> priority max) to MAX. I think it=20 makes sense to follow that behaviour, but print a warning.=20 Ignoring (< priority 0), with a warning, is fine. Secondly, and this is just weird, =E2=80=98man 2 swapon=E2=80=99 explicitly= =20 documents: (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK so naturally util-linux's swapon.c explicitly does this: (prio & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT What? Surely this ancient code can't work just by sheer luck=E2=80=A6=20 I'll ask. I see no advantage in ignoring SWAP_FLAG_PRIO_SHIFT, only risks.=20 Let's not. Here's how I'd write it: =2D-8<---------------cut here---------------start------------->8--- (define (swap-flags->bit-mask flags) "Return the number suitable for the 'flags' argument of 'mount'=20 that corresponds to the symbols listed in FLAGS." (let loop ((flags flags)) (match flags ((('priority p) rest ...) (if (< p 0) (begin (warning (G_ "Ignoring swap priority ~a as it is less=20 than 0.~%" p)) (loop rest)) (let* ((max (ash SWAP_FLAG_PRIO_MASK (-=20 SWAP_FLAG_PRIO_SHIFT))) (pri (if (> p max) (begin (warning (G_ "Limiting swap priority ~a to ~a.~%" p max)) max) p))) (logior SWAP_FLAG_PREFER (ash pri SWAP_FLAG_PRIO_SHIFT) (loop rest))))) (('discard rest ...) (logior SWAP_FLAG_DISCARD (loop rest))) (() 0)))) =2D-8<---------------cut here---------------end--------------->8--- It should also handle invalid input by printing the offending=20 symbol instead of a generic match error, but I'm about to board my=20 train, and will call it a night here. Kind regards, T G-R --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCYXTZGA0cbWVAdG9iaWFz LmdyAAoJEA2w/4hPVW15ZJcBAOhKTgpWIQz+TuEb0nLqlgFCNyGFWZ2M99MZKE9M 48OFAP9cBOJZsPcOuKYT1HRA8UoQZH66XYfoevEl+CDoh8cVAQ== =Di8U -----END PGP SIGNATURE----- --=-=-=--