From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id WI/ZJaRpGmQnPAEASxT56A (envelope-from ) for ; Wed, 22 Mar 2023 03:36:20 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id mEwZJaRpGmTHDAAAG6o9tA (envelope-from ) for ; Wed, 22 Mar 2023 03:36:20 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.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 2EE376F70 for ; Wed, 22 Mar 2023 03:36:20 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=OffapvUT; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1679452580; h=from:from:sender:sender: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:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=BDHLQ4N3VNT1moJINXZYg17z5iCfHAX8OlIwd3NOY8Q=; b=G1oAx0hItGK7Brcpr0c2SDI/OuOF9NaEtyCT+x0e0IDEbNkPIL9OCjJOpJRizfSfBl4iMI z6ZWYWDaCEsdpA8TIKne9xdX0Bg799BKC4YHG1VU0qYZ48sX/Y4q1/7sB2rVDUG4QWLyJo dSdPj19ommmSJ5SAHROmAMWT9RfWL24BO/+qz58HV+P/lJc55HwFeRgPAh6rlcFhRafs17 ueDflC/m636ivhPO50fv1q5p/N+MMTNKcYJiLbiTYrdzrgDGfJfw9StdtFrZEehlNOE1bs cQe5lWnh/aa3MAt3Qyl2KxAGzi1yB6urRYcuvti/o7T1Qu+KIbk4mvGi/pAvzw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=OffapvUT; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1679452580; a=rsa-sha256; cv=none; b=LPDB7xJwW9T2SluKl9mDJLttVRHTOlKQcHRsCSzxxM2SvmefxLkJVwC6acquSbYV6kHzZ+ hp1ZOxgjSR/PHKCSaPw5E0m1MoLBsj2OS9Q0fFGwltnYXqIqAro+obtmU75oFMkUKDvN3T Z9MKXm7RP9WXMEaKcpLvGVlGhkSU83n0tvCvppSxwdqtBASoFY2VcLFLOQGYXGL5/PaxTX gtz6IuCXEiCMJqpUzNaCajGvgO8KN1CijQOH8ifBRbd43TIB/DaWhItc9F9f9YPH3hzSkr VSdQZB67M3LhTqFGjsVLzHlEEyCJMpTz502coTmCCPSHeFTdU+ntF0KJPvjueg== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1peoKa-0004dQ-CS; Tue, 21 Mar 2023 22:36:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1peoKY-0004co-KZ for guix-patches@gnu.org; Tue, 21 Mar 2023 22:36:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1peoKY-0006O3-7X for guix-patches@gnu.org; Tue, 21 Mar 2023 22:36:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1peoKX-0007my-VE for guix-patches@gnu.org; Tue, 21 Mar 2023 22:36:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#61964] [PATCH] services: Add fstrim-service-type. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 22 Mar 2023 02:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61964 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Bruno Victal Cc: 61964@debbugs.gnu.org Received: via spool by 61964-submit@debbugs.gnu.org id=B61964.167945252829884 (code B ref 61964); Wed, 22 Mar 2023 02:36:01 +0000 Received: (at 61964) by debbugs.gnu.org; 22 Mar 2023 02:35:28 +0000 Received: from localhost ([127.0.0.1]:33105 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1peoJz-0007lu-VW for submit@debbugs.gnu.org; Tue, 21 Mar 2023 22:35:28 -0400 Received: from mail-qt1-f176.google.com ([209.85.160.176]:40530) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1peoJy-0007lh-Ff for 61964@debbugs.gnu.org; Tue, 21 Mar 2023 22:35:27 -0400 Received: by mail-qt1-f176.google.com with SMTP id x1so21131226qtr.7 for <61964@debbugs.gnu.org>; Tue, 21 Mar 2023 19:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679452520; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=Dim1VUewredpsQMyc1x60cM9U2lQKx0FxTh8xxDlOgk=; b=OffapvUTTu1ryO5hO/AJ/cl4mdr1PmhvJ498zSw5ix13uIIP6Gz6eEAM2/2GmdKCor cEGqiJE1JVaP/kzhNWhpaytvGiMZbhGRSDlQVu0NTXjkXv4X/mRhZYLBpV7dLL0em5wj PNtuDhbFl0ma9Fp6pz1b4pS5RuqPwsSpCKtx6o4RkpDKzav3/kYzGZ11QRhXAwIQxuDC B4Z3U/Lq3NmiOBMLimINpHFi+H0YTs7n3JhIuG7evkH0+ELqRug3hf1cguVoQfyoQcyL bEZNkac84/rqXCgsnTMcd2Xj7EqAVs868ZiB0w6Uu/hLDN4EYps3uLLROnTp7+zOL7bR wciA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679452520; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Dim1VUewredpsQMyc1x60cM9U2lQKx0FxTh8xxDlOgk=; b=fk4zuJAiqG1bcHI73s+KUuRKBy8aA4gsxh4uDQ45b4Fy2NatbzVIqi/C5Byn/E7faz PXYBU+pXXFHvy/HeW8Jv5KuqTimrL588Tom8mJO958E0XYQ32s7N4p6Eh7cZX+NSeR7R BZe93MA43KUsh6XWgmAwGEksf46KIz/VvJDxsWuezXcPUX0FVZ8P9onNQtOTDEfDaNhE Yz1ngk8JOB3ebCfi6Fn+tKrrB7gLgu6C6CLCqPRC+0TVqDHUlkgaq4VfICt686J4A1/N 3msbMnT5kMI1QYmy1ZSuaHbEkhV3ihQKGCxSHc9v99JqXd1G+N08QOg8aIJuqKF5DNHv MF8g== X-Gm-Message-State: AO0yUKVmkf+7auIhTm0xAIO8hNSXPHe3A6u3nxW9+Y3WGKdLJCFfHc6v Lu++Zm8LuqrQrxxadK+48W7rscndwU7cxQ== X-Google-Smtp-Source: AK7set+wBNTJHae39w+QARxB8iStJd+XnYB7vKw8xEb6z3LW5fR6KyqEXiBreVfFRST1yRYWsWM/3g== X-Received: by 2002:ac8:5c85:0:b0:3c0:3d68:540c with SMTP id r5-20020ac85c85000000b003c03d68540cmr3412490qta.65.1679452520567; Tue, 21 Mar 2023 19:35:20 -0700 (PDT) Received: from hurd (dsl-10-130-195.b2b2c.ca. [72.10.130.195]) by smtp.gmail.com with ESMTPSA id o197-20020a3741ce000000b0073b575f3603sm10485140qka.101.2023.03.21.19.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 19:35:20 -0700 (PDT) From: Maxim Cournoyer References: <9fec722b58c87211f019fa702a5c7047577bec64.1677952942.git.mirai@makinata.eu> Date: Tue, 21 Mar 2023 22:35:18 -0400 In-Reply-To: <9fec722b58c87211f019fa702a5c7047577bec64.1677952942.git.mirai@makinata.eu> (Bruno Victal's message of "Sat, 4 Mar 2023 18:03:28 +0000") Message-ID: <87o7olikd5.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: X-Migadu-Queue-Id: 2EE376F70 X-Spam-Score: -2.65 X-Migadu-Spam-Score: -2.65 X-Migadu-Scanner: scn0.migadu.com List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-TUID: 2bobi6ylXFpk Hi! Bruno Victal writes: > * gnu/services/linux.scm (fstrim-service-type): New variable. > (fstrim-mcron-job, serialize-fstrim-configuration) > (fstrim-serialize-list-of-strings, fstrim-serialize-boolean): New procedu= re. > (mcron-time?): New predicate. > (fstrim-configuration): New record. > * doc/guix.texi (Linux Services): Document new fstrim-service-type. Thanks! This looks nice. > --- > doc/guix.texi | 62 +++++++++++++++++++++++ > gnu/services/linux.scm | 109 +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 171 insertions(+) > > diff --git a/doc/guix.texi b/doc/guix.texi > index 74658dbc86..d5a83e387f 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -37436,6 +37436,68 @@ Linux Services > @end table > @end deftp >=20=20 > +@cindex fstrim service > +@cindex solid state drives, periodic trim > +@cindex solid state drives, trim > +@subsubheading fstrim Service > + > +The command @command{fstrim} can be used to discard (or @dfn{trim}) > +unused blocks on a mounted filesystem. Please s/filesystem/file system/, which is the preferred spelling in the GNU project. > + > +@c This was copied from the fstrim manpage, with some texinfo touch-ups. > Texinfo > +@quotation Warning > +Running @command{fstrim} frequently, or even using > +@command{mount -o discard}, might negatively affect the lifetime of > +poor-quality SSD devices. For most desktop and server systems a > +sufficient trimming frequency is once a week. Note that not all devices > +support a queued trim, so each trim command incurs a performance penalty > +on whatever else might be trying to use the disk at the time. > +@end quotation > + > +@defvar fstrim-service-type > +Type for a service that periodically runs @command{fstrim}, whose value = must > +be a @code{} object. The service can be instantia= ted > +in its default configuration with: > + > +@lisp > +(service fstrim-service-type) > +@end lisp > +@end defvar > + > +@c %start of fragment > +@deftp {Data Type} fstrim-configuration > +Available @code{fstrim-configuration} fields are: > + > +@table @asis > +@item @code{package} (default: @code{util-linux}) (type: file-like) > +The package providing @command{fstrim}. > + > +@item @code{schedule} (default: @code{"0 0 * * 0"}) (type: mcron-time) > +Schedule for launching @command{fstrim}. This can be a procedure, a > +list or a string. For additional information, @pxref{Guile Syntax,, Job > +specification, mcron,the mcron manual}. By default this is set to run > +weekly on Sunday at 00:00. pxref is supposed to be used in between parentheses (Parenthetical Cross-Reference); I think you can use just "see: @ref{...}" instead, without parentheses. > +@item @code{listed-in} (default: @code{("/etc/fstab" "/proc/self/mountin= fo")}) (type: maybe-list-of-strings) > +List of files in fstab or kernel mountinfo format. All missing or empty > +files are silently ignored. The evaluation of the list @emph{stops} > +after the first non-empty file. Filesystems with @code{X-fstrim.notrim} File systems > +mount option in fstab are skipped. > + > +@item @code{verbose?} (default: @code{#t}) (type: boolean) > +Verbose execution. > + > +@item @code{quiet-unsupported?} (default: @code{#t}) (type: boolean) > +Suppress error messages if trim operation (ioctl) is unsupported. > + > +@item @code{extra-arguments} (type: maybe-list-of-strings) > +Extra options to append to @command{fstrim} command.@footnote{Run > +@command{man fstrim} for more information.} I think @command is to denote a single command, not a command line (command + arguments); I'd use @samp{man fstrim} instead, and replace the footnote by (see @samp{man fstrim} for more information). > +@end table > +@end deftp > +@c %end of fragment > + > @cindex modprobe > @cindex kernel module loader > @subsubheading Kernel Module Loader Service > diff --git a/gnu/services/linux.scm b/gnu/services/linux.scm > index 60e2093e1d..f5ec5fec48 100644 > --- a/gnu/services/linux.scm > +++ b/gnu/services/linux.scm > @@ -5,6 +5,7 @@ > ;;; Copyright =C2=A9 2021 raid5atemyhomework > ;;; Copyright =C2=A9 2021 B. Wilson > ;;; Copyright =C2=A9 2022 Josselin Poiret > +;;; Copyright =C2=A9 2023 Bruno Victal > ;;; > ;;; This file is part of GNU Guix. > ;;; > @@ -30,12 +31,15 @@ (define-module (gnu services linux) > #:use-module (guix ui) > #:use-module (gnu services) > #:use-module (gnu services base) > + #:use-module (gnu services configuration) > + #:use-module (gnu services mcron) > #:use-module (gnu services shepherd) > #:use-module (gnu packages linux) > #:use-module (srfi srfi-1) > #:use-module (srfi srfi-26) > #:use-module (srfi srfi-34) > #:use-module (srfi srfi-35) > + #:use-module (ice-9 format) > #:use-module (ice-9 match) > #:export (earlyoom-configuration > earlyoom-configuration? > @@ -50,6 +54,16 @@ (define-module (gnu services linux) > earlyoom-configuration-send-notification-command > earlyoom-service-type >=20=20 > + fstrim-configuration > + fstrim-configuration? > + fstrim-configuration-package > + fstrim-configuration-schedule > + fstrim-configuration-listed-in > + fstrim-configuration-verbose? > + fstrim-configuration-quiet-unsupported? > + fstrim-configuration-extra-arguments > + fstrim-service-type > + > kernel-module-loader-service-type >=20=20 > rasdaemon-configuration > @@ -150,6 +164,101 @@ (define earlyoom-service-type > (compose list earlyoom-shepherd-service)))) > (description "Run @command{earlyoom}, the Early OOM daemon."))) >=20=20 > + > +;;; > +;;; fstrim > +;;; > + > +(define (mcron-time? x) > + (or (procedure? x) (string? x) (list? x))) > + > +(define-maybe list-of-strings (prefix fstrim-)) > + > +(define (fstrim-serialize-boolean field-name value) > + (list (format #f "~:[~;--~a~]" value > + ;; drop trailing '?' character Use full sentence for standalone comment (;; Drop [...] character.) > + (string-drop-right (symbol->string field-name) 1)))) > + > +(define (fstrim-serialize-list-of-strings field-name value) > + (list (string-append "--" (symbol->string field-name)) > + #~(string-join '#$value ":"))) > + > +(define-configuration fstrim-configuration > + (package > + (file-like util-linux) > + "The package providing @command{fstrim}." providing the @command{fstrim} command. > + empty-serializer) > + > + (schedule > + (mcron-time "0 0 * * 0") > + "Schedule for launching @command{fstrim}. This can be a procedure, a = list > +or a string. For additional information, @pxref{Guile Syntax,, > +Job specification, mcron, the mcron manual}. By default this is set to r= un > +weekly on Sunday at 00:00." > + empty-serializer) >From here on, the text started to use single sentence spacing. Please make it double sentence spacing. > + ;; fstrim options > + (listed-in > + (maybe-list-of-strings '("/etc/fstab" "/proc/self/mountinfo")) > + ;; XXX: documentation sourced from the fstrim manpage. What is "dirty" about the above comment? I'd just use ;; Note: [...]. > + "List of files in fstab or kernel mountinfo format. All missing or > +empty files are silently ignored. The evaluation of the list @emph{stops} > +after the first non-empty file. Filesystems with @code{X-fstrim.notrim} = mount > +option in fstab are skipped.") File systems. > + > + (verbose? > + (boolean #t) > + "Verbose execution.") > + > + (quiet-unsupported? > + (boolean #t) > + "Suppress error messages if trim operation (ioctl) is unsupported.") > + > + (extra-arguments > + maybe-list-of-strings > + ;; FIXME@GUILE(TEXINFO): @footnote causes errors when calling > + ;; configuration->documentation. > + ;; > Throw to key `parser-error' with args `(#f "Unknown command" foo= tnote)' Please take the time to report the issue upstream (bug-guile@gnu.org) and link to it here. > + "Extra options to append to @command{fstrim} command.@footnote{Run > +@command{man fstrim} for more information.}" > + (lambda (_ value) > + (if (maybe-value-set? value) > + value '()))) > + > + (prefix fstrim-)) > + > +(define (serialize-fstrim-configuration config) > + (concatenate > + (filter list? > + (map (lambda (field) > + ((configuration-field-serializer field) > + (configuration-field-name field) > + ((configuration-field-getter field) config))) > + fstrim-configuration-fields)))) > + > +(define (fstrim-mcron-job config) > + (match-record config (package schedule) > + #~(job > + ;; XXX: The =E2=80=9Cif=E2=80=9D below is to ensure that > + ;; lists are ungexp'd correctly since @var{schedule} > + ;; can be either a procedure, a string or a list. I'd turn the XXX into a 'Note' here as well. XXX is for ugly hacks that should be eventually replaced with something more elegant, when someone finds a way to do so. > + #$(if (list? schedule) > + `(list ,@schedule) > + schedule) > + (lambda () > + (system* #$(file-append package "/sbin/fstrim") > + #$@(serialize-fstrim-configuration config))) > + "fstrim"))) > + > +(define fstrim-service-type > + (service-type > + (name 'fstrim) > + (extensions > + (list (service-extension mcron-service-type > + (compose list fstrim-mcron-job)))) > + (description "Discard unused blocks from filesystems.") I think the main takeaway from my review is this: file systems! Eh. More seriously, thanks, this looks good! --=20 Thanks, Maxim