From patchwork Mon Nov 15 20:26:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Poiret X-Patchwork-Id: 34511 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D520227BBE3; Mon, 15 Nov 2021 20:28:17 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 481EA27BBE1 for ; Mon, 15 Nov 2021 20:28:17 +0000 (GMT) Received: from localhost ([::1]:58052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmiaO-0007vE-DC for patchwork@mira.cbaines.net; Mon, 15 Nov 2021 15:28:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmiaA-0007f5-S7 for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmiaA-00036w-KD for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmiaA-0008Vl-Gq for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51346] [PATCH v3 1/5] gnu: system: Rework swap space support, add dependencies. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 15 Nov 2021 20:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51346 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org Received: via spool by 51346-submit@debbugs.gnu.org id=B51346.163700803732597 (code B ref 51346); Mon, 15 Nov 2021 20:28:02 +0000 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== 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 X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches X-Patchwork-Original-From: Josselin Poiret via Guix-patches via From: Josselin Poiret X-getmail-retrieved-from-mailbox: Patches * 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 From patchwork Mon Nov 15 20:26:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Poiret X-Patchwork-Id: 34513 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 2985527BBE4; Mon, 15 Nov 2021 20:28:42 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id DAAEF27BBE3 for ; Mon, 15 Nov 2021 20:28:41 +0000 (GMT) Received: from localhost ([::1]:58484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmiam-0008C3-1b for patchwork@mira.cbaines.net; Mon, 15 Nov 2021 15:28:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmiaB-0007fE-8t for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmiaB-000374-0q for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmiaA-0008Vs-TV for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51346] [PATCH v3 2/5] gnu: system: Warn about swap-devices format change Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 15 Nov 2021 20:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51346 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org Received: via spool by 51346-submit@debbugs.gnu.org id=B51346.163700804232626 (code B ref 51346); Mon, 15 Nov 2021 20:28:02 +0000 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== 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 X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches X-Patchwork-Original-From: Josselin Poiret via Guix-patches via From: Josselin Poiret X-getmail-retrieved-from-mailbox: Patches * 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))) From patchwork Mon Nov 15 20:26:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Poiret X-Patchwork-Id: 34510 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 2C26B27BBE3; Mon, 15 Nov 2021 20:28:13 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 36E0527BBE4 for ; Mon, 15 Nov 2021 20:28:12 +0000 (GMT) Received: from localhost ([::1]:57718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmiaJ-0007hc-Dm for patchwork@mira.cbaines.net; Mon, 15 Nov 2021 15:28:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmiaB-0007fM-Ls for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44743) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmiaB-00037A-Dz for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmiaB-0008Vz-9x for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51346] [PATCH v3 3/5] gnu: system: Add swap flags. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 15 Nov 2021 20:28:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51346 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org Received: via spool by 51346-submit@debbugs.gnu.org id=B51346.163700804232634 (code B ref 51346); Mon, 15 Nov 2021 20:28:03 +0000 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== 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 X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches X-Patchwork-Original-From: Josselin Poiret via Guix-patches via From: Josselin Poiret X-getmail-retrieved-from-mailbox: Patches * 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)) From patchwork Mon Nov 15 20:26:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Poiret X-Patchwork-Id: 34512 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 869D427BBE3; Mon, 15 Nov 2021 20:28:18 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5130F27BBE1 for ; Mon, 15 Nov 2021 20:28:18 +0000 (GMT) Received: from localhost ([::1]:58148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmiaP-0007yq-HO for patchwork@mira.cbaines.net; Mon, 15 Nov 2021 15:28:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmiaC-0007fu-3w for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmiaB-00037G-Rs for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmiaB-0008W7-Nv for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51346] [PATCH v3 4/5] gnu: system: Filter out boot dependencies from swap-space. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 15 Nov 2021 20:28:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51346 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org Received: via spool by 51346-submit@debbugs.gnu.org id=B51346.163700804232641 (code B ref 51346); Mon, 15 Nov 2021 20:28:03 +0000 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== 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 X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches X-Patchwork-Original-From: Josselin Poiret via Guix-patches via From: Josselin Poiret X-getmail-retrieved-from-mailbox: Patches * 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) From patchwork Mon Nov 15 20:26:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Poiret X-Patchwork-Id: 34514 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B48BD27BBE3; Mon, 15 Nov 2021 20:28:42 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id C810227BBE1 for ; Mon, 15 Nov 2021 20:28:41 +0000 (GMT) Received: from localhost ([::1]:58564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmian-0008F6-0d for patchwork@mira.cbaines.net; Mon, 15 Nov 2021 15:28:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmiaD-0007hK-IT for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:44745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmiaD-00037U-AT for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmiaC-0008WE-6Z for guix-patches@gnu.org; Mon, 15 Nov 2021 15:28:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51346] [PATCH v3 5/5] doc: Add new Swap Space section. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 15 Nov 2021 20:28:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51346 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: Josselin Poiret , Tobias Geerinckx-Rice , 51346@debbugs.gnu.org Received: via spool by 51346-submit@debbugs.gnu.org id=B51346.163700804332648 (code B ref 51346); Mon, 15 Nov 2021 20:28:04 +0000 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== 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 X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches X-Patchwork-Original-From: Josselin Poiret via Guix-patches via From: Josselin Poiret X-getmail-retrieved-from-mailbox: Patches * 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")