From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id +DK9A4SrsV6RSQAA0tVLHw (envelope-from ) for ; Tue, 05 May 2020 18:08:04 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id mPxzH4+rsV77AQAAbx9fmQ (envelope-from ) for ; Tue, 05 May 2020 18:08:15 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 12BC5940707 for ; Tue, 5 May 2020 18:08:13 +0000 (UTC) Received: from localhost ([::1]:46092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jW1zJ-0005v8-D3 for larch@yhetil.org; Tue, 05 May 2020 14:08:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jW1z8-0005v2-2O for guix-patches@gnu.org; Tue, 05 May 2020 14:08:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:54065) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jW1z7-00056M-Pq for guix-patches@gnu.org; Tue, 05 May 2020 14:08:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jW1z7-0006qf-JD for guix-patches@gnu.org; Tue, 05 May 2020 14:08:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40927] [PATCH] Allow resume from swap device during boot Resent-From: Jean-Baptiste Note Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 05 May 2020 18:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40927 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Danny Milosavljevic Cc: 40927@debbugs.gnu.org Received: via spool by 40927-submit@debbugs.gnu.org id=B40927.158870205226290 (code B ref 40927); Tue, 05 May 2020 18:08:01 +0000 Received: (at 40927) by debbugs.gnu.org; 5 May 2020 18:07:32 +0000 Received: from localhost ([127.0.0.1]:37378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jW1ye-0006py-Aj for submit@debbugs.gnu.org; Tue, 05 May 2020 14:07:32 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:36732) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jW1yb-0006pj-OK for 40927@debbugs.gnu.org; Tue, 05 May 2020 14:07:30 -0400 Received: by mail-wm1-f68.google.com with SMTP id u127so3380035wmg.1 for <40927@debbugs.gnu.org>; Tue, 05 May 2020 11:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=imEEVfKFPJnSLL4yP/VwGVdvXzz3pc/m3Z2bK8eVIm0=; b=Sx5wp8quWsX4z+DpbFeVDM2HeP6LralgZSUS//kWWf3Ichm4hhTqN253Shv5JnwZmE fidQVdr4UFYodvk/xYzlthDxfFCDY/U/SanTUOnCfuw0MXWIQl3c9Yr2zoQzZnIPVhys zREQ5y7WnwMySj+lkv+PJrdck1LUGHymIr5Tiw5dzbk82ZiWJZ+Z6YOKgcvRSVVgFSNC B6mfAY+i/FBKKhjMvS2BsRJz78qaIrQrYJ7t38LSGE+K0YTmEi1M4OvpHx62OGSFsJgD HyGn9qjucSafmxBPa9uhPEFQd2zjUjlTWBtCCJI+T/KVtryA8Dd2B675rNjm2guTp2XL YzDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=imEEVfKFPJnSLL4yP/VwGVdvXzz3pc/m3Z2bK8eVIm0=; b=Sb4ZULbFWRgWI9tPkn8z9uDrhkQXlPJGd4dZJpSwYovvG4fSLwbZ3hhmTauZrAaBhN Rvy754xMMdRNLQLGf99ma1z09kTlQmYDcbRLyAIZsQLhApUoMm004J+bShEN6lGdNyOs 8w2mO+bteikwtPGcayytJSRpSuzqtiL1MHKETAItYME6bk9a9+UYJosZB1Jx4XH/70I8 aGz1p8adW5rhxNBhNamViUDAXbYgulETcaDVlQ0GtmmxP4ftiXTzX9G2bsGcn8JYYFZR 5zEisZFNhYQTzr1HfgLoOBZyhqsHwFoYox5saMIpl99bJHjl6EcAjCuCId2W5/AsDn69 t5NQ== X-Gm-Message-State: AGi0PuZbS7q/t/DV/UV037/qzXW3B+oaRKmus+Pckm5L3LOuuPSrUrIx vB4EBFR7SaXglifh8cyfTH1RchjJpOw= X-Google-Smtp-Source: APiQypLlvtBu0j/5eFLqdY7ZVewqzfSEalLt3FWyvh6jPUQUfkJqsQxADFmHUf8kZZiAE8CHpX31SA== X-Received: by 2002:a1c:bd89:: with SMTP id n131mr4660419wmf.3.1588702043349; Tue, 05 May 2020 11:07:23 -0700 (PDT) Received: from guixrules ([2a01:e35:2e0b:a6b0:e2ce:c3ff:fe74:cec8]) by smtp.gmail.com with ESMTPSA id 185sm5759238wmc.32.2020.05.05.11.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 11:07:22 -0700 (PDT) From: Jean-Baptiste Note References: <87zhawax60.fsf@m4x.org> <20200501165045.3d845900@scratchpost.org> Date: Tue, 05 May 2020 18:07:15 +0000 In-Reply-To: <20200501165045.3d845900@scratchpost.org> (Danny Milosavljevic's message of "Fri, 1 May 2020 16:50:45 +0200") Message-ID: <87d07ixnl8.fsf@m4x.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: 0.5 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -0.5 (/) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 X-Spam-Score: -2.11 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=Sx5wp8qu; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Scan-Result: default: False [-2.11 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.49572284525585]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:142::/48:c]; R_DKIM_REJECT(1.00)[gmail.com:s=20161025]; HAS_ATTACHMENT(0.00)[]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.12), country: US(-0.00), ip: 2001:470:142::17(-0.50)]; DWL_DNSWL_BLOCKED(0.00)[2001:470:142::17:from]; DKIM_TRACE(0.00)[gmail.com:-]; RCPT_COUNT_TWO(0.00)[2]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; MAILLIST(-0.20)[mailman]; SIGNED_PGP(-2.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_IN_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:+,4:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_FROM(0.00)[larch=yhetil.org]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jean-baptiste.note@m4x.org,guix-patches-bounces@gnu.org]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[m4x.org:email,gnu.org:url,pantherx.org:url,netris.org:email]; MIME_GOOD(-0.20)[multipart/signed,multipart/mixed,text/plain,text/x-patch]; PREVIOUSLY_DELIVERED(0.00)[40927@debbugs.gnu.org]; DMARC_NA(0.00)[m4x.org]; HAS_LIST_UNSUB(-0.01)[]; RCVD_COUNT_SEVEN(0.00)[9]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: d3HChfMhc8UM --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Hi Danny, Thanks for being so guix in answering the original report. Your questions prompted me to take a bit of time before answering. Regarding attribution, i've dug two instances of this patch: https://git.pantherx.org/mirror/guix/commit/af8d58efa05927b24694c87379cccc378f3fdde7 https://issues.guix.gnu.org/issue/37290 https://lists.gnu.org/archive/html/bug-guix/2019-09/msg00017.html Both instances of the patch are given by author Mark H Weaver As you can see there's already an open issue in GUIX regarding resume; i'm sorry i missed that. Maybe for attribution it would make sense for me to resend the patch there; let me know how to proceed. Regarding the patch itself and your questions: - for comparison to the original patch: elogind currently has the configurability required to make the second half of the original patch moot, and I think it would be better to split the work anyways; - i've addressed the reference to swsusp.txt - the resume argument is provided by (in my case) the system definition, so I basically have something like that: #+begin_src scheme (operating-system (kernel-arguments (cons (string-append "modprobe.blacklist=" (comma-separated %redundant-linux-modules)) '("--resume=/dev/sdb3" "quiet")))) #end_src - in order to support this in the GUIX installer, I guess adding such a line in the generated system definition, along with a swap partition, would be sufficient. My knowledge of the workings of the guix installer is null, tough :) - please note that if you have a suspend signature on your swap partition, and fail to resume from it (for instance because of a missing kernel commandline argument...), then shepherd will fail bringing up the swap device, and you will need to handle this situation by hand currently; - My knowledge of the details of swsusp is rather limited: I don't know, for instance, how this would translate in case of a more complex setup of multi-swap devices; - However, it seems very clear from the documentation that a mere resume= argument syntax can trigger specific initialization paths within the kernel itself leading to a resume. I find it better style, ultimately, to properly separate the responsibilities of kernel and initrd, follow the GUIX conventions with a --resume argument. - therefore I propose the following, updated patch, with a more GUIX-like --resume argument; I've tested it on my laptop, which happens to have an encrypted /home partition (but only one swap device). - as far as I can understand the documentation, the swap partition does not have to be as big as the RAM; by default the kernel will strive to make the suspend image 2/5 of the physical RAM, but this can be tuned more aggressively. There's actually less than overhead: some parts of the memory can be discarded (shared MMAPd files, the buffer cache); and even then you can hope compression will reduce the needs. If the swap space is not large enough, suspend will simply fail. This probably raises more issues than it solves, however i'd rather you have the whole picture. Let me know how to proceed; I'm willing to follow-up with other patches to get the feature up to the required standards of quality. Kind regards, Jean-Baptiste --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-linux-boot-Add-support-for-resuming-from-swap-device.patch Content-Transfer-Encoding: quoted-printable Content-Description: updated resume patch From=206cf0833a93bede5fe41e0f126267876fefbb3672 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Note Date: Mon, 27 Apr 2020 20:42:03 +0000 Subject: [PATCH] linux-boot: Add support for resuming from swap device. * gnu/build/linux-boot.scm (resume-from-device): Add function. * gnu/build/linux-boot.scm (boot-system): Add hook calling resume-from-devi= ce if specified on commandline, before mounting any actual disk filesystems. =2D-- gnu/build/linux-boot.scm | 43 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm index 05e833c0c6..2febe61ec1 100644 =2D-- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -357,6 +357,37 @@ the last argument of `mknod'." (compose (cut string=3D? program <>) basename)))) (filter-map string->number (scandir "/proc"))))) =20 +(define (resume-from-device resume-device) + "Resume from hibernation state on RESUME-DEVICE. This *must* happen befo= re +we mount any filesystems on disk. See +linux-libre/Documentation/power/swsusp.txt. Please note that this function +will not return if resume happens successfully, and will return if swap de= vice +does not contain a valid resume signature." + (false-if-exception + (let* ((device-base-name + ;; The base name of the device file, after resolving + ;; symlinks. + (let loop ((file resume-device)) + (match (stat:type (lstat file)) + ('symlink + (let ((target (readlink file))) + (if (string-prefix? "/" target) + (loop target) + (loop (string-append (dirname file) "/" target))))) + (_ (basename file))))) + (major+minor + ;; The major:minor string (e.g. "8:2") corresponding + ;; to the resume device. + (call-with-input-file (string-append "/sys/class/block/" + device-base-name + "/dev") + read-line))) + ;; Write the major:minor string to /sys/power/resume + ;; to attempt resume from hibernation. + (when major+minor + (call-with-output-file "/sys/power/resume" + (cut display major+minor <>)))))) + (define* (mount-root-file-system root type #:key volatile-root? (flags 0) options) "Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROO= T? is @@ -493,9 +524,10 @@ upon error." (call-with-error-handling (lambda () (mount-essential-file-systems) =2D (let* ((args (linux-command-line)) =2D (to-load (find-long-option "--load" args)) =2D (root (find-long-option "--root" args))) + (let* ((args (linux-command-line)) + (to-load (find-long-option "--load" args)) + (root (find-long-option "--root" args)) + (resume-device (find-long-option "--resume" args))) =20 (when (member "--repl" args) (start-repl)) @@ -528,6 +560,11 @@ upon error." (unless (pre-mount) (error "pre-mount actions failed"))) =20 + (when (and resume-device + (file-exists? resume-device) + (file-exists? "/sys/power/resume")) + (resume-from-device resume-device)) + (setenv "EXT2FS_NO_MTAB_OK" "1") =20 (if root =2D-=20 2.26.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEPxcq3dp4FVY5UpckkC0pVsuz75YFAl6xq1MACgkQkC0pVsuz 75aSCg//SmzFeJeO6Z1Tcek0yq1pEsuK0BxFoMBs9Lt269yl3ehZZSj/O8Uu7KO/ FJVDtUU5ge+DaSKW8S9rCUFstdMHkCVRHqK6fA37YGHdjJy5nNCa6JaRHExOfSUP BikygFAerkGu+8q5Y12c3EAC+QLYgntjwIF2tJTqjbZP2JMOhA913rvGyC/Vpqm1 9fMR+pSXHrtYXwUbbAsAeCgPNO3lim7REIAsHG+hjw1aFr20XYgfhr2DOdVA3wz6 2m0f0ycYr9mRyoJcAOrQpv0yXRoC81bECbsYPYHxERhKV5JQ0s9zbGa8teYPzzG/ 6QMuSnAPHYS6lDMOrH2OK7w2LJCQ3gohwJ3Q8AFH8ASau/ETopao4URHUhOsjLnL sE7U8RwAHlUQqC48H4xhX59vAD4OZl0w6bR0RIo367PHAcn5PzXQWgjtcakCo9Pa fS9NKGO/tmie+ngQcv2X7XwM4ecCugtxAZ0Zsdg6GoFxOua3xqRFQiHbXbh55LaL VRa34XKq/WgMFbQSmI1iA2qb/jwXrnIuoxSD9V9W1O9Jgz8YqM5xc68sipmFy0fO aEyT5HYyanYSdcT3h1jjvtV/VUqx7Syfxr6q8UOZyWpGvfEeq4s/D37Xr1Hftyq/ QhGxkcZSmXknuNIRf3in9AgX9BRjy6CZguRs+Zxv7ICEcun7zbY= =Wx+h -----END PGP SIGNATURE----- --==-=-=--