From patchwork Tue May 5 18:07:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Note X-Patchwork-Id: 21906 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 BF47E27BBE3; Tue, 5 May 2020 19:08:21 +0100 (BST) 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,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) by mira.cbaines.net (Postfix) with ESMTP id 2E17A27BBE1 for ; Tue, 5 May 2020 19:08:21 +0100 (BST) Received: from localhost ([::1]:46092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jW1zQ-0005v8-Jp for patchwork@mira.cbaines.net; Tue, 05 May 2020 14:08:20 -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 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" X-getmail-retrieved-from-mailbox: Patches 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 From 6cf0833a93bede5fe41e0f126267876fefbb3672 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-device if specified on commandline, before mounting any actual disk filesystems. --- 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 --- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -357,6 +357,37 @@ the last argument of `mknod'." (compose (cut string=? program <>) basename)))) (filter-map string->number (scandir "/proc"))))) +(define (resume-from-device resume-device) + "Resume from hibernation state on RESUME-DEVICE. This *must* happen before +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 device +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-ROOT? is @@ -493,9 +524,10 @@ upon error." (call-with-error-handling (lambda () (mount-essential-file-systems) - (let* ((args (linux-command-line)) - (to-load (find-long-option "--load" args)) - (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))) (when (member "--repl" args) (start-repl)) @@ -528,6 +560,11 @@ upon error." (unless (pre-mount) (error "pre-mount actions failed"))) + (when (and resume-device + (file-exists? resume-device) + (file-exists? "/sys/power/resume")) + (resume-from-device resume-device)) + (setenv "EXT2FS_NO_MTAB_OK" "1") (if root -- 2.26.2