From nobody Tue Apr 16 20:12:18 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VJwDy5Pdgz5H0GN; Tue, 16 Apr 2024 20:12:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VJwDy2w7tz4s8X; Tue, 16 Apr 2024 20:12:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=akmL2pu6fbe2KLiiJdLSlckCrjdD+/4Gk3aSsddDCQ4=; b=SJbeTqypCEwdGmtmGvNljMLyP7O6DBTNYJURxlVHFciWzWVmikSl7uo9fGBxWLIYPkf1Pi vbIX2VEB79ARAeoqae0zqXwkJDsIIr3Tyyiswml36hPt0+Lw9BN4zASh4MdFP2wxb1dU4T n0uCvsRe7gezLZbqTDGGod6CG04PG/ELd8S3pYfki7U2BlAQDxINbHS5I+A8MRoUW+BwS5 C5iRmpynjjfI3BKTefNTWyNGsjttKB5w0kXj+WJwsyfmvMjmUBKv+T6FnrpVdYsUy3K0TX R46VW7qjpLmZMJu6ccUc8d1uzckxLAZlEF3tNjul/s6TM7RH1A6/kRjS/tkwsg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713298338; a=rsa-sha256; cv=none; b=VWZHMIFyKHfhDBtJQEOjlUN11D2+/kuiGNNVaOcNRbV5QI3O7m46Flp+dY6ogFEn3uaBQ8 fjbDpR7c5jcbVg03hgpxV2KM8F2kQozaXwccLa96NnIff0vluoGxYM5O+5JLBAd9jrQniR hR9nwIWZ+fkfFiefNswpVgIx42OiKZJhK7i04LrF4i9iks7gIkwgoL3YaUSewijvtKhUk0 P2/TXRK83QK8QnLlE6SLIKy5eIcBsj7UhbxDnCBsKw/L5WFxR0c1SOnhKOIRnU0Z6kOVZV o35m/S0Ha+UwCs6HKS2tReU2H6EZc3H1KgIPY+YcBu48BL9y1ayzEMXchaXZaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=akmL2pu6fbe2KLiiJdLSlckCrjdD+/4Gk3aSsddDCQ4=; b=QANc/UmNa4r4JDYS/brO7jQ6o71erepDKHDHd41nA7CP5O+RYKUH+qfY5dPdg01A293t05 TqJ2HWft+lwcwfaNfSMKPZy/Q6go+fJk/rToHJy71s2JvuEN6O4doDI8QaDYrHnEf0Cd64 Rt81ev0nvhkqeetbiUnnfa2Hcs22+Sh5UHy1cMgpUNqo8jZmIaROoeLMB4hMX/vPdePNjC rfqgqbo2ZXdeK8rTNIt6+rvCC7clz2HnbqkK0FB4FHQGI0uJhZXZ1beNN897vgB1GDunrg hgseof4sIe/FpI1PD+ZULVlWZX5FJo7aPwe3MvxJy8zZJWn/z2ZN9bLani16uw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VJwDy2X2DzxZw; Tue, 16 Apr 2024 20:12:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43GKCIvG036602; Tue, 16 Apr 2024 20:12:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43GKCIJk036599; Tue, 16 Apr 2024 20:12:18 GMT (envelope-from git) Date: Tue, 16 Apr 2024 20:12:18 GMT Message-Id: <202404162012.43GKCIJk036599@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 3e69ab88a032 - stable/14 - periodic/daily/801.trim-zfs: Add a daily zfs trim script List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 3e69ab88a032ac43d433f787b715466a87e72817 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3e69ab88a032ac43d433f787b715466a87e72817 commit 3e69ab88a032ac43d433f787b715466a87e72817 Author: Lexi Winter AuthorDate: 2024-04-09 21:49:56 +0000 Commit: Warner Losh CommitDate: 2024-04-16 19:54:20 +0000 periodic/daily/801.trim-zfs: Add a daily zfs trim script As mentioned in zpoolprops(7), on some SSDs, it may not be desirable to use ZFS autotrim because a large number of trim requests can degrade disk performance; instead, the pool should be manually trimmed at regular intervals. Add a new daily periodic script for this purpose, 801.trim-zfs. If enabled (daily_trim_zfs_enable=YES; the default is NO), it will run a 'zpool trim' operation on all online pools, or on the pools listed in 'daily_trim_zfs_pools'. The trim is not started if the pool is degraded (which matches the behaviour of the existing 800.scrub-zfs script) or if a trim is already running on that pool. Having autotrim enabled does not inhibit the periodic trim; it's sometimes desirable to run periodic trims even with autotrim enabled, because autotrim can elide trims for very small regions. PR: 275965 MFC after: 1 week Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/956 (cherry picked from commit 493908c4b45c7b75e4a6b4aea3b5b63ea5c268d5) --- share/man/man5/periodic.conf.5 | 11 +++++- usr.sbin/periodic/etc/daily/801.trim-zfs | 59 ++++++++++++++++++++++++++++++++ usr.sbin/periodic/etc/daily/Makefile | 3 +- usr.sbin/periodic/periodic.conf | 5 +++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/share/man/man5/periodic.conf.5 b/share/man/man5/periodic.conf.5 index 29fff146c212..a2ed2b09d772 100644 --- a/share/man/man5/periodic.conf.5 +++ b/share/man/man5/periodic.conf.5 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 31, 2023 +.Dd April 9, 2024 .Dt PERIODIC.CONF 5 .Os .Sh NAME @@ -634,6 +634,15 @@ The same as .Va daily_scrub_zfs_default_threshold but specific to the pool .Ao Ar poolname Ac Ns . +.It Va daily_trim_zfs_enable +.Pq Vt bool +Set to +.Dq Li YES +if you want to run a zfs trim daily. +.It Va daily_trim_zfs_pools +.Pq Vt str +A space separated list of names of zfs pools to trim. +If the list is empty or not set, all zfs pools are trimmed. .It Va daily_local .Pq Vt str Set to a list of extra scripts that should be run after all other diff --git a/usr.sbin/periodic/etc/daily/801.trim-zfs b/usr.sbin/periodic/etc/daily/801.trim-zfs new file mode 100755 index 000000000000..17d2ce217c10 --- /dev/null +++ b/usr.sbin/periodic/etc/daily/801.trim-zfs @@ -0,0 +1,59 @@ +#!/bin/sh +# +# + +# If there is a global system configuration file, suck it in. +# + +if [ -r /etc/defaults/periodic.conf ] +then + . /etc/defaults/periodic.conf + source_periodic_confs +fi + +case "$daily_trim_zfs_enable" in + [Yy][Ee][Ss]) + echo + echo 'Trimming of zfs pools:' + + if [ -z "${daily_trim_zfs_pools}" ]; then + daily_trim_zfs_pools="$(zpool list -H -o name)" + fi + + rc=0 + for pool in ${daily_trim_zfs_pools}; do + # sanity check + _status=$(zpool list -Hohealth "${pool}" 2> /dev/null) + if [ $? -ne 0 ]; then + rc=2 + echo " WARNING: pool '${pool}' specified in" + echo " '/etc/periodic.conf:daily_trim_zfs_pools'" + echo " does not exist" + continue + fi + case ${_status} in + FAULTED) + rc=3 + echo "Skipping faulted pool: ${pool}" + continue ;; + UNAVAIL) + rc=4 + echo "Skipping unavailable pool: ${pool}" + continue ;; + esac + + if ! zpool status "${pool}" | grep -q '(trimming)'; then + echo " starting trim of pool '${pool}'" + zpool trim ${daily_zfs_trim_flags} "${pool}" + else + echo " trim of pool '${pool}' already in progress, skipping" + fi + done + ;; + + *) + rc=0 + ;; +esac + +exit $rc diff --git a/usr.sbin/periodic/etc/daily/Makefile b/usr.sbin/periodic/etc/daily/Makefile index 4eabc0bb1d52..3bf4601f5145 100644 --- a/usr.sbin/periodic/etc/daily/Makefile +++ b/usr.sbin/periodic/etc/daily/Makefile @@ -60,7 +60,8 @@ SENDMAILPACKAGE= sendmail .if ${MK_ZFS} != "no" CONFS+= 223.backup-zfs \ 404.status-zfs \ - 800.scrub-zfs + 800.scrub-zfs \ + 801.trim-zfs .endif .include diff --git a/usr.sbin/periodic/periodic.conf b/usr.sbin/periodic/periodic.conf index 5e3a7837c6b4..608a199b3cc9 100644 --- a/usr.sbin/periodic/periodic.conf +++ b/usr.sbin/periodic/periodic.conf @@ -179,6 +179,11 @@ daily_scrub_zfs_pools="" # empty string selects all pools daily_scrub_zfs_default_threshold="35" # days between scrubs #daily_scrub_zfs_${poolname}_threshold="35" # pool specific threshold +# 801.trim-zfs +daily_trim_zfs_enable="NO" +daily_trim_zfs_pools="" # empty string selects all pools +daily_trim_zfs_flags="" # zpool-trim(8) flags + # 999.local daily_local="/etc/daily.local" # Local scripts