From patchwork Tue Feb 25 10:23:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Neidhardt X-Patchwork-Id: 20419 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 D77B527BBEA; Tue, 25 Feb 2020 10:24:10 +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.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI 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 ESMTP id 77AAB27BBE4 for ; Tue, 25 Feb 2020 10:24:10 +0000 (GMT) Received: from localhost ([::1]:52004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6XNo-0000ql-Uj for patchwork@mira.cbaines.net; Tue, 25 Feb 2020 05:24:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33728) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6XNj-0000qR-Pi for guix-patches@gnu.org; Tue, 25 Feb 2020 05:24:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6XNi-0005Tb-K9 for guix-patches@gnu.org; Tue, 25 Feb 2020 05:24:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:48480) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6XNi-0005TT-Gh for guix-patches@gnu.org; Tue, 25 Feb 2020 05:24:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1j6XNi-00035D-Da for guix-patches@gnu.org; Tue, 25 Feb 2020 05:24:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#39734] [PATCH] scripts: Emit GC hint if free space is lower than absolute and relative threshold. Resent-From: Pierre Neidhardt Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 25 Feb 2020 10:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39734 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 39734@debbugs.gnu.org Received: via spool by 39734-submit@debbugs.gnu.org id=B39734.158262622111821 (code B ref 39734); Tue, 25 Feb 2020 10:24:02 +0000 Received: (at 39734) by debbugs.gnu.org; 25 Feb 2020 10:23:41 +0000 Received: from localhost ([127.0.0.1]:54453 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j6XNN-00034b-1T for submit@debbugs.gnu.org; Tue, 25 Feb 2020 05:23:41 -0500 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:23745) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j6XNK-00034M-L9 for 39734@debbugs.gnu.org; Tue, 25 Feb 2020 05:23:39 -0500 X-Originating-IP: 92.169.129.147 Received: from bababa.home (lfbn-idf2-1-1315-147.w92-169.abo.wanadoo.fr [92.169.129.147]) (Authenticated sender: mail@ambrevar.xyz) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 2C4D2240010 for <39734@debbugs.gnu.org>; Tue, 25 Feb 2020 10:23:31 +0000 (UTC) From: Pierre Neidhardt Date: Tue, 25 Feb 2020 11:23:30 +0100 Message-Id: <20200225102330.4825-1-mail@ambrevar.xyz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <87lforarw6.fsf@ambrevar.xyz> References: <87lforarw6.fsf@ambrevar.xyz> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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 * guix/scripts.scm (%disk-space-warning-absolute): New variable. (warn-about-disk-space): Test against %disk-space-warning-absolute. Fix error in display-hint due to extraneous 'profile' argument. --- guix/scripts.scm | 65 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/guix/scripts.scm b/guix/scripts.scm index 77cbf12350..7ad1d5194c 100644 --- a/guix/scripts.scm +++ b/guix/scripts.scm @@ -181,32 +181,69 @@ Show what and how will/would be built." (newline (guix-warning-port)))) (define %disk-space-warning - ;; The fraction (between 0 and 1) of free disk space below which a warning - ;; is emitted. - (make-parameter (match (and=> (getenv "GUIX_DISK_SPACE_WARNING") - string->number) - (#f .05) ;5% - (threshold (/ threshold 100.))))) + ;; Return a pair of absolute threshold (number of bytes) and relative + ;; threshold (fraction between 0 and 1) for the free disk space below which + ;; a warning is emitted. + ;; GUIX_DISK_SPACE_WARNING can contain both thresholds. A value in [0;100) + ;; is a relative threshold, otherwise it's absolute. The following + ;; example values are valid: + ;; - 1GiB;10% ;1 GiB absolute, and 10% relative. + ;; - 15G ;15 GiB absolute, and default relative. + ;; - 99% ;99% relative, and default absolute. + ;; - 99 ;Same. + ;; - 100 ;100 absolute, and default relative. + (let* ((default-absolute-threshold (size->number "5GiB")) + (default-relative-threshold 0.05) + (percentage->float (lambda (percentage) + (or (and=> (string->number + (car (string-split percentage #\%))) + (lambda (n) (/ n 100.0))) + default-relative-threshold))) + (size->number* (lambda (size) + (or (false-if-exception (size->number size)) + default-absolute-threshold))) + (absolute? (lambda (size) + (not (or (string-suffix? "%" size) + (false-if-exception (< (size->number size) 100))))))) + (make-parameter + (match (getenv "GUIX_DISK_SPACE_WARNING") + (#f (list default-absolute-threshold + default-relative-threshold)) + (env-string (match (string-split env-string #\;) + ((threshold) + (if (absolute? threshold) + (list (size->number* threshold) + default-relative-threshold) + (list default-absolute-threshold + (percentage->float threshold)))) + ((threshold1 threshold2) + (if (absolute? threshold1) + (list (size->number* threshold1) + (percentage->float threshold2)) + (list (size->number* threshold2) + (percentage->float threshold1)))))))))) (define* (warn-about-disk-space #:optional profile #:key - (threshold (%disk-space-warning))) + (thresholds (%disk-space-warning))) "Display a hint about 'guix gc' if less than THRESHOLD of /gnu/store is -available." +available. +THRESHOLD is a pair of (ABSOLUTE-THRESHOLD RELATIVE-THRESHOLD)." (let* ((stats (statfs (%store-prefix))) (block-size (file-system-block-size stats)) (available (* block-size (file-system-blocks-available stats))) (total (* block-size (file-system-block-count stats))) - (ratio (/ available total 1.))) - (when (< ratio threshold) - (warning (G_ "only ~,1f% of free space available on ~a~%") - (* ratio 100) (%store-prefix)) + (relative-threshold-in-bytes (* total (cadr thresholds))) + (absolute-threshold-in-bytes (* 1024 1024 1024 (car thresholds)))) + (when (< available (min relative-threshold-in-bytes + absolute-threshold-in-bytes)) + (warning (G_ "only ~,1f GiB of free space available on ~a~%") + available (%store-prefix)) (display-hint (format #f (G_ "Consider deleting old profile generations and collecting garbage, along these lines: @example guix gc --delete-generations=1m -@end example\n") - profile))))) +@end example\n")))))) ;;; scripts.scm ends here