From unknown Tue Jun 24 05:10:13 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#51346 <51346@debbugs.gnu.org> To: bug#51346 <51346@debbugs.gnu.org> Subject: Status: [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags Reply-To: bug#51346 <51346@debbugs.gnu.org> Date: Tue, 24 Jun 2025 12:10:13 +0000 retitle 51346 [PATCH 0/1 core-updates-frozen] Rework swap device to add dep= endencies and flags reassign 51346 guix-patches submitter 51346 Josselin Poiret severity 51346 normal tag 51346 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 23 05:46:15 2021 Received: (at submit) by debbugs.gnu.org; 23 Oct 2021 09:46:15 +0000 Received: from localhost ([127.0.0.1]:34402 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meDbS-0002b6-MK for submit@debbugs.gnu.org; Sat, 23 Oct 2021 05:46:15 -0400 Received: from lists.gnu.org ([209.51.188.17]:59520) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meDbP-0002YX-N9 for submit@debbugs.gnu.org; Sat, 23 Oct 2021 05:46:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meDbP-0000Fs-Fj for guix-patches@gnu.org; Sat, 23 Oct 2021 05:46:11 -0400 Received: from jpoiret.xyz ([206.189.101.64]:39642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meDbN-00025w-Ca for guix-patches@gnu.org; Sat, 23 Oct 2021 05:46:11 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id C9818184D67; Sat, 23 Oct 2021 09:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1634982366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=AhuXbSYs8EImhVdVzEFZkhxOk0BfJetVgsn5a3qU93Q=; b=G82vlKEVfRH2nYSISDZGsJcUadnLpbE/8hHFt43FDiULEjAgk2Ez5rV/zuO5KUUBvtvurS QLQm6+dlEptmjv8wKUlaoaAfOPESVjBzudv0VAFsz84ga16bR+x3K+H/4Es3fsb1CeFLoS NI8Ja+6YpirjdXT6Ub39w7wjjyEmltwd0D5XDd0S5tSDh/s+zfRUaz52HOCpEAAc4O7HAI TtIoBndQ8bL1pyDKvULFBWu9ElZ62E3CIonzmgKXJqJtZ8SDWPP8sFbrWMjABrPCnSycDk /y49+w3/lIvFhALDztDRfHhZWhF9rUhEjrIeI9n66IefE44RvvMPg7Xx6F2hgQ== From: Josselin Poiret To: guix-patches@gnu.org Subject: [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags Date: Sat, 23 Oct 2021 09:46:05 +0000 Message-ID: <87fsssdqg2.fsf@jpoiret.xyz> MIME-Version: 1.0 Content-Type: text/plain X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz Received-SPF: pass client-ip=206.189.101.64; envelope-from=dev@jpoiret.xyz; helo=jpoiret.xyz X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.5, FROM_SUSPICIOUS_NTLD_FP=1.999, PDS_OTHER_BAD_TLD=0.449, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.7 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi, This patchset adds new record types swap-partition and swap-file, to be used in the swap-devices field of operating-system. These support dependencies on mapped-device and file-system objects respecti [...] Content analysis details: (1.7 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] 0.9 SPF_FAIL SPF: sender does not match SPF record (fail) [SPF failed: Please see http://www.openspf.org/Why?s=mfrom; id=dev%40jpoiret.xyz; ip=209.51.188.17; r=debbugs.gnu.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.51.188.17 listed in wl.mailspike.net] -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [209.51.188.17 listed in list.dnswl.org] 0.5 FROM_SUSPICIOUS_NTLD_FP From abused NTLD 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.1 (/) Hi, This patchset adds new record types swap-partition and swap-file, to be used in the swap-devices field of operating-system. These support dependencies on mapped-device and file-system objects respectively, as well as swapon flags. I pulled those from GNU libc, and in the manual I refer to 'man 2 swapon' for the description of these flags. Support for the old style is kept for now, but I added deprecation warnings. This works well on my laptop, whereas my swap file used to never be swapon on boot because it wasn't available yet (on BTRFS on LUKS). I don't have a swap partition lying around though so testers welcome! I hope this can make it in time for the core-updates-frozen merge. I also plan to add swap file hibernation support eventually, where the file offsets are automatically determined by guix (or we could even write our own suspend/resume script in guile, see https://www.kernel.org/doc/html/latest/power/userland-swsusp.html). Josselin Poiret (1): gnu: system: Add support for swap dependencies and flags doc/guix.texi | 98 +++++++++++++++++++--------- gnu/build/file-systems.scm | 25 ++++++- gnu/services/base.scm | 126 ++++++++++++++++++++++++++---------- gnu/system.scm | 4 +- gnu/system/file-systems.scm | 34 +++++++++- guix/build/syscalls.scm | 12 ++++ 6 files changed, 230 insertions(+), 69 deletions(-) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 23 05:48:09 2021 Received: (at 51346) by debbugs.gnu.org; 23 Oct 2021 09:48:09 +0000 Received: from localhost ([127.0.0.1]:34408 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meDdI-0003vP-7n for submit@debbugs.gnu.org; Sat, 23 Oct 2021 05:48:09 -0400 Received: from jpoiret.xyz ([206.189.101.64]:41422) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meDdG-0003vH-8R for 51346@debbugs.gnu.org; Sat, 23 Oct 2021 05:48:07 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 350ED184D67; Sat, 23 Oct 2021 09:48:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1634982485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=PJPYTy6j+jb6HR295ZU2QisL1+YMzwrA0AazbZyJKvs=; b=RumFD9Bm98EJBjoEuhDfA/AJ+NSPQ3OJ3HcKcNRtrcEq1D9EibhBP9tVfzlnTtIVl3SPaE TnqNMPKU14jrTZo/45DYDidefdR5xrq5BbuavctqgZ5OCzbjDYtFA0buROr9zyRtERUJpH /GbMrWso6EGp+adB4Sh/roQ9fjPrqsWfo5Xi9PrsgrgDibD8YQddxwoirBREt0d8ohHDte GplCiMvLmtVEcYT/FQrsgiaZd4SyFb+A7frlfhwy5KE6bHpTf4649zgmpPMvxSongOROo+ DwNJ/t92fcl/DCf2Qq88GIJSOgXnFVsbnVOE0z2Md5/Pusux94o6GkCbhFdCPQ== From: Josselin Poiret To: 51346@debbugs.gnu.org Subject: [PATCH 1/1] gnu: system: Add support for swap dependencies and flags Date: Sat, 23 Oct 2021 08:55:24 +0000 Message-ID: <87cznwdqcr.fsf@jpoiret.xyz> MIME-Version: 1.0 Content-Type: text/plain X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 3.0 (+++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add new record types swap-file and swap-partition while still supporting the old style (for now). These support dependencies, as well as swapon flags. * gnu/system/file-systems.scm (swap-file, swap-partition): Add them. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-partition->service-name, swap-file [...] Content analysis details: (3.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD_FP From abused NTLD 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add new record types swap-file and swap-partition while still supporting the old style (for now). These support dependencies, as well as swapon flags. * gnu/system/file-systems.scm (swap-file, swap-partition): Add them. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-partition->service-name, swap-file [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager Add new record types swap-file and swap-partition while still supporting the old style (for now). These support dependencies, as well as swapon flags. * gnu/system/file-systems.scm (swap-file, swap-partition): Add them. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-partition->service-name, swap-file->service-name, swap-deprecated->service-name, swap->service-name): Add them. * gnu/services/base.scm (swap-service-type): Make it use the new record types and flags. * gnu/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK, SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add flags from glibc. * gnu/build/file-systems.scm (swap-flags->bit-mask): Add it. * doc/guix.texi (Swap Space): Add new section. * doc/guix.texi (operating-system Reference): Update it. --- doc/guix.texi | 98 +++++++++++++++++++--------- gnu/build/file-systems.scm | 25 ++++++- gnu/services/base.scm | 126 ++++++++++++++++++++++++++---------- gnu/system.scm | 4 +- gnu/system/file-systems.scm | 34 +++++++++- guix/build/syscalls.scm | 12 ++++ 6 files changed, 230 insertions(+), 69 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 67a05a10ff..88b097b3a8 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -319,6 +319,7 @@ System Configuration * operating-system Reference:: Detail of operating-system declarations. * File Systems:: Configuring file system mounts. * Mapped Devices:: Block device extra processing. +* Swap Space:: Adding swap space. * User Accounts:: Specifying user accounts. * Keyboard Layout:: How the system interprets key strokes. * Locales:: Language and cultural convention settings. @@ -13769,6 +13770,7 @@ instance to support new system services. * operating-system Reference:: Detail of operating-system declarations. * File Systems:: Configuring file system mounts. * Mapped Devices:: Block device extra processing. +* Swap Space:: Adding swap space. * User Accounts:: Specifying user accounts. * Keyboard Layout:: How the system interprets key strokes. * Locales:: Language and cultural convention settings. @@ -14135,38 +14137,11 @@ A list of mapped devices. @xref{Mapped Devices}. @item @code{file-systems} A list of file systems. @xref{File Systems}. -@cindex swap devices -@cindex swap space @item @code{swap-devices} (default: @code{'()}) -A list of UUIDs, file system labels, or strings identifying devices or -files to be used for ``swap -space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference -Manual}). Here are some examples: - -@table @code -@item (list (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")) -Use the swap partition with the given UUID@. You can learn the UUID of a -Linux swap partition by running @command{swaplabel @var{device}}, where -@var{device} is the @file{/dev} file name of that partition. - -@item (list (file-system-label "swap")) -Use the partition with label @code{swap}. Again, the -@command{swaplabel} command allows you to view and change the label of a -Linux swap partition. - -@item (list "/swapfile") -Use the file @file{/swapfile} as swap space. - -@item (list "/dev/sda3" "/dev/sdb2") -Use the @file{/dev/sda3} and @file{/dev/sdb2} partitions as swap space. -We recommend referring to swap devices by UUIDs or labels as shown above -instead. -@end table - -It is possible to specify a swap file in a file system on a mapped -device (under @file{/dev/mapper}), provided that the necessary device -mapping and file system are also specified. @xref{Mapped Devices} and -@ref{File Systems}. +@cindex swap devices +A list of @code{} or @code{} objects +(@pxref{Swap Space}), to be used for ``swap space'' (@pxref{Memory +Concepts,,, libc, The GNU C Library Reference Manual}). @item @code{users} (default: @code{%base-user-accounts}) @itemx @code{groups} (default: @code{%base-groups}) @@ -14788,6 +14763,67 @@ Devices @file{/dev/mapper/vg0-alpha} and @file{/dev/mapper/vg0-beta} can then be used as the @code{device} of a @code{file-system} declaration (@pxref{File Systems}). +@node Swap Space +@section Swap Space +@cindex swap space + +@deftp {Data Type} swap-partition +Objects of this type represent swap partitions. They contain the following +members: + +@table @asis +@item @code{device} +The device to use, either a UUID, a @code{file-system-label} or a string, +as in the definition of a @code{file-system} (@pxref{File Systems}). + +@item @code{dependencies} (default: @code{'()}) +A list of @code{mapped-device} objects, upon which the availability of +the device depends. + +@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 man pages +(@code{man-pages} guix package) for more information. + +@end table +@end deftp + +@deftp {Data Type} swap-file +Objects of this type represent swap files. They contain the following +members: + +@table @asis +@item @code{path} +A string, specifying the file path of the swap file to use. + +@item @code{fs} +A @code{file-system} object representing the file system inside which the +swap file may be found. + +@item @code{flags} (default: @code{'()}) +See the @code{flags} member of @code{swap-partition}. + +@end table +@end deftp + +Here are some examples: + +@table @code +@item (swap-partition (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb"))) +Use the swap partition with the given UUID@. You can learn the UUID of a +Linux swap partition by running @command{swaplabel @var{device}}, where +@var{device} is the @file{/dev} file name of that partition. + +@item (swap-partition (device (file-system-label "swap"))) +Use the partition with label @code{swap}. Again, the +@command{swaplabel} command allows you to view and change the label of a +Linux swap partition. + +@item (swap-file (path "/swapfile") (fs root-fs)) +Use the file @file{/swapfile} as swap space, which is present on the +@var{root-fs} filesystem. +@end table + @node User Accounts @section User Accounts diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index d8a5ddf1e5..e9806620fb 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -29,6 +29,8 @@ (define-module (gnu build file-systems) #:use-module (guix build bournish) #:use-module ((guix build syscalls) #:hide (file-system-type)) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (rnrs io ports) #:use-module (rnrs bytevectors) #:use-module (ice-9 match) @@ -54,7 +56,9 @@ (define-module (gnu build file-systems) mount-flags->bit-mask check-file-system - mount-file-system)) + mount-file-system + + swap-flags->bit-mask)) ;;; Commentary: ;;; @@ -227,6 +231,25 @@ (define (linux-swap-superblock-volume-name sblock) "Return the label of Linux-swap superblock SBLOCK as a string." (null-terminated-latin1->string (sub-bytevector sblock (+ 1024 4 4 4 16) 16))) + +(define (swap-flags->bit-mask flags) + "Return the number suitable for the 'flags' argument of 'mount' that +corresponds to the symbols listed in FLAGS." + (let loop ((flags flags)) + (match flags + ((('priority p) rest ...) + (if (<= 0 p SWAP_FLAG_PRIO_MASK) ; Here we take for granted that shift == 0 + (logior SWAP_FLAG_PREFER + p + (loop rest)) + (begin (warning (G_ "Given swap priority ~a is not contained +between 0 and ~a. Ignoring.~%") p SWAP_FLAG_PRIO_MASK) + (loop rest)))) + (('discard rest ...) + (logior SWAP_FLAG_DISCARD (loop rest))) + (() + 0)))) + ;;; diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 50865055fe..9b70e59b6f 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -58,11 +58,14 @@ (define-module (gnu services base) #:use-module (gnu packages linux) #:use-module (gnu packages terminals) #:use-module ((gnu build file-systems) - #:select (mount-flags->bit-mask)) + #:select (mount-flags->bit-mask + swap-flags->bit-mask)) #:use-module (guix gexp) #:use-module (guix records) #:use-module (guix modules) #:use-module ((guix self) #:select (make-config.scm)) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (ice-9 match) @@ -2146,62 +2149,117 @@ (define* (udev-rules-service name rules #:key (groups '())) udev-service-type udev-extension)))))) (service type #f))) +(define (swap-partition->service-name spartition) + (let ((device (swap-partition-device spartition))) + (symbol-append 'swap- + (string->symbol + (cond ((uuid? device) + (uuid->string device)) + ((file-system-label? device) + (file-system-label->string device)) + (else + device)))))) + +(define (swap-file->service-name sfile) + (symbol-append 'swap- (string->symbol (swap-file-path sfile)))) + +; TODO Remove after deprecation +(define (swap-deprecated->service-name sdep) + (symbol-append 'swap- + (string->symbol + (cond ((uuid? sdep) + (string-take (uuid->string sdep) 6)) + ((file-system-label? sdep) + (file-system-label->string sdep)) + (else + sdep))))) + +(define swap->service-name + (match-lambda ((? swap-partition? spartition) + (swap-partition->service-name spartition)) + ((? swap-file? sfile) + (swap-file->service-name sfile)) + (sdep + (swap-deprecated->service-name sdep)))) + (define swap-service-type (shepherd-service-type 'swap - (lambda (device) - (define requirement - (if (and (string? device) - (string-prefix? "/dev/mapper/" device)) - (list (symbol-append 'device-mapping- - (string->symbol (basename device)))) - '())) - - (define (device-lookup device) + (lambda (swap) + (define requirements + (cond ((swap-partition? swap) + (map dependency->shepherd-service-name + (swap-partition-dependencies swap))) + ((swap-file? swap) + (list (dependency->shepherd-service-name + (swap-file-fs swap)))) + ; TODO Remove after deprecation + ((and (string? swap) (string-prefix? "/dev/mapper/" swap)) + (list (symbol-append 'device-mapping- + (string->symbol (basename swap))))) + (else + '()))) + + (define device-lookup ;; The generic 'find-partition' procedures could return a partition ;; that's not swap space, but that's unlikely. - (cond ((uuid? device) - #~(find-partition-by-uuid #$(uuid-bytevector device))) - ((file-system-label? device) + (cond ((swap-partition? swap) + (let ((device (swap-partition-device swap))) + (cond ((uuid? device) + #~(find-partition-by-uuid #$(uuid-bytevector device))) + ((file-system-label? device) + #~(find-partition-by-label + #$(file-system-label->string device))) + (else + device)))) + ((swap-file? swap) + (swap-file-path swap)) + ; TODO Remove after deprecation + ((uuid? swap) + #~(find-partition-by-uuid #$(uuid-bytevector swap))) + ((file-system-label? swap) #~(find-partition-by-label - #$(file-system-label->string device))) + #$(file-system-label->string swap))) (else - device))) - - (define service-name - (symbol-append 'swap- - (string->symbol - (cond ((uuid? device) - (string-take (uuid->string device) 6)) - ((file-system-label? device) - (file-system-label->string device)) - (else - device))))) + swap))) + + (define flags + (cond ((swap-partition? swap) + (swap-partition-flags swap)) + ((swap-file? swap) + (swap-file-flags swap)) + (else '()))) (with-imported-modules (source-module-closure '((gnu build file-systems))) (shepherd-service - (provision (list service-name)) - (requirement `(udev ,@requirement)) - (documentation "Enable the given swap device.") + (provision (list (swap->service-name swap))) + (requirement `(udev ,@requirements)) + (documentation "Enable the given swap space.") (modules `((gnu build file-systems) ,@%default-modules)) (start #~(lambda () - (let ((device #$(device-lookup device))) + (let ((device #$device-lookup)) (and device (begin - (restart-on-EINTR (swapon device)) + (restart-on-EINTR (swapon device + #$(swap-flags->bit-mask + flags))) #t))))) (stop #~(lambda _ - (let ((device #$(device-lookup device))) + (let ((device #$device-lookup)) (when device (restart-on-EINTR (swapoff device))) #f))) (respawn? #f)))) (description "Turn on the virtual memory swap area."))) -(define (swap-service device) - "Return a service that uses @var{device} as a swap device." - (service swap-service-type device)) +(define (swap-service swap) + "Return a service that uses @var{swap} as a swap space." + (unless (or (swap-partition? swap) (swap-file? swap)) + (warning (G_ "Specifying swap space without @code{swap-partition} or +@code{swap-file} is deprecated, see \"(guix) operating-system Reference\" for +more details.~%"))) + (service swap-service-type swap)) (define %default-gpm-options ;; Default options for GPM. diff --git a/gnu/system.scm b/gnu/system.scm index 58b594694a..f732840488 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -234,8 +234,8 @@ (define-record-type* operating-system (mapped-devices operating-system-mapped-devices ; list of (default '())) (file-systems operating-system-file-systems) ; list of fs - (swap-devices operating-system-swap-devices ; list of strings - (default '())) + (swap-devices operating-system-swap-devices ; list of string | | + (default '())) ; (users operating-system-users ; list of user accounts (default %base-user-accounts)) diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm index e69cfd06e6..105f1e449b 100644 --- a/gnu/system/file-systems.scm +++ b/gnu/system/file-systems.scm @@ -96,7 +96,19 @@ (define-module (gnu system file-systems) %store-mapping %network-configuration-files - %network-file-mappings)) + %network-file-mappings + + swap-file + swap-file? + swap-file-path + swap-file-fs + swap-file-flags + + swap-partition + swap-partition? + swap-partition-device + swap-partition-dependencies + swap-partition-flags)) ;;; Commentary: ;;; @@ -671,4 +683,24 @@ (define (prepend-slash/maybe s) (G_ "Use the @code{subvol} Btrfs file system option.")))))))) +;;; +;;; Swap partition and files +;;; + +(define-record-type* swap-partition make-swap-partition + swap-partition? + this-swap-partition + (device swap-partition-device) + (dependencies swap-partition-dependencies + (default '())) + (flags swap-partition-flags + (default '()))) + +(define-record-type* swap-file make-swap-file swap-file? + this-swap-file + (path swap-file-path) + (fs swap-file-fs) + (flags swap-file-flags + (default '()))) + ;;; file-systems.scm ends here diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 99a3b45004..ae52c0ec54 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -71,6 +71,11 @@ (define-module (guix build syscalls) mounts mount-points + SWAP_FLAG_PREFER + SWAP_FLAG_PRIO_MASK + SWAP_FLAG_PRIO_SHIFT + SWAP_FLAG_DISCARD + swapon swapoff @@ -677,6 +682,13 @@ (define (mount-points) "Return the mounts points for currently mounted file systems." (map mount-point (mounts))) +;; Pulled from glibc's sysdeps/unix/sysv/linux/sys/swap.h + +(define SWAP_FLAG_PREFER #x8000) ;; Set if swap priority is specified. +(define SWAP_FLAG_PRIO_MASK #x7fff) +(define SWAP_FLAG_PRIO_SHIFT 0) +(define SWAP_FLAG_DISCARD #x10000) ;; + (define swapon (let ((proc (syscall->procedure int "swapon" (list '* int)))) (lambda* (device #:optional (flags 0)) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 23 23:55:00 2021 Received: (at submit) by debbugs.gnu.org; 24 Oct 2021 03:55:00 +0000 Received: from localhost ([127.0.0.1]:37678 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meUb5-0005eL-M1 for submit@debbugs.gnu.org; Sat, 23 Oct 2021 23:55:00 -0400 Received: from lists.gnu.org ([209.51.188.17]:38802) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meUb2-0005e4-VW for submit@debbugs.gnu.org; Sat, 23 Oct 2021 23:54:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meUb2-0006R1-Jx for guix-patches@gnu.org; Sat, 23 Oct 2021 23:54:56 -0400 Received: from tobias.gr ([2a02:c205:2020:6054::1]:34116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meUaz-0005TA-Jv for guix-patches@gnu.org; Sat, 23 Oct 2021 23:54:56 -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> From: Tobias Geerinckx-Rice To: Josselin Poiret Subject: Re: [bug#51346] [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags 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" Received-SPF: pass client-ip=2a02:c205:2020:6054::1; envelope-from=me@tobias.gr; helo=tobias.gr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-Debbugs-Envelope-To: submit Cc: 51346@debbugs.gnu.org, guix-patches@gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) --=-=-= 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----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 24 11:47:14 2021 Received: (at submit) by debbugs.gnu.org; 24 Oct 2021 15:47:14 +0000 Received: from localhost ([127.0.0.1]:40594 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mefiM-0006hG-Es for submit@debbugs.gnu.org; Sun, 24 Oct 2021 11:47:14 -0400 Received: from lists.gnu.org ([209.51.188.17]:35994) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mefiL-0006h9-Jt for submit@debbugs.gnu.org; Sun, 24 Oct 2021 11:47:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mefiK-0002BP-Aw for guix-patches@gnu.org; Sun, 24 Oct 2021 11:47:13 -0400 Received: from tobias.gr ([2a02:c205:2020:6054::1]:34164) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mefiH-0001aA-05 for guix-patches@gnu.org; Sun, 24 Oct 2021 11:47:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=2018; bh=e01sQtIq9GhN+ GOzfPuzTEqI9SQq2pVB9TlZz2e/BOw=; h=in-reply-to:date:subject:cc:to: from:references; d=tobias.gr; b=XCyVpRAHcNlPqZ+4UdlQldPhskcND2QlieYgPX zmK3KjhRcco1YZPwsitFAw3Fi6dg7UwlmE/NTvuYxNhtoVZvnjc0LoST/k5u+KZvhrXX0u BnHOujDfCjsSyle8rWdMTMYPv1YM818JWAZEWQvjg044klWylBa9M7VMWCIJ5XJVtMzJOV A9q05O4PccuISz78SFWCJWqfGRM30OvaNAZdx8GyVvp0Bcl/n/kBG8zrqK/AA4hXeB9saR uklwRTXQBg6ytbKsGCPid1ggDce3DrG942Yi5ZrVJL8DJuowvVUKsCJmjjacr5lg43ZnPZ nD8ZlR5Srcf2rSjn81Ezm0Vw== Received: by submission.tobias.gr (OpenSMTPD) with ESMTPSA id 1c01c2db (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sun, 24 Oct 2021 15:47:01 +0000 (UTC) References: <87fsssdqg2.fsf@jpoiret.xyz> <87cznwdqcr.fsf@jpoiret.xyz> From: Tobias Geerinckx-Rice To: Josselin Poiret Subject: Re: [bug#51346] [PATCH 1/1] gnu: system: Add support for swap dependencies and flags Date: Sun, 24 Oct 2021 15:58:56 +0200 In-reply-to: <87cznwdqcr.fsf@jpoiret.xyz> BIMI-Selector: v=BIMI1; s=default; Message-ID: <87tuh6ifwe.fsf@nckx> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Received-SPF: pass client-ip=2a02:c205:2020:6054::1; envelope-from=me@tobias.gr; helo=tobias.gr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-Debbugs-Envelope-To: submit Cc: 51346@debbugs.gnu.org, guix-patches@gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Oh no, he's back. With another annoying question: why don't we drop the=20 whole swap-partition/swap-file dichotomy? The distinction is=20 artificial insofar as Linux doesn't make one. Which end is supposed to explode if you (swap-partition (device "/home/nckx/swap")) (swap-file (name "/dev/sda2")) ? What real-world drawback(s) do you see to (swap (space "/home/nckx/swap")) (swap (space "/dev/sda2")) (swap (space (uuid "ab-c-d-e-fgh"))) (swap (space (file-system-label "best-swaps"))) naming aside? Josselin Poiret via Guix-patches via =E5=86=99=E9=81=93=EF=BC=9A > +(define (swap-partition->service-name spartition) Nitpick: ->shepherd-service-name just for similarity to=20 s. Aside, when I try to apply your third manual example, I get: guix system: error: service 'swap-/dev/sda2' requires 'file-system-/', which is not provided by any service Kind regards, T G-R --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCYXWAAQ0cbWVAdG9iaWFz LmdyAAoJEA2w/4hPVW15nCsBAKa+1VcqpB7zlZNjfarJi8/CD0in0524AduTy8um qMa3AP9B8iZ3k3oGQa1mXdPy8nhTdyeuKDrHO1HitvQtHBTAAw== =fUdI -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 25 10:17:46 2021 Received: (at submit) by debbugs.gnu.org; 25 Oct 2021 14:17:46 +0000 Received: from localhost ([127.0.0.1]:43905 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mf0nJ-000257-T4 for submit@debbugs.gnu.org; Mon, 25 Oct 2021 10:17:46 -0400 Received: from lists.gnu.org ([209.51.188.17]:53598) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mf0nI-00024x-0G for submit@debbugs.gnu.org; Mon, 25 Oct 2021 10:17:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mf0nG-0003Dr-1Z for guix-patches@gnu.org; Mon, 25 Oct 2021 10:17:43 -0400 Received: from jpoiret.xyz ([206.189.101.64]:39422) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mf0nD-0005Lh-HR for guix-patches@gnu.org; Mon, 25 Oct 2021 10:17:41 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 2F5D2184F41; Mon, 25 Oct 2021 14:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1635171455; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M3f2fVS+TODdAoIvnA+CB2uvAfRbEJh3P7zaZ405LMY=; b=NDfhkBSruiK05cKzHg7CIO26WFdE15g0KfdRAyhulAQD4diS3BWjSPUjQLRP4yxKq/h9Ax URrttONcmt1HIrlDLIzIZ3rVgrzZX4bb/RpAoZG91VW5+LonK6oWesKhsopa3ZaKzGeu40 ZX1QqYID0yvnlO5wSjeuPeutI+3L48pM+BBUzJX1SlblYKjKbNeT9nWuxZkNE8I8Kz+P9g 1NpG37/0QLK0BxGTkBK0aC3UEGLcsfqT1DkZhkx1KjiOUK1ILC2087ZdS22UuHdJyN717Q IAJBrPOdpRpXSvOdShgQlcQZSGY/ATt0L4py5LkxOnJRvUHRn1TacnRUkjWk5g== Subject: Re: [bug#51346] [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags To: Tobias Geerinckx-Rice References: <87fsssdqg2.fsf@jpoiret.xyz> <8735orjcvb.fsf@nckx> From: Josselin Poiret Message-ID: <9a5e71f6-91d0-a226-ff51-609598aa3625@jpoiret.xyz> Date: Mon, 25 Oct 2021 14:17:16 +0000 MIME-Version: 1.0 In-Reply-To: <8735orjcvb.fsf@nckx> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz Received-SPF: pass client-ip=206.189.101.64; envelope-from=dev@jpoiret.xyz; helo=jpoiret.xyz X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.499, PDS_OTHER_BAD_TLD=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi, First and foremost, thank you for your review! On 10/24/21 2:05 AM, Tobias Geerinckx-Rice wrote: Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [209.51.188.17 listed in list.dnswl.org] 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] 0.9 SPF_FAIL SPF: sender does not match SPF record (fail) [SPF failed: Please see http://www.openspf.org/Why?s=mfrom; id=dev%40jpoiret.xyz; ip=209.51.188.17; r=debbugs.gnu.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.51.188.17 listed in wl.mailspike.net] 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: submit Cc: 51346@debbugs.gnu.org, guix-patches@gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi, First and foremost, thank you for your review! On 10/24/21 2:05 AM, Tobias Geerinckx-Rice wrote: Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.51.188.17 listed in wl.mailspike.net] -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [209.51.188.17 listed in list.dnswl.org] 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] 0.9 SPF_FAIL SPF: sender does not match SPF record (fail) [SPF failed: Please see http://www.openspf.org/Why?s=mfrom;id=dev%40jpoiret.xyz;ip=209.51.188.17;r=debbugs.gnu.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD 1.0 BULK_RE_SUSP_NTLD Precedence bulk and RE: from a suspicious TLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager Hi, First and foremost, thank you for your review! On 10/24/21 2:05 AM, Tobias Geerinckx-Rice wrote: > Do you happen to know anything about how the Hurd handles swap? I'm investigating this currently, got a Hurd vm up and running ("guix system image -t hurd-raw" is very nice). We talked about this on IRC, and decided that it would be easier to simply used the Hurd's swapon binary (from the hurd package itself), rather than directly communicate with the default_pager server, since that'd involve writing a lot of Hurd RPC code. In the long run, this would be the way to go, just like for Linux (we use (guix build syscalls) instead of util-linux's swapon), but getting initial support in faster would be great. >> in the manual I refer to 'man 2 swapon' for the description of these flags. > > I think we should document the basics ourselves. We can still 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. Now that I'm looking at it, they really are not that complicated, I'll write something to describe them then. >> +++ b/doc/guix.texi >> +* Swap Space:: Adding swap space. > > You're following existing precedent here, but I just read the same thing twice. > > I suggest ‘Swap Space:: Adding virtual memory to free up precious RAM.’. Noted! Maybe something along "Backing RAM with disk space." rather, as swap space isn't really memory? >> +@cindex swap devices >> +A list of @code{} or @code{} objects >> +(@pxref{Swap Space}), to be used for ``swap space'' (@pxref{Memory >> +Concepts,,, libc, The GNU C Library Reference Manual}). > > At the risk of leaving this very stubby, I think the (libc) ref should be moved to the Swap Space node, which readers might visit directly without reading the above. > >> +@node Swap Space >> +@section Swap Space >> +@cindex swap space > > …so, here. > > I'm missing a short intro sentence that mentions what swap is for, and that it comes in 2 common forms. > > The libc explanation is quite technical, doesn't actually define ‘swap space’ except by implication, and immediately rambles on about zeroes that don't even exist. As a new user, I think I'd feel lost. Will add. >> +@deftp {Data Type} swap-partition >> +Objects of this type represent swap partitions. They contain the following >> +members: > > (What are ‘swap partitions’? Maybe explain the pros/cons of both in each @deftp intro. Mostly a reminder to myself, but if you 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 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 ‘flags’ (what even is that priority… thing…) this way feels like exposing users to an ugly C implementation detail for no benefit: why not > > (swap-partition > (priority 5) ; or #f distinct from 0 > (discard? #t) > …) > > instead? > > On the other hand: perhaps other kernels expose different flags and this model might make sense. I'm not convinced, but I'm willing to be. Welp, looks like you gave me the perfect excuse: from what I gather, Hurd does not have any flags for its swap space (see hurd/default_pager.defs, line 86). The other part of the reason is that I did not want to have even more "swap-partition-priority"/"swap-file-priority" duplicate accessors (more on swap-file/swap-partition below). >> +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, thankfully. > > That said, why does this field exist at all? The example given here: > >> +@item (swap-file (path "/swapfile") (fs root-fs)) >> +Use the file @file{/swapfile} as swap space, which is present on the >> +@var{root-fs} filesystem. > > …rather side-steps the question of how this is supposed to work, or in which situation it makes sense. I feel like it's papering over a bug. Abbreviation aside, the example is bad: even though theoretically presence of the swap file depends on the root filesystem being mounted, well, root-fs is always mounted and should be ignored (there's no filesystem-/ service either). A better example would be my personal configuration: (swap-devices (list (swap-file (path "/btrfs/swapfile") (fs (car (filter (lambda (x) (equal? (file-system-mount-point x) "/btrfs")) file-systems)))))) You can see here that /btrfs/swapfile wouldn't be accessible if the filesystem under fs wasn't mounted first. >> +(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 makes sense to follow that behaviour, but print a warning. Ignoring (< priority 0), with a warning, is fine. > > Secondly, and this is just weird, ‘man 2 swapon’ explicitly 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… I'll ask. I mean, SWAP_FLAG_PRIO_SHIFT has been equal 0 since at least the initial linux git commit 17 years ago, so it might actually be sheer luck. > I see no advantage in ignoring SWAP_FLAG_PRIO_SHIFT, only risks. Let's not. How I saw it: if SWAP_FLAG_PRIO_SHIFT ever changes from 0, and our code actually cared about its value, we'd still have to notice the change and change the value (it would be different if we were parsing linux headers instead). But I guess that's mostly laziness on my part, and since you wrote a nice replacement, I guess I'll add that. > It should also handle invalid input by printing the offending symbol instead of a generic match error, but I'm about to board my train, and will call it a night here. Will do! On 10/24/21 1:58 PM, Tobias Geerinckx-Rice wrote: > Oh no, > > he's back. With another annoying question: why don't we drop the whole swap-partition/swap-file dichotomy? The distinction is artificial insofar as Linux doesn't make one. > > Which end is supposed to explode if you > > (swap-partition (device "/home/nckx/swap")) > (swap-file (name "/dev/sda2")) > > ? > > What real-world drawback(s) do you see to > > (swap (space "/home/nckx/swap")) > (swap (space "/dev/sda2")) > (swap (space (uuid "ab-c-d-e-fgh"))) > (swap (space (file-system-label "best-swaps"))) > > naming aside? The motivating thing for me was that they have to be treated differently for hibernation purposes: you shouldn't make the dependencies of a swap file available (ie mount the filesystem it's on) but rather determine its offset inside the block device. For a swap partition, there's no such thing, you have to make the device itself available to the kernel. We could have a swapfile? flag instead though, but I'm still not convinced by both approaches. For the current patch though, nothing is going to explode there (although for a swap-file you do have to specify the filesystem it is on, but that's just my record definition forcing you to). > Josselin Poiret via Guix-patches via 写道: >> +(define (swap-partition->service-name spartition) > > Nitpick: ->shepherd-service-name just for similarity to s. > > Aside, when I try to apply your third manual example, I get: > > guix system: error: service 'swap-/dev/sda2' requires > 'file-system-/', which is not provided by any service I forgot that the root filesystem is treated differently from others, so this example is borked. I'll add something akin to my config instead. On a tangential note, there's nothing stopping us from renaming root-file-system to file-system-/, so that these at least don't give an error, right (they're logically not wrong dependencies, although a bit useless)? Thanks again for your review! A revised patchset (yes, this time with multiple commits) will be coming soon, once I figure out the proper way to work with block devices on Hurd. Best, Josselin Poiret From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 27 11:09:38 2021 Received: (at 51346) by debbugs.gnu.org; 27 Oct 2021 15:09:38 +0000 Received: from localhost ([127.0.0.1]:50178 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYc-0000NY-Hx for submit@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:38 -0400 Received: from jpoiret.xyz ([206.189.101.64]:34570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYa-0000NO-Rq for 51346@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:37 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 4F09D184BC9; Wed, 27 Oct 2021 15:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1635347375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oIE9R1TjsTaFgqYj9Pk1B/x0cG5UYXvtORcKGtZuraw=; b=KaVxDMvUk+tZLLFfkhGpwlDFdcDbuNREi2XEPFfQryG8l45ia8EdzFoI4CqauogDTBiUQb X1qbiGYrl9cOU0+dCmjNfKT3728gucrazfKtQGNzFjIbcphDpwU1zduJlEdmElfrcCJ8gK BlQO7xzZCO5V+64Y37bygVp5SmnNpKou7z4A9C+2YT+SG4iex9vIF/35wvURTVhWt0Mp1s 3QI7KDKs59GGWLMuIKg4x9dVbPQl5SnMrgRFMRsZG059KyFh/3B3KOTxoseNcG8Cip80Aw nSw9VQNezhh2v1uOYdK+WXb/gaVd14wQXGaCERZmmHTk9A1WZham7V+DyskpCg== From: Josselin Poiret To: Tobias Geerinckx-Rice Subject: [PATCH v2 0/4] Rework swap, add flags and dependencies. Date: Wed, 27 Oct 2021 15:09:09 +0000 Message-Id: <20211027150913.6038-1-dev@jpoiret.xyz> In-Reply-To: <87tuh6ifwe.fsf@nckx> References: <87tuh6ifwe.fsf@nckx> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++ Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Level: **** X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi, Alright, this new revised and expanded patchset should take into account most of the previous remarks, as well as fix some corner cases. Akin to what is done for file system services, I've modified swap-services so that it filters out boot-time dependencies which cannot be managed by Shepherd. Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi, Alright, this new revised and expanded patchset should take into account most of the previous remarks, as well as fix some corner cases. Akin to what is done for file system services, I've modified swap-services so that it filters out boot-time dependencies which cannot be managed by Shepherd. Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager Hi, Alright, this new revised and expanded patchset should take into account most of the previous remarks, as well as fix some corner cases. Akin to what is done for file system services, I've modified swap-services so that it filters out boot-time dependencies which cannot be managed by Shepherd. In doing so, I noticed that the non-boot-file-system-services procedure automagically adds mapped devices dependencies that it detects: is that documented behaviour, are we trying to support it or are we trying to move away from it? The documentation should now be self-sufficient, with the example desktop configuration updated to contain a swap file. Josselin Poiret (4): gnu: system: Rework swap space support, add dependencies. gnu: system: Add swap flags. gnu: system: Filter out boot dependencies from swap-space. doc: Add new Swap Space section. doc/guix.texi | 136 ++++++++++++++++++++++--------- gnu/build/file-systems.scm | 35 +++++++- gnu/services/base.scm | 109 +++++++++++++++++-------- gnu/system.scm | 20 ++++- gnu/system/examples/desktop.tmpl | 7 +- gnu/system/file-systems.scm | 24 +++++- guix/build/syscalls.scm | 12 +++ 7 files changed, 267 insertions(+), 76 deletions(-) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 27 11:09:43 2021 Received: (at 51346) by debbugs.gnu.org; 27 Oct 2021 15:09:43 +0000 Received: from localhost ([127.0.0.1]:50182 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYg-0000Np-P4 for submit@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:43 -0400 Received: from jpoiret.xyz ([206.189.101.64]:34654) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYf-0000Nh-8R for 51346@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:41 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 7DC55184BC9; Wed, 27 Oct 2021 15:09:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1635347380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d+fmujT6setCL9MnWntBntviV5dlhnM8zxeOYNC/OX8=; b=Jk9S4qjpfFsYNAnpPhZAvCVFmA19E9vzeM/wCHpQ+J4atY9RMkFdcJX8x9286leNSS1m40 67mykt4xCKpmozuMor218Hm6Bar95S/RInNX5DGmq9F0eUARAhBNKTcGX822/berHCmdAg 4KA6kg3EE6g2PvR4PdmCNCfS5kj6TljTo5cPMIXM+w3E4rCAu5oLtIcS7c1VoO6LWG1V+A wgQzFOGNBdnnVS8CiGcTb6cmOY/cCbc4uv5JDE5Gw3KOzOTDhMBRkuJZfA/EgkQegqaHXc ScgJWOTcCUTeQh0UeGXelLiyxjLEwHtRxaxNG0XH18GF8+dWc2E7ecqQBfUamA== From: Josselin Poiret To: Tobias Geerinckx-Rice Subject: [PATCH v2 1/4] gnu: system: Rework swap space support, add dependencies. Date: Wed, 27 Oct 2021 15:09:10 +0000 Message-Id: <20211027150913.6038-2-dev@jpoiret.xyz> In-Reply-To: <20211027150913.6038-1-dev@jpoiret.xyz> References: <87tuh6ifwe.fsf@nckx> <20211027150913.6038-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system/file-systems.scm (swap-space): Add it. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-space->shepherd-service-name, swap-deprecated->shep [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system/file-systems.scm (swap-space): Add it. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-space->shepherd-service-name, swap-deprecated->shep [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * gnu/system/file-systems.scm (swap-space): Add it. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-space->shepherd-service-name, swap-deprecated->shepherd-service-name, swap->shepherd-service-name): Add them. * gnu/services/base.scm (swap-service-type, swap-service): Use the new records. --- gnu/services/base.scm | 102 +++++++++++++++++++++++++----------- gnu/system.scm | 2 +- gnu/system/file-systems.scm | 18 ++++++- 3 files changed, 88 insertions(+), 34 deletions(-) diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 50865055fe..c816381198 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -63,6 +63,8 @@ (define-module (gnu services base) #:use-module (guix records) #:use-module (guix modules) #:use-module ((guix self) #:select (make-config.scm)) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (ice-9 match) @@ -2146,62 +2148,98 @@ (define* (udev-rules-service name rules #:key (groups '())) udev-service-type udev-extension)))))) (service type #f))) +(define (swap-space->shepherd-service-name space) + (let ((target (swap-space-target space))) + (symbol-append 'swap- + (string->symbol + (cond ((uuid? target) + (uuid->string target)) + ((file-system-label? target) + (file-system-label->string target)) + (else + target)))))) + +; TODO Remove after deprecation +(define (swap-deprecated->shepherd-service-name sdep) + (symbol-append 'swap- + (string->symbol + (cond ((uuid? sdep) + (string-take (uuid->string sdep) 6)) + ((file-system-label? sdep) + (file-system-label->string sdep)) + (else + sdep))))) + +(define swap->shepherd-service-name + (match-lambda ((? swap-space? space) + (swap-space->shepherd-service-name space)) + (sdep + (swap-deprecated->shepherd-service-name sdep)))) + (define swap-service-type (shepherd-service-type 'swap - (lambda (device) - (define requirement - (if (and (string? device) - (string-prefix? "/dev/mapper/" device)) - (list (symbol-append 'device-mapping- - (string->symbol (basename device)))) - '())) - - (define (device-lookup device) + (lambda (swap) + (define requirements + (cond ((swap-space? swap) + (map dependency->shepherd-service-name + (swap-space-dependencies swap))) + ; TODO Remove after deprecation + ((and (string? swap) (string-prefix? "/dev/mapper/" swap)) + (list (symbol-append 'device-mapping- + (string->symbol (basename swap))))) + (else + '()))) + + (define device-lookup ;; The generic 'find-partition' procedures could return a partition ;; that's not swap space, but that's unlikely. - (cond ((uuid? device) - #~(find-partition-by-uuid #$(uuid-bytevector device))) - ((file-system-label? device) + (cond ((swap-space? swap) + (let ((target (swap-space-target swap))) + (cond ((uuid? target) + #~(find-partition-by-uuid #$(uuid-bytevector target))) + ((file-system-label? target) + #~(find-partition-by-label + #$(file-system-label->string target))) + (else + target)))) + ; TODO Remove after deprecation + ((uuid? swap) + #~(find-partition-by-uuid #$(uuid-bytevector swap))) + ((file-system-label? swap) #~(find-partition-by-label - #$(file-system-label->string device))) + #$(file-system-label->string swap))) (else - device))) - - (define service-name - (symbol-append 'swap- - (string->symbol - (cond ((uuid? device) - (string-take (uuid->string device) 6)) - ((file-system-label? device) - (file-system-label->string device)) - (else - device))))) + swap))) (with-imported-modules (source-module-closure '((gnu build file-systems))) (shepherd-service - (provision (list service-name)) - (requirement `(udev ,@requirement)) - (documentation "Enable the given swap device.") + (provision (list (swap->shepherd-service-name swap))) + (requirement `(udev ,@requirements)) + (documentation "Enable the given swap space.") (modules `((gnu build file-systems) ,@%default-modules)) (start #~(lambda () - (let ((device #$(device-lookup device))) + (let ((device #$device-lookup)) (and device (begin (restart-on-EINTR (swapon device)) #t))))) (stop #~(lambda _ - (let ((device #$(device-lookup device))) + (let ((device #$device-lookup)) (when device (restart-on-EINTR (swapoff device))) #f))) (respawn? #f)))) (description "Turn on the virtual memory swap area."))) -(define (swap-service device) - "Return a service that uses @var{device} as a swap device." - (service swap-service-type device)) +(define (swap-service swap) + "Return a service that uses @var{swap} as a swap space." + (unless (swap-space? swap) + (warning (G_ "Specifying swap space without @code{swap-space} +is deprecated, see \"(guix) operating-system Reference\" for +more details.~%"))) + (service swap-service-type swap)) (define %default-gpm-options ;; Default options for GPM. diff --git a/gnu/system.scm b/gnu/system.scm index 58b594694a..2797c07e36 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -234,7 +234,7 @@ (define-record-type* operating-system (mapped-devices operating-system-mapped-devices ; list of (default '())) (file-systems operating-system-file-systems) ; list of fs - (swap-devices operating-system-swap-devices ; list of strings + (swap-devices operating-system-swap-devices ; list of string | (default '())) (users operating-system-users ; list of user accounts diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm index e69cfd06e6..7aa19069a1 100644 --- a/gnu/system/file-systems.scm +++ b/gnu/system/file-systems.scm @@ -96,7 +96,12 @@ (define-module (gnu system file-systems) %store-mapping %network-configuration-files - %network-file-mappings)) + %network-file-mappings + + swap-space + swap-space? + swap-space-target + swap-space-dependencies)) ;;; Commentary: ;;; @@ -671,4 +676,15 @@ (define (prepend-slash/maybe s) (G_ "Use the @code{subvol} Btrfs file system option.")))))))) +;;; +;;; Swap space +;;; + +(define-record-type* swap-space make-swap-space + swap-space? + this-swap-space + (target swap-space-target) + (dependencies swap-space-dependencies + (default '()))) + ;;; file-systems.scm ends here -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 27 11:09:48 2021 Received: (at 51346) by debbugs.gnu.org; 27 Oct 2021 15:09:48 +0000 Received: from localhost ([127.0.0.1]:50190 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYm-0000OM-7S for submit@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:48 -0400 Received: from jpoiret.xyz ([206.189.101.64]:34742) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYh-0000Nq-E7 for 51346@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:43 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 961D9184BC9; Wed, 27 Oct 2021 15:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1635347382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PAKY3EBJZaeHuIoMZ/xxWuXzRdhV65m7BJSYz1AAK+U=; b=m7Gg12GToY/14D5tF3bAR17Oj0gMCiyG4Ljv41HSsaSt+xO/3K6dM4Js0BmUlNBn1iw7Wz KxRA+dIAir8S50FSm9U02QIGvAzo16tlrBdqlrA2bJHkHv0RiwRtU05uU+bA6pjhuWLatM CHR5B5lAaZsoywx6VEk2BuPMOgCpoCYDdogDU+2dOnvs9n3eeTe3mME2PdAMuWH1f4BZv7 tDLR1RWTBMTFFJY9FHRXzklodHCziQDZ6oF+8PAIv/mTyv0Aa4nK1PMsPJ+8IJGJlNGHsQ OnZCpLVG1b/ILBPzkrSDLFb8wee88+0f6dQpN5wtiapMrgn58+aN57Uhn6kCYg== From: Josselin Poiret To: Tobias Geerinckx-Rice Subject: [PATCH v2 2/4] gnu: system: Add swap flags. Date: Wed, 27 Oct 2021 15:09:11 +0000 Message-Id: <20211027150913.6038-3-dev@jpoiret.xyz> In-Reply-To: <20211027150913.6038-1-dev@jpoiret.xyz> References: <87tuh6ifwe.fsf@nckx> <20211027150913.6038-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system/file-systems.scm (swap-space)[priority, discard?]: Add them. * guix/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK, SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add them. * gnu/bu [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system/file-systems.scm (swap-space)[priority, discard?]: Add them. * guix/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK, SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add them. * gnu/bu [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * gnu/system/file-systems.scm (swap-space)[priority, discard?]: Add them. * guix/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK, SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add them. * gnu/build/file-systems.scm (swap-space->flags-bit-mask): Add it. * gnu/services/base.scm (swap-service-type): Use it. --- gnu/build/file-systems.scm | 35 ++++++++++++++++++++++++++++++++++- gnu/services/base.scm | 7 +++++-- gnu/system/file-systems.scm | 10 ++++++++-- guix/build/syscalls.scm | 12 ++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index d8a5ddf1e5..39a408e8c1 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -29,6 +29,8 @@ (define-module (gnu build file-systems) #:use-module (guix build bournish) #:use-module ((guix build syscalls) #:hide (file-system-type)) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (rnrs io ports) #:use-module (rnrs bytevectors) #:use-module (ice-9 match) @@ -54,7 +56,9 @@ (define-module (gnu build file-systems) mount-flags->bit-mask check-file-system - mount-file-system)) + mount-file-system + + swap-space->flags-bit-mask)) ;;; Commentary: ;;; @@ -227,6 +231,35 @@ (define (linux-swap-superblock-volume-name sblock) "Return the label of Linux-swap superblock SBLOCK as a string." (null-terminated-latin1->string (sub-bytevector sblock (+ 1024 4 4 4 16) 16))) + +(define (swap-space->flags-bit-mask swap) + "Return the number suitable for the 'flags' argument of 'mount' +that corresponds to the swap-space SWAP." + (define prio-flag + (let ((p (swap-space-priority swap)) + (max (ash SWAP_FLAG_PRIO_MASK (- SWAP_FLAG_PRIO_SHIFT)))) + (if p + (logior SWAP_FLAG_PREFER + (ash (cond + ((< p 0) + (begin (warning + (G_ "Given swap priority ~a is negative, +defaulting to 0.~%") p) + 0)) + ((> p max) + (begin (warning + (G_ "Limiting swap priority ~a to ~a.~%") + p max) + max)) + (else p)) + SWAP_FLAG_PRIO_SHIFT)) + 0))) + (define delayed-flag + (if (swap-space-discard? swap) + SWAP_FLAG_DISCARD + 0)) + (logior prio-flag delayed-flag)) + ;;; diff --git a/gnu/services/base.scm b/gnu/services/base.scm index c816381198..cf43a78fd0 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -58,7 +58,8 @@ (define-module (gnu services base) #:use-module (gnu packages linux) #:use-module (gnu packages terminals) #:use-module ((gnu build file-systems) - #:select (mount-flags->bit-mask)) + #:select (mount-flags->bit-mask + swap-space->flags-bit-mask)) #:use-module (guix gexp) #:use-module (guix records) #:use-module (guix modules) @@ -2223,7 +2224,9 @@ (define device-lookup (let ((device #$device-lookup)) (and device (begin - (restart-on-EINTR (swapon device)) + (restart-on-EINTR (swapon device + #$(swap-space->flags-bit-mask + swap))) #t))))) (stop #~(lambda _ (let ((device #$device-lookup)) diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm index 7aa19069a1..fba4ebf65d 100644 --- a/gnu/system/file-systems.scm +++ b/gnu/system/file-systems.scm @@ -101,7 +101,9 @@ (define-module (gnu system file-systems) swap-space swap-space? swap-space-target - swap-space-dependencies)) + swap-space-dependencies + swap-space-priority + swap-space-discard?)) ;;; Commentary: ;;; @@ -685,6 +687,10 @@ (define-record-type* swap-space make-swap-space this-swap-space (target swap-space-target) (dependencies swap-space-dependencies - (default '()))) + (default '())) + (priority swap-space-priority + (default #f)) + (discard? swap-space-discard? + (default #f))) ;;; file-systems.scm ends here diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 99a3b45004..f2b18abf5a 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -71,6 +71,11 @@ (define-module (guix build syscalls) mounts mount-points + SWAP_FLAG_PREFER + SWAP_FLAG_PRIO_MASK + SWAP_FLAG_PRIO_SHIFT + SWAP_FLAG_DISCARD + swapon swapoff @@ -677,6 +682,13 @@ (define (mount-points) "Return the mounts points for currently mounted file systems." (map mount-point (mounts))) +;; Pulled from glibc's sysdeps/unix/sysv/linux/sys/swap.h + +(define SWAP_FLAG_PREFER #x8000) ;; Set if swap priority is specified. +(define SWAP_FLAG_PRIO_MASK #x7fff) +(define SWAP_FLAG_PRIO_SHIFT 0) +(define SWAP_FLAG_DISCARD #x10000) ;; Discard swap cluster after use. + (define swapon (let ((proc (syscall->procedure int "swapon" (list '* int)))) (lambda* (device #:optional (flags 0)) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 27 11:09:48 2021 Received: (at 51346) by debbugs.gnu.org; 27 Oct 2021 15:09:49 +0000 Received: from localhost ([127.0.0.1]:50192 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYm-0000OO-JK for submit@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:48 -0400 Received: from jpoiret.xyz ([206.189.101.64]:34834) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYj-0000O7-84 for 51346@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:45 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 504D0184BC9; Wed, 27 Oct 2021 15:09:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1635347384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=83Fns071x+nG1qjkWnmqp22+5nT32NIAaiErrr/0H+4=; b=HAE/fuMccxzYyLVpCc2XsCWcn/i6Zs1KO4LZAFb2Khluey9ReoqLPlnrSCtHhqGs76N6Jm tp1ndDld6klNRJbglrOTPXVJE5njUNjuK5d++H5iO550tuY6xJQasHg+kWHbmgB9UEgmhr apQtZ+l1aZ7ryMzU3uL+7KKNuI7Reo7rJuP44PGsQcpEEU4U5x/7NeliYb0rH4CVgw0PjV XxW32cG/DVQTAh9I/BIKTjc0WqZC0MtTZ4T8ZFU69K3NcwdZpGm5lmY1rAhGCjZeZ3ROxX tc4bunUXsZyq0xPFXkTKphi1vPWucyNCFTGSfeYB4mLgOYimjj/vSdED4UboXw== From: Josselin Poiret To: Tobias Geerinckx-Rice Subject: [PATCH v2 3/4] gnu: system: Filter out boot dependencies from swap-space. Date: Wed, 27 Oct 2021 15:09:12 +0000 Message-Id: <20211027150913.6038-4-dev@jpoiret.xyz> In-Reply-To: <20211027150913.6038-1-dev@jpoiret.xyz> References: <87tuh6ifwe.fsf@nckx> <20211027150913.6038-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/systems.scm (swap-services): Filter them. --- gnu/system.scm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gnu/system.scm b/gnu/system.scm index 2797c07e36..e3accb3c1e 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -586, 7 +586, 23 @@ (define (device-mapping-services os) Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/systems.scm (swap-services): Filter them. --- gnu/system.scm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gnu/system.scm b/gnu/system.scm index 2797c07e36..e3accb3c1e 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -586,7 +586,23 @@ (define (device-mapping-services os) Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * gnu/systems.scm (swap-services): Filter them. --- gnu/system.scm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gnu/system.scm b/gnu/system.scm index 2797c07e36..e3accb3c1e 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -586,7 +586,23 @@ (define (device-mapping-services os) (define (swap-services os) "Return the list of swap services for OS." - (map swap-service (operating-system-swap-devices os))) + (define early-userspace-file-systems + (filter file-system-needed-for-boot? + (operating-system-file-systems os))) + + (define early-userspace-mapped-devices + (operating-system-boot-mapped-devices os)) + + (define (filter-deps swap) + (swap-space + (inherit swap) + (dependencies (remove (lambda (dep) + (or (member dep early-userspace-mapped-devices) + (member dep early-userspace-file-systems))) + (swap-space-dependencies swap))))) + + (map (compose swap-service filter-deps) + (operating-system-swap-devices os))) (define* (system-linux-image-file-name #:optional (target (or (%current-target-system) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 27 11:09:49 2021 Received: (at 51346) by debbugs.gnu.org; 27 Oct 2021 15:09:49 +0000 Received: from localhost ([127.0.0.1]:50194 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYm-0000OV-SB for submit@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:49 -0400 Received: from jpoiret.xyz ([206.189.101.64]:34926) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfkYk-0000OE-K4 for 51346@debbugs.gnu.org; Wed, 27 Oct 2021 11:09:47 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id C0165184BC9; Wed, 27 Oct 2021 15:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1635347386; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HOBTRR4VEZuK6wFDIvJ78aYavptxQsPFfAQpJXLvRgY=; b=s+LMKR9ZN/4aMLJJ3i1AsdICalJtaO56X4a4rW/B2Mc4pRZ6AWbq0RdTwn4NMY2l5WAcX4 dphT6etsQYswcSNjSX2pH5/zAUYMghMjAICZbfJEeMhgYw1J6eEFLPPgrkSk+lWRHmU37Y ZBtOLu2Cfz5c79SvVNGzZIFvUmt6RybnyPoYvsTV8P5H9VQZQEHAbRbGiUYz41MggkqTsF N1p6LDkXa8m9/btL/q8WU18yCoc8Ur+SbnWFA1qWhGok6an1GI2slGXWQK7U+s0jwjdNRT Ch0WVlMEhkG1BW/p4pSgVD/sSPLp+c4WnwkDj8SrDubKWO9I+E9DBUMV60vVxA== From: Josselin Poiret To: Tobias Geerinckx-Rice Subject: [PATCH v2 4/4] doc: Add new Swap Space section. Date: Wed, 27 Oct 2021 15:09:13 +0000 Message-Id: <20211027150913.6038-5-dev@jpoiret.xyz> In-Reply-To: <20211027150913.6038-1-dev@jpoiret.xyz> References: <87tuh6ifwe.fsf@nckx> <20211027150913.6038-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * doc/guix.texi (operating-system Reference): Update swap-devices. * doc/guix.texi (Swap Space): Add it. * gnu/system/examples/desktop.tmpl: Add swap-devices example. --- doc/guix.texi | 136 +++++++++ [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * doc/guix.texi (operating-system Reference): Update swap-devices. * doc/guix.texi (Swap Space): Add it. * gnu/system/examples/desktop.tmpl: Add swap-devices example. --- doc/guix.texi | 136 +++++++++ [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * doc/guix.texi (operating-system Reference): Update swap-devices. * doc/guix.texi (Swap Space): Add it. * gnu/system/examples/desktop.tmpl: Add swap-devices example. --- doc/guix.texi | 136 ++++++++++++++++++++++--------- gnu/system/examples/desktop.tmpl | 7 +- 2 files changed, 105 insertions(+), 38 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 67a05a10ff..2cf30536fe 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -319,6 +319,7 @@ System Configuration * operating-system Reference:: Detail of operating-system declarations. * File Systems:: Configuring file system mounts. * Mapped Devices:: Block device extra processing. +* Swap Space:: Backing RAM with disk space. * User Accounts:: Specifying user accounts. * Keyboard Layout:: How the system interprets key strokes. * Locales:: Language and cultural convention settings. @@ -2515,10 +2516,9 @@ system relative to this path. If you have opted for @file{/boot/efi} as an EFI mount point for example, mount it at @file{/mnt/boot/efi} now so it is found by @code{guix system init} afterwards. -Finally, if you plan to use one or more swap partitions (@pxref{Memory -Concepts, swap space,, libc, The GNU C Library Reference Manual}), make -sure to initialize them with @command{mkswap}. Assuming you have one -swap partition on @file{/dev/sda3}, you would run: +Finally, if you plan to use one or more swap partitions (@pxref{Swap +Space}), make sure to initialize them with @command{mkswap}. Assuming +you have one swap partition on @file{/dev/sda3}, you would run: @example mkswap /dev/sda3 @@ -13769,6 +13769,7 @@ instance to support new system services. * operating-system Reference:: Detail of operating-system declarations. * File Systems:: Configuring file system mounts. * Mapped Devices:: Block device extra processing. +* Swap Space:: Backing RAM with disk space. * User Accounts:: Specifying user accounts. * Keyboard Layout:: How the system interprets key strokes. * Locales:: Language and cultural convention settings. @@ -13937,7 +13938,7 @@ configuration, but with a few modifications. @cindex encrypted disk The configuration for a typical ``desktop'' usage, with an encrypted -root partition, the X11 display +root partition, a swap file on the root partition, the X11 display server, GNOME and Xfce (users can choose which of these desktop environments to use at the log-in screen by pressing @kbd{F1}), network management, power management, and more, would look like this: @@ -14135,38 +14136,9 @@ A list of mapped devices. @xref{Mapped Devices}. @item @code{file-systems} A list of file systems. @xref{File Systems}. -@cindex swap devices -@cindex swap space @item @code{swap-devices} (default: @code{'()}) -A list of UUIDs, file system labels, or strings identifying devices or -files to be used for ``swap -space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference -Manual}). Here are some examples: - -@table @code -@item (list (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")) -Use the swap partition with the given UUID@. You can learn the UUID of a -Linux swap partition by running @command{swaplabel @var{device}}, where -@var{device} is the @file{/dev} file name of that partition. - -@item (list (file-system-label "swap")) -Use the partition with label @code{swap}. Again, the -@command{swaplabel} command allows you to view and change the label of a -Linux swap partition. - -@item (list "/swapfile") -Use the file @file{/swapfile} as swap space. - -@item (list "/dev/sda3" "/dev/sdb2") -Use the @file{/dev/sda3} and @file{/dev/sdb2} partitions as swap space. -We recommend referring to swap devices by UUIDs or labels as shown above -instead. -@end table - -It is possible to specify a swap file in a file system on a mapped -device (under @file{/dev/mapper}), provided that the necessary device -mapping and file system are also specified. @xref{Mapped Devices} and -@ref{File Systems}. +@cindex swap devices +A list of swap spaces. @xref{Swap Space}. @item @code{users} (default: @code{%base-user-accounts}) @itemx @code{groups} (default: @code{%base-groups}) @@ -14756,7 +14728,8 @@ It is also desirable to encrypt swap space, since swap space may contain sensitive data. One way to accomplish that is to use a swap file in a file system on a device mapped via LUKS encryption. In this way, the swap file is encrypted because the entire device is encrypted. -@xref{Preparing for Installation,,Disk Partitioning}, for an example. +@xref{Swap Space}, or @xref{Preparing for Installation,,Disk +Partitioning}, for an example. A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1} may be declared as follows: @@ -14788,6 +14761,95 @@ Devices @file{/dev/mapper/vg0-alpha} and @file{/dev/mapper/vg0-beta} can then be used as the @code{device} of a @code{file-system} declaration (@pxref{File Systems}). +@node Swap Space +@section Swap Space +@cindex swap space + +Swap space, as it is commonly called, is a disk area specifically +designated for paging: the process in charge of memory management +(the Linux kernel or Hurd's default pager) can decide that some memory +pages stored in RAM which belong to a running program but are unused +should be stored on disk instead. It unloads those from the RAM, +freeing up precious fast memory, and writes them to the swap space. If +the program tries to access that very page, the memory management +process loads it back into memory for the program to use. + +A common misconception about swap is that it is only useful when small +amounts of RAM are available to the system. However, it should be noted +that kernels often use all available RAM for disk access caching to make +I/O faster, and thus paging out unused portions of program memory will +expand the RAM available for such caching. + +For a more detailed description of how memory is managed from the +viewpoint of a monolithic kernel, @xref{Memory +Concepts,,, libc, The GNU C Library Reference Manual}. + +The Linux kernel has support for swap partitions and swap files: the +former uses a whole disk partition for paging, whereas the second uses a +file on a file system for that (the file system driver needs to support +it). On a comparable setup, both have the same performance, so one +should consider ease of use when deciding between them. Partitions are +``simpler'' and do not need file system support, but need to be +allocated at disk formatting time (logical volumes notwithstanding), +whereas files can be allocated and deallocated at any time. + +Note that swap space is not zeroed on shutdown, so sensitive data (such +as passwords) may linger on it if it was paged out. As such, you should +consider having your swap reside on an encrypted device (@pxref{Mapped +Devices}). + +@deftp {Data Type} swap-space +Objects of this type represent swap spaces. They contain the following +members: + +@table @asis +@item @code{target} +The device or file to use, either a UUID, a @code{file-system-label} or +a string, as in the definition of a @code{file-system} (@pxref{File +Systems}). + +@item @code{dependencies} (default: @code{'()}) +A list of @code{file-system} or @code{mapped-device} objects, upon which +the availability of the space depends. Note that just like for +@code{file-system} objects, dependencies which are needed for boot and +mounted in early userspace are not managed by the Shepherd, and so +automatically filtered out for you. + +@item @code{priority} (default: @code{#f}) +Only supported by the Linux kernel. Either @code{#f} to disable swap +priority, or an integer between 0 and 32767. The kernel will first use +swap spaces of higher priority when paging, and use same priority spaces +on a round-robin basis. The kernel will use swap spaces without a set +priority after prioritized spaces, and in the order that they appeared in +(not round-robin). + +@item @code{discard?} (default: @code{#f}) +Only supported by the Linux kernel. When true, the kernel will notify +the disk controller of discarded pages, for example with the TRIM +operation on Solid State Drives. + +@end table +@end deftp + +Here are some examples: + +@table @code +@item (swap-space (target (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb"))) +Use the swap partition with the given UUID@. You can learn the UUID of a +Linux swap partition by running @command{swaplabel @var{device}}, where +@var{device} is the @file{/dev} file name of that partition. + +@item (swap-space (target (file-system-label "swap")) (dependencies (list lvm-device))) +Use the partition with label @code{swap}, which can be found after the +@var{lvm-device} mapped device has been opened. Again, the +@command{swaplabel} command allows you to view and change the label of a +Linux swap partition. + +@item (swap-space (target "/btrfs/swapfile") (dependencies (list btrfs-fs))) +Use the file @file{/btrfs/swapfile} as swap space, which is present on the +@var{btrfs-fs} filesystem. +@end table + @node User Accounts @section User Accounts diff --git a/gnu/system/examples/desktop.tmpl b/gnu/system/examples/desktop.tmpl index c928008c92..93c35a03bc 100644 --- a/gnu/system/examples/desktop.tmpl +++ b/gnu/system/examples/desktop.tmpl @@ -1,6 +1,6 @@ ;; This is an operating system configuration template ;; for a "desktop" setup with GNOME and Xfce where the -;; root partition is encrypted with LUKS. +;; root partition is encrypted with LUKS, and a swap file. (use-modules (gnu) (gnu system nss)) (use-service-modules desktop xorg) @@ -42,6 +42,11 @@ (type "vfat"))) %base-file-systems)) + ;; Specify a swap file for the system, which resides on the + ;; root file system. + (swap-devices (list (swap-space + (target "/swapfile")))) + ;; Create user `bob' with `alice' as its initial password. (users (cons (user-account (name "bob") -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 05:56:51 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 10:56:51 +0000 Received: from localhost ([127.0.0.1]:52750 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmZfP-0007lK-Jn for submit@debbugs.gnu.org; Mon, 15 Nov 2021 05:56:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53280) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmZfN-0007l4-83 for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 05:56:50 -0500 Received: from [2001:470:142:3::e] (port=57764 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmZfH-0004a8-RN; Mon, 15 Nov 2021 05:56:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=8GZuKzZwievXqcjurAx0mOU9y22nRYsncZXwr/n4+sg=; b=LYo0aB+7S8HcxtZ5rIJA cOVWR/44C7DTX5yd+kq2OQapc1Ej3jtnPgKtQAKs3Grr1URk6NDIIWl3izC9vYZ7G27rRaMTmLoyT Xk5205mH+4wlMoorOlxUs7XRgCOhdFrHMIiGYEv9UYLlvSuyns3sD182SizlBeT12VFakLPAz7NPg niPyRpQEv8WX+owOZHfaxprwEvUR5xqKKiuY2InS9XZsyrgm2k8Q0yVO9yoJkuWP7z6ElgDYCsX3U cntEh71lhIH0U6ebObOklAbeoNp8xal0+insBCUrvWTXl0lZB4HNv/1NI/FPkQ/shfo7FjR7h9DFw nBlFqn1njJb1cA==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=41724 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmZfH-00075b-Iu; Mon, 15 Nov 2021 05:56:43 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Josselin Poiret Subject: Re: bug#51346: [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags References: <87tuh6ifwe.fsf@nckx> <20211027150913.6038-1-dev@jpoiret.xyz> <20211027150913.6038-2-dev@jpoiret.xyz> Date: Mon, 15 Nov 2021 11:56:40 +0100 In-Reply-To: <20211027150913.6038-2-dev@jpoiret.xyz> (Josselin Poiret's message of "Wed, 27 Oct 2021 15:09:10 +0000") Message-ID: <87ee7h7klz.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.3 (/) X-Debbugs-Envelope-To: 51346 Cc: Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Hi, Josselin Poiret skribis: > * gnu/system/file-systems.scm (swap-space): Add it. > * gnu/system.scm (operating-system)[swap-devices]: Update comment. > * gnu/services/base.scm (swap-space->shepherd-service-name, > swap-deprecated->shepherd-service-name, swap->shepherd-service-name): > Add them. > * gnu/services/base.scm (swap-service-type, swap-service): Use the new > records. Nice, LGTM! I would tend to merge the doc patch (#4) with this one, but not big deal. Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 05:59:45 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 10:59:45 +0000 Received: from localhost ([127.0.0.1]:52755 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmZiD-0007ps-1M for submit@debbugs.gnu.org; Mon, 15 Nov 2021 05:59:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53808) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmZiB-0007pg-4R for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 05:59:43 -0500 Received: from [2001:470:142:3::e] (port=57818 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmZi5-0004p8-RP; Mon, 15 Nov 2021 05:59:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=iEKQKWfl2HYHi+Q7CI4Ni5euyODtEBhM3P8Wiujf5lI=; b=b//z4j4b/V6h/LvAS2XU 8jBwc/H1w6l2uHXDttkgbF9qXmiXj/BnTfyPTq28TifiBbhBz5gUFdrAvfvDXJO4Ao/4mG2pyY2sF VLM0Lym84T4UkM1wwHLshWkQNWVGSejuh3gg1xtIRxMGlI0AyJEcigHMva3odyfYl4PcHHAVdu+PT fujWdG82K3GbJTwU2nzJcAxH2e9xCnvuhIuB/aG2niT92UEle64IUsVMQEveZNBAapoGMlPv/V4Uw N0Ui42lx50x7+FBTJ7+arAPwbwb6rGOHh1yZeuia0JTwpHEqT13rnPtSl5BhBvEyjdVNhAGd7+5tM Uq1V5zvpEGgbmQ==; Received: from [193.50.110.110] (port=57552 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmZi5-0007RU-F5; Mon, 15 Nov 2021 05:59:37 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Josselin Poiret Subject: Re: bug#51346: [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags References: <87tuh6ifwe.fsf@nckx> <20211027150913.6038-1-dev@jpoiret.xyz> <20211027150913.6038-3-dev@jpoiret.xyz> Date: Mon, 15 Nov 2021 11:59:35 +0100 In-Reply-To: <20211027150913.6038-3-dev@jpoiret.xyz> (Josselin Poiret's message of "Wed, 27 Oct 2021 15:09:11 +0000") Message-ID: <878rxp7kh4.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.3 (/) X-Debbugs-Envelope-To: 51346 Cc: Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Josselin Poiret skribis: > * gnu/system/file-systems.scm (swap-space)[priority, discard?]: Add > them. > * guix/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK, > SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add them. > * gnu/build/file-systems.scm (swap-space->flags-bit-mask): Add it. > * gnu/services/base.scm (swap-service-type): Use it. [...] > (let ((device #$device-lookup)) > (and device > (begin > - (restart-on-EINTR (swapon device)) > + (restart-on-EINTR (swapon device > + #$(swap-space->flags-bit-mask > + swap))) Note for later: IWBN to have a =E2=80=98sanitize=E2=80=99 field in that checks the flags, similar to commit 5eb5c0789f34e87ee417a53ddfcfa3b6521bb33= 7. > - swap-space-dependencies)) > + swap-space-dependencies > + swap-space-priority > + swap-space-discard?)) Please don=E2=80=99t use tabs at all in Scheme code. LGTM! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 06:01:26 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 11:01:26 +0000 Received: from localhost ([127.0.0.1]:52776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmZjp-0007vf-VP for submit@debbugs.gnu.org; Mon, 15 Nov 2021 06:01:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54276) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmZjo-0007vT-3o for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 06:01:24 -0500 Received: from [2001:470:142:3::e] (port=57896 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmZji-0005Dj-L7; Mon, 15 Nov 2021 06:01:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=NrTyhEKSsgMtIIvqVh6XYy1SRGQ+j4Y4Cq/je/OJCJQ=; b=EkceEgk8Ab3EIEBT2R2b TzYwKdWOubQBxMq451gsxSjc6pARlChWFfZ4Zbv522elKAzVq82GE70XBWuZeSF7Fix/nQ2nxE0x8 7M+gOHF/Jlgw/jTznwI3x3s4QCNTydMyNOSytsq0Ch3W4tArnR+cKidS7af5kjA3SJJI7jzBK/YA3 dylMPPIha7WkfGWe2eJydqo7vgWiOe3mX2Lve/yfoPezOJrFbCGnFa46lMMLBgMoPN9k1JxDlgkLF lG3C0ulDfD8SPNRWttfWi7/jESCQhdrSL0tqSy1O4PeUNqCoW/VDjeGRBiUgYZHYwZscnRSZvS47Y fYxiP2XxBXWt8g==; Received: from [193.50.110.110] (port=57554 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmZji-0002bx-4E; Mon, 15 Nov 2021 06:01:18 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Josselin Poiret Subject: Re: bug#51346: [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags References: <87tuh6ifwe.fsf@nckx> <20211027150913.6038-1-dev@jpoiret.xyz> <20211027150913.6038-5-dev@jpoiret.xyz> Date: Mon, 15 Nov 2021 12:01:15 +0100 In-Reply-To: <20211027150913.6038-5-dev@jpoiret.xyz> (Josselin Poiret's message of "Wed, 27 Oct 2021 15:09:13 +0000") Message-ID: <874k8d7kec.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.3 (/) X-Debbugs-Envelope-To: 51346 Cc: Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Josselin Poiret skribis: > * doc/guix.texi (operating-system Reference): Update swap-devices. > * doc/guix.texi (Swap Space): Add it. > * gnu/system/examples/desktop.tmpl: Add swap-devices example. [...] > +Here are some examples: > + > +@table @code > +@item (swap-space (target (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb"))) > +Use the swap partition with the given UUID@. You can learn the UUID of a > +Linux swap partition by running @command{swaplabel @var{device}}, where > +@var{device} is the @file{/dev} file name of that partition. > + > +@item (swap-space (target (file-system-label "swap")) (dependencies (lis= t lvm-device))) Could you get rid of the table here, and instead write examples in @lisp blocks? Otherwise LGTM. Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 06:04:33 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 11:04:33 +0000 Received: from localhost ([127.0.0.1]:52781 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmZmr-00080J-Fk for submit@debbugs.gnu.org; Mon, 15 Nov 2021 06:04:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55188) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmZmp-000806-DG for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 06:04:31 -0500 Received: from [2001:470:142:3::e] (port=58022 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmZmk-0005hh-6Q; Mon, 15 Nov 2021 06:04:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=cCimXRk9RYXQWlcsF6NOhb3bMXUbm7x42f5INIJYr0w=; b=frOpF+7aMEe+RgCyZ2vA r+gUv2rSflJOLhCdY+RSAkGWC4UVpePX/nnXHEXRjNUaEOHwbW9gJ861NfqYJbtRdFOYYZ9EeYiE5 jlcL8eHj9zVcqQk2clQ/7i1Wba1f2A4yIGGqsdKEyUbx4wTlzHMwwj+YDLRQEle/NkoO2btNkdKnv c3zOQfysP8KvSo+DNg+EpIm500sFWVXX4voXlWdakXrUX+RQGysB+7rDbgmNbo1I8UYaKTYULptmA J5gipKTCmHyTalJncLy2iG6k9w3aht0w6k0WmgNL0qdnEulcViCmugYXqyTYmUDhwdCJ594oM8my7 pBnntcUJ4XwGQA==; Received: from [193.50.110.110] (port=57556 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmZmj-0001Ys-RY; Mon, 15 Nov 2021 06:04:26 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Josselin Poiret Subject: Re: bug#51346: [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags References: <87tuh6ifwe.fsf@nckx> <20211027150913.6038-1-dev@jpoiret.xyz> <20211027150913.6038-2-dev@jpoiret.xyz> Date: Mon, 15 Nov 2021 12:04:24 +0100 In-Reply-To: <20211027150913.6038-2-dev@jpoiret.xyz> (Josselin Poiret's message of "Wed, 27 Oct 2021 15:09:10 +0000") Message-ID: <87y25p65on.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.3 (/) X-Debbugs-Envelope-To: 51346 Cc: Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Josselin Poiret skribis: > + (lambda (swap) > + (define requirements > + (cond ((swap-space? swap) > + (map dependency->shepherd-service-name > + (swap-space-dependencies swap))) > + ; TODO Remove after deprecation > + ((and (string? swap) (string-prefix? "/dev/mapper/" swap)) > + (list (symbol-append 'device-mapping- > + (string->symbol (basename swap))))) BTW, shouldn=E2=80=99t we emit a deprecation warning when (string? swap)? If we do, it should contain source location info, as discussed at . The whole series LGTM modulo the minor issues I commented on; could you send a last version? If Tobias agrees, we can apply that last version as soon as we get it. I=E2=80=99d even apply it to =E2=80=98master=E2=80=99; why did you target = =E2=80=98core-updates-frozen=E2=80=99? Thanks! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 15:27:17 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 20:27:17 +0000 Received: from localhost ([127.0.0.1]:56268 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZQ-0008TT-Lq for submit@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:17 -0500 Received: from jpoiret.xyz ([206.189.101.64]:34638) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZO-0008TB-Ki for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:15 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id EC3B5184B88; Mon, 15 Nov 2021 20:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637008033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kDU0e5xGxcuQE2tMMKwxkJx2FP1sP1FJDslz13p8sDM=; b=cgrRaqn6QO6vXy6Pv8Vv7/ZXgHqhQuCFI6N4QUN5Hd3hWUeQoxYrifh/OjAG4+L/k4Gsix hGAXlG7hOIbh1z/1dKDhL5dWcX/9bDwKbEnFOA1ikcY+JPqMTY9naxRlcBU9bri68rdzZV wvFe1MUksUgTPwd14eOFJ+tMfuGXrDphF7uQdHoRxSXgpS6ic1RkLf/6FqpuNwVst7Apaa XlmnnRiDJ3Px67WXxxC/oVCUVoyiKz2SjvJswQv74IMFZb0nYnp86pxJ2DOnq5i9B5OjVh UnD4JLLQzmBaYIx71HCAO+RvapgL4I3W//B5eaMBsgvUJtlSuhJ/v7Z1TtVYsw== From: Josselin Poiret To: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Subject: [PATCH v3 0/5] Rework swap device to add dependencies and flags Date: Mon, 15 Nov 2021 20:26:26 +0000 Message-Id: <20211115202631.6032-1-dev@jpoiret.xyz> In-Reply-To: <87y25p65on.fsf_-_@gnu.org> References: <87y25p65on.fsf_-_@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++ Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Level: **** X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hello Tobias and Ludovic, Thanks for the review! Here is hopefully the last patchset, which addresses most of the issues. I decided not to merge the doc changes with the first commit as it also describes swap flags, but that's just a matter of taste I suppose. Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hello Tobias and Ludovic, Thanks for the review! Here is hopefully the last patchset, which addresses most of the issues. I decided not to merge the doc changes with the first commit as it also describes swap flags, but that's just a matter of taste I suppose. Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager Hello Tobias and Ludovic, Thanks for the review! Here is hopefully the last patchset, which addresses most of the issues. I decided not to merge the doc changes with the first commit as it also describes swap flags, but that's just a matter of taste I suppose. Moved the deprecation warning that I originally put in gnu/services/base.scm (swap-service) to a sanitizer of swap-devices in its own commit, although it only reports the location of the (operating-system) syntax use, not of the field itself (but that is what I also noticed for other deprecation warnings, alas). I marked the field as delayed, otherwise I was getting a lot of warnings while testing rather than the only one I'm getting now. Fixed the swap-device dependency filtering to silently ignore old-style values rather than erroring out. Overall, I cleaned up all the rogue TABs I had inserted! (setq-default indent-tabs-mode nil) for our Emacs readers at home. This should not happen any more as I have set whitespace-mode to an aggressive red highlighting for TAB characters. And finally, I changed the examples at the end to simply be @lisp blocks, outside of a table. Josselin Poiret (5): gnu: system: Rework swap space support, add dependencies. gnu: system: Warn about swap-devices format change gnu: system: Add swap flags. gnu: system: Filter out boot dependencies from swap-space. doc: Add new Swap Space section. doc/guix.texi | 147 +++++++++++++++++++++++-------- gnu/build/file-systems.scm | 36 +++++++- gnu/services/base.scm | 105 +++++++++++++++------- gnu/system.scm | 40 ++++++++- gnu/system/examples/desktop.tmpl | 7 +- gnu/system/file-systems.scm | 24 ++++- guix/build/syscalls.scm | 12 +++ 7 files changed, 294 insertions(+), 77 deletions(-) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 15:27:17 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 20:27:17 +0000 Received: from localhost ([127.0.0.1]:56270 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZR-0008Tb-26 for submit@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:17 -0500 Received: from jpoiret.xyz ([206.189.101.64]:34722) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZP-0008TD-GP for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:16 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 3A2DF184F5F; Mon, 15 Nov 2021 20:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637008034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IzP42peC19fRTdv8GnXtbrzlgER2BZhEDkMrqGPFnTI=; b=EvLgiQZf8wleGPDLhTmqhclb2j2O4BkS2AqVQfff4miC7SOo/a2XbxwL9WSFa62wPsPDPo rll6ZFYwp8+6hfmYumvi7bXKSGe4HUoaCI4spHLlo0P1T9cu58pa2QMVTMBVbtvOLS5sct 9D8+7TlFzGGpwVf2rybeB9CnYzuIqtaDKSaXy5sU9DwEf1NQyeRasU4/CwU05DmRqYBZq5 bZjmrCBcjpofcEE8bJxetX8qW9z9BhbfDSHHexMturdjbG/WTa8/TsgZcxdI4eNIPlB6sa tluxOiEaj3jzKOPWA6WFJLX0YiTA5p2jZ7wuaoL3VC53tiSQVY3RO1K3NWLSXQ== From: Josselin Poiret To: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Subject: [PATCH v3 1/5] gnu: system: Rework swap space support, add dependencies. Date: Mon, 15 Nov 2021 20:26:27 +0000 Message-Id: <20211115202631.6032-2-dev@jpoiret.xyz> In-Reply-To: <20211115202631.6032-1-dev@jpoiret.xyz> References: <87y25p65on.fsf_-_@gnu.org> <20211115202631.6032-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system/file-systems.scm (swap-space): Add it. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-space->shepherd-service-name, swap-deprecated->shep [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system/file-systems.scm (swap-space): Add it. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-space->shepherd-service-name, swap-deprecated->shep [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * gnu/system/file-systems.scm (swap-space): Add it. * gnu/system.scm (operating-system)[swap-devices]: Update comment. * gnu/services/base.scm (swap-space->shepherd-service-name, swap-deprecated->shepherd-service-name, swap->shepherd-service-name): Add them. * gnu/services/base.scm (swap-service-type, swap-service): Use the new records. --- gnu/services/base.scm | 98 +++++++++++++++++++++++++------------ gnu/system.scm | 4 +- gnu/system/file-systems.scm | 18 ++++++- 3 files changed, 85 insertions(+), 35 deletions(-) diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 50865055fe..35f38c7e09 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -63,6 +63,8 @@ (define-module (gnu services base) #:use-module (guix records) #:use-module (guix modules) #:use-module ((guix self) #:select (make-config.scm)) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (ice-9 match) @@ -2146,62 +2148,94 @@ (define* (udev-rules-service name rules #:key (groups '())) udev-service-type udev-extension)))))) (service type #f))) +(define (swap-space->shepherd-service-name space) + (let ((target (swap-space-target space))) + (symbol-append 'swap- + (string->symbol + (cond ((uuid? target) + (uuid->string target)) + ((file-system-label? target) + (file-system-label->string target)) + (else + target)))))) + +; TODO Remove after deprecation +(define (swap-deprecated->shepherd-service-name sdep) + (symbol-append 'swap- + (string->symbol + (cond ((uuid? sdep) + (string-take (uuid->string sdep) 6)) + ((file-system-label? sdep) + (file-system-label->string sdep)) + (else + sdep))))) + +(define swap->shepherd-service-name + (match-lambda ((? swap-space? space) + (swap-space->shepherd-service-name space)) + (sdep + (swap-deprecated->shepherd-service-name sdep)))) + (define swap-service-type (shepherd-service-type 'swap - (lambda (device) - (define requirement - (if (and (string? device) - (string-prefix? "/dev/mapper/" device)) - (list (symbol-append 'device-mapping- - (string->symbol (basename device)))) - '())) - - (define (device-lookup device) + (lambda (swap) + (define requirements + (cond ((swap-space? swap) + (map dependency->shepherd-service-name + (swap-space-dependencies swap))) + ; TODO Remove after deprecation + ((and (string? swap) (string-prefix? "/dev/mapper/" swap)) + (list (symbol-append 'device-mapping- + (string->symbol (basename swap))))) + (else + '()))) + + (define device-lookup ;; The generic 'find-partition' procedures could return a partition ;; that's not swap space, but that's unlikely. - (cond ((uuid? device) - #~(find-partition-by-uuid #$(uuid-bytevector device))) - ((file-system-label? device) + (cond ((swap-space? swap) + (let ((target (swap-space-target swap))) + (cond ((uuid? target) + #~(find-partition-by-uuid #$(uuid-bytevector target))) + ((file-system-label? target) + #~(find-partition-by-label + #$(file-system-label->string target))) + (else + target)))) + ; TODO Remove after deprecation + ((uuid? swap) + #~(find-partition-by-uuid #$(uuid-bytevector swap))) + ((file-system-label? swap) #~(find-partition-by-label - #$(file-system-label->string device))) + #$(file-system-label->string swap))) (else - device))) - - (define service-name - (symbol-append 'swap- - (string->symbol - (cond ((uuid? device) - (string-take (uuid->string device) 6)) - ((file-system-label? device) - (file-system-label->string device)) - (else - device))))) + swap))) (with-imported-modules (source-module-closure '((gnu build file-systems))) (shepherd-service - (provision (list service-name)) - (requirement `(udev ,@requirement)) - (documentation "Enable the given swap device.") + (provision (list (swap->shepherd-service-name swap))) + (requirement `(udev ,@requirements)) + (documentation "Enable the given swap space.") (modules `((gnu build file-systems) ,@%default-modules)) (start #~(lambda () - (let ((device #$(device-lookup device))) + (let ((device #$device-lookup)) (and device (begin (restart-on-EINTR (swapon device)) #t))))) (stop #~(lambda _ - (let ((device #$(device-lookup device))) + (let ((device #$device-lookup)) (when device (restart-on-EINTR (swapoff device))) #f))) (respawn? #f)))) (description "Turn on the virtual memory swap area."))) -(define (swap-service device) - "Return a service that uses @var{device} as a swap device." - (service swap-service-type device)) +(define (swap-service swap) + "Return a service that uses @var{swap} as a swap space." + (service swap-service-type swap)) (define %default-gpm-options ;; Default options for GPM. diff --git a/gnu/system.scm b/gnu/system.scm index 17653682c5..fd556e1e7c 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -233,8 +233,8 @@ (define-record-type* operating-system (mapped-devices operating-system-mapped-devices ; list of (default '())) (file-systems operating-system-file-systems) ; list of fs - (swap-devices operating-system-swap-devices ; list of strings - (default '())) + (swap-devices operating-system-swap-devices ; list of string | + (default '()) (users operating-system-users ; list of user accounts (default %base-user-accounts)) diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm index c6c1b96d16..027df7e966 100644 --- a/gnu/system/file-systems.scm +++ b/gnu/system/file-systems.scm @@ -97,7 +97,12 @@ (define-module (gnu system file-systems) %store-mapping %network-configuration-files - %network-file-mappings)) + %network-file-mappings + + swap-space + swap-space? + swap-space-target + swap-space-dependencies)) ;;; Commentary: ;;; @@ -712,4 +717,15 @@ (define (prepend-slash/maybe s) (G_ "Use the @code{subvol} Btrfs file system option.")))))))) +;;; +;;; Swap space +;;; + +(define-record-type* swap-space make-swap-space + swap-space? + this-swap-space + (target swap-space-target) + (dependencies swap-space-dependencies + (default '()))) + ;;; file-systems.scm ends here -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 15:27:22 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 20:27:22 +0000 Received: from localhost ([127.0.0.1]:56278 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZV-0008U9-Pe for submit@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:22 -0500 Received: from jpoiret.xyz ([206.189.101.64]:34832) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZQ-0008TS-HR for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:16 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 79517184F65; Mon, 15 Nov 2021 20:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637008036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5KPq/s8cDPllOM96phVS0nOUo3h4Y/GEW13rRcHTK0Y=; b=rOp+EV+CphzU1Af6QPGO0MbSwbv26j9T5IeHnBfa25mk1SRWJIqfgEfdSdD+WvSl0pv6SG Rm+yjXBRJZHQKhyZjNMFeOE2iCnMud4/mxDrMY7aIcD4Gmr+rxK1RZ6hbFaHpOy1rEd35q AEMTjZcD+wCgc/FvkM43BfRDi3U0OA/CsLffTa827x4UZFZA5i2hR3bLI0JS3/mkvLna9C Na6MPRBl6lVcAJa9NeotjnilXOyg90c07bIH3di08M2D76OvTL/3Om8e0bx0zNxMx3bRMf ZKJjZr8yG90ZEMgeu6j6iTeHdvxyLuDzmJZjsQxodmEnvM4/sOESlrXVqftWJA== From: Josselin Poiret To: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Subject: [PATCH v3 2/5] gnu: system: Warn about swap-devices format change Date: Mon, 15 Nov 2021 20:26:28 +0000 Message-Id: <20211115202631.6032-3-dev@jpoiret.xyz> In-Reply-To: <20211115202631.6032-1-dev@jpoiret.xyz> References: <87y25p65on.fsf_-_@gnu.org> <20211115202631.6032-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system.scm (warn-swap-devices-change, %warn-swap-devices-change): Add them. * gnu/system.scm (operating-system) [swap-devices]: Use it. --- gnu/system.scm | 16 ++++++++++++++++ 1 file changed, 1 [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system.scm (warn-swap-devices-change, %warn-swap-devices-change): Add them. * gnu/system.scm (operating-system) [swap-devices]: Use it. --- gnu/system.scm | 16 ++++++++++++++++ 1 file changed, 1 [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * gnu/system.scm (warn-swap-devices-change, %warn-swap-devices-change): Add them. * gnu/system.scm (operating-system) [swap-devices]: Use it. --- gnu/system.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gnu/system.scm b/gnu/system.scm index fd556e1e7c..76a904b681 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -235,6 +235,8 @@ (define-record-type* operating-system (file-systems operating-system-file-systems) ; list of fs (swap-devices operating-system-swap-devices ; list of string | (default '()) + (delayed) + (sanitize warn-swap-devices-change)) (users operating-system-users ; list of user accounts (default %base-user-accounts)) @@ -583,6 +585,20 @@ (define (device-mapping-services os) (map device-mapping-service (operating-system-user-mapped-devices os))) +(define-syntax-rule (warn-swap-devices-change value) + (%warn-swap-devices-change value (current-source-location))) + +(define (%warn-swap-devices-change value location) + (map (lambda (x) + (unless (swap-space? x) + (warning + (source-properties->location + location) + (G_ "List elements of the field 'swap-devices' should \ +now use the record, as the old method is deprecated. \ +See \"(guix) operating-system Reference\" for more details.~%"))) + x) value)) + (define (swap-services os) "Return the list of swap services for OS." (map swap-service (operating-system-swap-devices os))) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 15:27:22 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 20:27:22 +0000 Received: from localhost ([127.0.0.1]:56280 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZW-0008UB-1W for submit@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:22 -0500 Received: from jpoiret.xyz ([206.189.101.64]:34832) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZR-0008TS-6N for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:17 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 8DA20184F66; Mon, 15 Nov 2021 20:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637008036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dUX1Tii1gMKZg0Uo9K8lh5WP9Ol3D7rTc8lVJ19VY+M=; b=rahSPtyfJiejA8B+hncmGUo37oKt9hgkTEzB6M582CSyEWeZuqOr16PC+mxWRGZWl4Wvxo BZVxxpvr2kojhQPVGGnVQ6Pf+tpUTMCd8WNSYlwSF5ObFT8GCKgJP1+xIu6QCLoIq+/qPZ Iku5lQ/It+YLRDJZ+BaDzWTEhvXWxHxdu/pg+mVaFK62exMp/38acCkSj/WNoZLsOPENJg 3Og/aUfF/5NNAjaUGYk27FXlyNHNMMrBVvcN9dAhIRfN1wd6ZW5Cwh+eGG3C2aipdpKhqF ErcygfwxJXuzGBaMAx59BafVbvWo+KK9dheBnJHOjRwXJntNg8vewTK7hQgyMw== From: Josselin Poiret To: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Subject: [PATCH v3 3/5] gnu: system: Add swap flags. Date: Mon, 15 Nov 2021 20:26:29 +0000 Message-Id: <20211115202631.6032-4-dev@jpoiret.xyz> In-Reply-To: <20211115202631.6032-1-dev@jpoiret.xyz> References: <87y25p65on.fsf_-_@gnu.org> <20211115202631.6032-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system/file-systems.scm (swap-space)[priority, discard?]: Add them. * guix/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK, SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add them. * gnu/bu [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/system/file-systems.scm (swap-space)[priority, discard?]: Add them. * guix/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK, SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add them. * gnu/bu [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * gnu/system/file-systems.scm (swap-space)[priority, discard?]: Add them. * guix/build/syscalls.scm (SWAP_FLAG_PREFER, SWAP_FLAG_PRIO_MASK, SWAP_FLAG_PRIO_SHIFT, SWAP_FLAG_DISCARD): Add them. * gnu/build/file-systems.scm (swap-space->flags-bit-mask): Add it. * gnu/services/base.scm (swap-service-type): Use it. --- gnu/build/file-systems.scm | 36 +++++++++++++++++++++++++++++++++++- gnu/services/base.scm | 7 +++++-- gnu/system/file-systems.scm | 10 ++++++++-- guix/build/syscalls.scm | 12 ++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index d8a5ddf1e5..d95340df83 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -29,6 +29,8 @@ (define-module (gnu build file-systems) #:use-module (guix build bournish) #:use-module ((guix build syscalls) #:hide (file-system-type)) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (rnrs io ports) #:use-module (rnrs bytevectors) #:use-module (ice-9 match) @@ -54,7 +56,9 @@ (define-module (gnu build file-systems) mount-flags->bit-mask check-file-system - mount-file-system)) + mount-file-system + + swap-space->flags-bit-mask)) ;;; Commentary: ;;; @@ -227,6 +231,36 @@ (define (linux-swap-superblock-volume-name sblock) "Return the label of Linux-swap superblock SBLOCK as a string." (null-terminated-latin1->string (sub-bytevector sblock (+ 1024 4 4 4 16) 16))) + +(define (swap-space->flags-bit-mask swap) + "Return the number suitable for the 'flags' argument of 'mount' +that corresponds to the swap-space SWAP." + (define prio-flag + (let ((p (swap-space-priority swap)) + (max (ash SWAP_FLAG_PRIO_MASK (- SWAP_FLAG_PRIO_SHIFT)))) + (if p + (logior SWAP_FLAG_PREFER + (ash (cond + ((< p 0) + (begin (warning + (G_ "Given swap priority ~a is +negative, defaulting to 0.~%") p) + 0)) + ((> p max) + (begin (warning + (G_ "Limiting swap priority ~a to +~a.~%") + p max) + max)) + (else p)) + SWAP_FLAG_PRIO_SHIFT)) + 0))) + (define delayed-flag + (if (swap-space-discard? swap) + SWAP_FLAG_DISCARD + 0)) + (logior prio-flag delayed-flag)) + ;;; diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 35f38c7e09..20736eb13f 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -58,7 +58,8 @@ (define-module (gnu services base) #:use-module (gnu packages linux) #:use-module (gnu packages terminals) #:use-module ((gnu build file-systems) - #:select (mount-flags->bit-mask)) + #:select (mount-flags->bit-mask + swap-space->flags-bit-mask)) #:use-module (guix gexp) #:use-module (guix records) #:use-module (guix modules) @@ -2223,7 +2224,9 @@ (define device-lookup (let ((device #$device-lookup)) (and device (begin - (restart-on-EINTR (swapon device)) + (restart-on-EINTR (swapon device + #$(swap-space->flags-bit-mask + swap))) #t))))) (stop #~(lambda _ (let ((device #$device-lookup)) diff --git a/gnu/system/file-systems.scm b/gnu/system/file-systems.scm index 027df7e966..e1d1fb72cc 100644 --- a/gnu/system/file-systems.scm +++ b/gnu/system/file-systems.scm @@ -102,7 +102,9 @@ (define-module (gnu system file-systems) swap-space swap-space? swap-space-target - swap-space-dependencies)) + swap-space-dependencies + swap-space-priority + swap-space-discard?)) ;;; Commentary: ;;; @@ -726,6 +728,10 @@ (define-record-type* swap-space make-swap-space this-swap-space (target swap-space-target) (dependencies swap-space-dependencies - (default '()))) + (default '())) + (priority swap-space-priority + (default #f)) + (discard? swap-space-discard? + (default #f))) ;;; file-systems.scm ends here diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index b305133c37..63bd017d1d 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -71,6 +71,11 @@ (define-module (guix build syscalls) mounts mount-points + SWAP_FLAG_PREFER + SWAP_FLAG_PRIO_MASK + SWAP_FLAG_PRIO_SHIFT + SWAP_FLAG_DISCARD + swapon swapoff @@ -685,6 +690,13 @@ (define (mount-points) "Return the mounts points for currently mounted file systems." (map mount-point (mounts))) +;; Pulled from glibc's sysdeps/unix/sysv/linux/sys/swap.h + +(define SWAP_FLAG_PREFER #x8000) ;; Set if swap priority is specified. +(define SWAP_FLAG_PRIO_MASK #x7fff) +(define SWAP_FLAG_PRIO_SHIFT 0) +(define SWAP_FLAG_DISCARD #x10000) ;; Discard swap cluster after use. + (define swapon (let ((proc (syscall->procedure int "swapon" (list '* int)))) (lambda* (device #:optional (flags 0)) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 15:27:22 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 20:27:22 +0000 Received: from localhost ([127.0.0.1]:56282 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZW-0008UJ-FH for submit@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:22 -0500 Received: from jpoiret.xyz ([206.189.101.64]:35100) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZS-0008Tu-8k for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:18 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 6CBE0184F67; Mon, 15 Nov 2021 20:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637008037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EHYoelUGo2Gf5whnyHK/Ud0HFS1RNHHMUgEymPzenJQ=; b=VJX8Gvn5sagFGAVlqTVzltqO7mjr0xKzDJnsRO2c4lU6OxAm7nom99tHeJQd1xwsHqvB5a bjWq6tBZx2N1u8ATuBIro86hqZU99AzGKw2aTGcKyq1HwcOxxra7BSDlnTSCsah/Gl4zld Phd+nm+W6R/FhSuCpDsnCsTRZ804GAfZ7UWP7HWlaSkLoS9ZQnaVYyAxDRao/bSQi+jKgD +mgG34+4zy1Zyzhc+9sn2X8iq+USFcW67sggX0KIs9U/vOPMa1Rf15wnLpJrWi4bmQfyCf 95FE2rnKDzklIVPk3bVmu9G40ScggVVUfK6Vf8e2pnLKw4bNEQBt5vJePfmWHQ== From: Josselin Poiret To: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Subject: [PATCH v3 4/5] gnu: system: Filter out boot dependencies from swap-space. Date: Mon, 15 Nov 2021 20:26:30 +0000 Message-Id: <20211115202631.6032-5-dev@jpoiret.xyz> In-Reply-To: <20211115202631.6032-1-dev@jpoiret.xyz> References: <87y25p65on.fsf_-_@gnu.org> <20211115202631.6032-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/systems.scm (swap-services): Filter them. --- gnu/system.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gnu/system.scm b/gnu/system.scm index 76a904b681..03fb55db15 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -601, 7 +601, 25 @@ (define (%warn-swap-devices-change value location) Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * gnu/systems.scm (swap-services): Filter them. --- gnu/system.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gnu/system.scm b/gnu/system.scm index 76a904b681..03fb55db15 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -601,7 +601,25 @@ (define (%warn-swap-devices-change value location) Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * gnu/systems.scm (swap-services): Filter them. --- gnu/system.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gnu/system.scm b/gnu/system.scm index 76a904b681..03fb55db15 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -601,7 +601,25 @@ (define (%warn-swap-devices-change value location) (define (swap-services os) "Return the list of swap services for OS." - (map swap-service (operating-system-swap-devices os))) + (define early-userspace-file-systems + (filter file-system-needed-for-boot? + (operating-system-file-systems os))) + + (define early-userspace-mapped-devices + (operating-system-boot-mapped-devices os)) + + (define (filter-deps swap) + (if (swap-space? swap) + (swap-space + (inherit swap) + (dependencies (remove (lambda (dep) + (or (member dep early-userspace-mapped-devices) + (member dep early-userspace-file-systems))) + (swap-space-dependencies swap)))) + swap)) + + (map (compose swap-service filter-deps) + (operating-system-swap-devices os))) (define* (system-linux-image-file-name #:optional (target (or (%current-target-system) -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 15 15:27:23 2021 Received: (at 51346) by debbugs.gnu.org; 15 Nov 2021 20:27:23 +0000 Received: from localhost ([127.0.0.1]:56284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZW-0008UQ-O6 for submit@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:23 -0500 Received: from jpoiret.xyz ([206.189.101.64]:35210) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmiZT-0008U1-6O for 51346@debbugs.gnu.org; Mon, 15 Nov 2021 15:27:19 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 423E4184B88; Mon, 15 Nov 2021 20:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1637008038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=geye6H3GvUKPXTskGMybTA9Uv/BH0Wc7kK/Xdw2ztxA=; b=fMcZsUabOTGDHBpxNV7/pd4qYIMz6//7aRpebDejX9VVCH9MQr4mqOfwRJ6jj+VEia/4ov absvmeX47RKtevDAYKdehEZZgISyLQi06NntJmzhOe4v/9TJVkz33tiZc0X7rCnOcDoP91 pJ+Ti47cnhGxIO5ggKLU+6M94aaqLe9Detxg15bgnNJ7TE7Srhan1/0Og+iQopEV3kdu7G +lNwemhSuGtJbxLkxw18oPxMNrSg0odh43PnBrQZrd8r7q/MibTvyvSajoi2BNspPQU0DJ uyFkN8in0b6YUck83NYNnOBDvP/4khRKsKiEiJuQdDIM3ydp98JQHLXfU42U8g== From: Josselin Poiret To: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Subject: [PATCH v3 5/5] doc: Add new Swap Space section. Date: Mon, 15 Nov 2021 20:26:31 +0000 Message-Id: <20211115202631.6032-6-dev@jpoiret.xyz> In-Reply-To: <20211115202631.6032-1-dev@jpoiret.xyz> References: <87y25p65on.fsf_-_@gnu.org> <20211115202631.6032-1-dev@jpoiret.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * doc/guix.texi (operating-system Reference): Update swap-devices. * doc/guix.texi (Swap Space): Add it. * gnu/system/examples/desktop.tmpl: Add swap-devices example. --- doc/guix.texi | 147 +++++++++ [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-Debbugs-Envelope-To: 51346 Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.5 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: * doc/guix.texi (operating-system Reference): Update swap-devices. * doc/guix.texi (Swap Space): Add it. * gnu/system/examples/desktop.tmpl: Add swap-devices example. --- doc/guix.texi | 147 +++++++++ [...] Content analysis details: (1.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: jpoiret.xyz (xyz)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager * doc/guix.texi (operating-system Reference): Update swap-devices. * doc/guix.texi (Swap Space): Add it. * gnu/system/examples/desktop.tmpl: Add swap-devices example. --- doc/guix.texi | 147 +++++++++++++++++++++++-------- gnu/system/examples/desktop.tmpl | 7 +- 2 files changed, 116 insertions(+), 38 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 95d286a836..6838a3691f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -320,6 +320,7 @@ System Configuration * operating-system Reference:: Detail of operating-system declarations. * File Systems:: Configuring file system mounts. * Mapped Devices:: Block device extra processing. +* Swap Space:: Backing RAM with disk space. * User Accounts:: Specifying user accounts. * Keyboard Layout:: How the system interprets key strokes. * Locales:: Language and cultural convention settings. @@ -2527,10 +2528,9 @@ system relative to this path. If you have opted for @file{/boot/efi} as an EFI mount point for example, mount it at @file{/mnt/boot/efi} now so it is found by @code{guix system init} afterwards. -Finally, if you plan to use one or more swap partitions (@pxref{Memory -Concepts, swap space,, libc, The GNU C Library Reference Manual}), make -sure to initialize them with @command{mkswap}. Assuming you have one -swap partition on @file{/dev/sda3}, you would run: +Finally, if you plan to use one or more swap partitions (@pxref{Swap +Space}), make sure to initialize them with @command{mkswap}. Assuming +you have one swap partition on @file{/dev/sda3}, you would run: @example mkswap /dev/sda3 @@ -14012,6 +14012,7 @@ instance to support new system services. * operating-system Reference:: Detail of operating-system declarations. * File Systems:: Configuring file system mounts. * Mapped Devices:: Block device extra processing. +* Swap Space:: Backing RAM with disk space. * User Accounts:: Specifying user accounts. * Keyboard Layout:: How the system interprets key strokes. * Locales:: Language and cultural convention settings. @@ -14180,7 +14181,7 @@ configuration, but with a few modifications. @cindex encrypted disk The configuration for a typical ``desktop'' usage, with an encrypted -root partition, the X11 display +root partition, a swap file on the root partition, the X11 display server, GNOME and Xfce (users can choose which of these desktop environments to use at the log-in screen by pressing @kbd{F1}), network management, power management, and more, would look like this: @@ -14378,38 +14379,9 @@ A list of mapped devices. @xref{Mapped Devices}. @item @code{file-systems} A list of file systems. @xref{File Systems}. -@cindex swap devices -@cindex swap space @item @code{swap-devices} (default: @code{'()}) -A list of UUIDs, file system labels, or strings identifying devices or -files to be used for ``swap -space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference -Manual}). Here are some examples: - -@table @code -@item (list (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")) -Use the swap partition with the given UUID@. You can learn the UUID of a -Linux swap partition by running @command{swaplabel @var{device}}, where -@var{device} is the @file{/dev} file name of that partition. - -@item (list (file-system-label "swap")) -Use the partition with label @code{swap}. Again, the -@command{swaplabel} command allows you to view and change the label of a -Linux swap partition. - -@item (list "/swapfile") -Use the file @file{/swapfile} as swap space. - -@item (list "/dev/sda3" "/dev/sdb2") -Use the @file{/dev/sda3} and @file{/dev/sdb2} partitions as swap space. -We recommend referring to swap devices by UUIDs or labels as shown above -instead. -@end table - -It is possible to specify a swap file in a file system on a mapped -device (under @file{/dev/mapper}), provided that the necessary device -mapping and file system are also specified. @xref{Mapped Devices} and -@ref{File Systems}. +@cindex swap devices +A list of swap spaces. @xref{Swap Space}. @item @code{users} (default: @code{%base-user-accounts}) @itemx @code{groups} (default: @code{%base-groups}) @@ -14999,7 +14971,8 @@ It is also desirable to encrypt swap space, since swap space may contain sensitive data. One way to accomplish that is to use a swap file in a file system on a device mapped via LUKS encryption. In this way, the swap file is encrypted because the entire device is encrypted. -@xref{Preparing for Installation,,Disk Partitioning}, for an example. +@xref{Swap Space}, or @xref{Preparing for Installation,,Disk +Partitioning}, for an example. A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1} may be declared as follows: @@ -15031,6 +15004,106 @@ Devices @file{/dev/mapper/vg0-alpha} and @file{/dev/mapper/vg0-beta} can then be used as the @code{device} of a @code{file-system} declaration (@pxref{File Systems}). +@node Swap Space +@section Swap Space +@cindex swap space + +Swap space, as it is commonly called, is a disk area specifically +designated for paging: the process in charge of memory management +(the Linux kernel or Hurd's default pager) can decide that some memory +pages stored in RAM which belong to a running program but are unused +should be stored on disk instead. It unloads those from the RAM, +freeing up precious fast memory, and writes them to the swap space. If +the program tries to access that very page, the memory management +process loads it back into memory for the program to use. + +A common misconception about swap is that it is only useful when small +amounts of RAM are available to the system. However, it should be noted +that kernels often use all available RAM for disk access caching to make +I/O faster, and thus paging out unused portions of program memory will +expand the RAM available for such caching. + +For a more detailed description of how memory is managed from the +viewpoint of a monolithic kernel, @xref{Memory +Concepts,,, libc, The GNU C Library Reference Manual}. + +The Linux kernel has support for swap partitions and swap files: the +former uses a whole disk partition for paging, whereas the second uses a +file on a file system for that (the file system driver needs to support +it). On a comparable setup, both have the same performance, so one +should consider ease of use when deciding between them. Partitions are +``simpler'' and do not need file system support, but need to be +allocated at disk formatting time (logical volumes notwithstanding), +whereas files can be allocated and deallocated at any time. + +Note that swap space is not zeroed on shutdown, so sensitive data (such +as passwords) may linger on it if it was paged out. As such, you should +consider having your swap reside on an encrypted device (@pxref{Mapped +Devices}). + +@deftp {Data Type} swap-space +Objects of this type represent swap spaces. They contain the following +members: + +@table @asis +@item @code{target} +The device or file to use, either a UUID, a @code{file-system-label} or +a string, as in the definition of a @code{file-system} (@pxref{File +Systems}). + +@item @code{dependencies} (default: @code{'()}) +A list of @code{file-system} or @code{mapped-device} objects, upon which +the availability of the space depends. Note that just like for +@code{file-system} objects, dependencies which are needed for boot and +mounted in early userspace are not managed by the Shepherd, and so +automatically filtered out for you. + +@item @code{priority} (default: @code{#f}) +Only supported by the Linux kernel. Either @code{#f} to disable swap +priority, or an integer between 0 and 32767. The kernel will first use +swap spaces of higher priority when paging, and use same priority spaces +on a round-robin basis. The kernel will use swap spaces without a set +priority after prioritized spaces, and in the order that they appeared in +(not round-robin). + +@item @code{discard?} (default: @code{#f}) +Only supported by the Linux kernel. When true, the kernel will notify +the disk controller of discarded pages, for example with the TRIM +operation on Solid State Drives. + +@end table +@end deftp + +Here are some examples: + +@lisp +(swap-space (target (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb"))) +@end lisp + +Use the swap partition with the given UUID@. You can learn the UUID of a +Linux swap partition by running @command{swaplabel @var{device}}, where +@var{device} is the @file{/dev} file name of that partition. + +@lisp +(swap-space + (target (file-system-label "swap")) + (dependencies (list lvm-device))) +@end lisp + +Use the partition with label @code{swap}, which can be found after the +@var{lvm-device} mapped device has been opened. Again, the +@command{swaplabel} command allows you to view and change the label of a +Linux swap partition. + +@lisp +(swap-space + (target "/btrfs/swapfile") + (dependencies (list btrfs-fs))) +@end lisp + +Use the file @file{/btrfs/swapfile} as swap space, which is present on the +@var{btrfs-fs} filesystem. + @node User Accounts @section User Accounts diff --git a/gnu/system/examples/desktop.tmpl b/gnu/system/examples/desktop.tmpl index c928008c92..6df53844b1 100644 --- a/gnu/system/examples/desktop.tmpl +++ b/gnu/system/examples/desktop.tmpl @@ -1,6 +1,6 @@ ;; This is an operating system configuration template ;; for a "desktop" setup with GNOME and Xfce where the -;; root partition is encrypted with LUKS. +;; root partition is encrypted with LUKS, and a swap file. (use-modules (gnu) (gnu system nss)) (use-service-modules desktop xorg) @@ -42,6 +42,11 @@ (type "vfat"))) %base-file-systems)) + ;; Specify a swap file for the system, which resides on the + ;; root file system. + (swap-devices (list (swap-space + (target "/swapfile")))) + ;; Create user `bob' with `alice' as its initial password. (users (cons (user-account (name "bob") -- 2.33.1 From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 23 04:23:41 2021 Received: (at 51346-done) by debbugs.gnu.org; 23 Nov 2021 09:23:41 +0000 Received: from localhost ([127.0.0.1]:49988 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mpS1d-0007OU-4O for submit@debbugs.gnu.org; Tue, 23 Nov 2021 04:23:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mpS1X-0007OC-Jj for 51346-done@debbugs.gnu.org; Tue, 23 Nov 2021 04:23:39 -0500 Received: from [2001:470:142:3::e] (port=39322 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpS1S-0007k8-C0; Tue, 23 Nov 2021 04:23:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=hSV29mN02cMuhNyE+p0cv2bK8p+lrGRTcTbGawRNc5w=; b=qHCZ29G0MUt9G+TU0CIV /BGO1cHqePvciMjyAR0lSkBCIf7cZ3oMq9QX1qpv1I048oFu34+mm5WSCa9qSevEwG7R92mrc3/lQ LPRysqWmEFEgHiXRt7z4cXk4H2nM1wUmBUEwRquIfyvEMp+H5Y1tWcdM0JHC1GxZpME/sw3mfb+jF 47NeE1QaGToCpcQWWGYHTlkeod8lDBxYSDwAfCHTIovw6L0T3K9G8by7w5J2fbj8qo9R6gAW3LRNj rTL06/v6e/JP1LvGkd65rHspKZTqfmTO/JtxYOxT7sdAeTNp34UMJq8i6fs1dovrkRWArBWDfrQqF BLSSyIzSTiCbXw==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:62055 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpS1S-00008Z-6J; Tue, 23 Nov 2021 04:23:30 -0500 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Josselin Poiret Subject: Re: bug#51346: [PATCH 0/1 core-updates-frozen] Rework swap device to add dependencies and flags References: <87y25p65on.fsf_-_@gnu.org> <20211115202631.6032-1-dev@jpoiret.xyz> Date: Tue, 23 Nov 2021 10:23:27 +0100 In-Reply-To: <20211115202631.6032-1-dev@jpoiret.xyz> (Josselin Poiret's message of "Mon, 15 Nov 2021 20:26:26 +0000") Message-ID: <87r1b7jkds.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.3 (/) X-Debbugs-Envelope-To: 51346-done Cc: Tobias Geerinckx-Rice , 51346-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Hi Josselin, Josselin Poiret skribis: > Thanks for the review! Here is hopefully the last patchset, which > addresses most of the issues. > > I decided not to merge the doc changes with the first commit as it > also describes swap flags, but that's just a matter of taste I > suppose. > > Moved the deprecation warning that I originally put in > gnu/services/base.scm (swap-service) to a sanitizer of swap-devices in > its own commit, although it only reports the location of the > (operating-system) syntax use, not of the field itself (but that is > what I also noticed for other deprecation warnings, alas). I marked > the field as delayed, otherwise I was getting a lot of warnings while > testing rather than the only one I'm getting now. I suppose this can be addressed with this newfangled =E2=80=98define-with-syntax-properties=E2=80=99, right? :-) > Fixed the swap-device dependency filtering to silently ignore > old-style values rather than erroring out. > > Overall, I cleaned up all the rogue TABs I had inserted! > (setq-default indent-tabs-mode nil) for our Emacs readers at home. > This should not happen any more as I have set whitespace-mode to an > aggressive red highlighting for TAB characters. Nice. Note that =E2=80=98.dir-locals.el=E2=80=99 is supposed to set that; = not sure why it didn=E2=80=99t work for you. > And finally, I changed the examples at the end to simply be @lisp > blocks, outside of a table. > > Josselin Poiret (5): > gnu: system: Rework swap space support, add dependencies. > gnu: system: Warn about swap-devices format change > gnu: system: Add swap flags. > gnu: system: Filter out boot dependencies from swap-space. > doc: Add new Swap Space section. Applied on =E2=80=98master=E2=80=99, which I plan to merge into =E2=80=98co= re-updates-frozen=E2=80=99 shortly. Thank you! Ludo=E2=80=99. From unknown Tue Jun 24 05:10:13 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 21 Dec 2021 12:24:08 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator