FreeBSD Bugzilla – Attachment 250113 Details for
Bug 275965
periodic: add a daily zfs trim
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
trim-zfs.diff
trim-zfs.diff (text/plain), 4.92 KB, created by
Dmitry Wagin
on 2024-04-20 20:02:30 UTC
(
hide
)
Description:
trim-zfs.diff
Filename:
MIME Type:
Creator:
Dmitry Wagin
Created:
2024-04-20 20:02:30 UTC
Size:
4.92 KB
patch
obsolete
>diff --git a/share/man/man5/periodic.conf.5 b/share/man/man5/periodic.conf.5 >index a2ed2b09d..4b4c384f1 100644 >--- a/share/man/man5/periodic.conf.5 >+++ b/share/man/man5/periodic.conf.5 >@@ -643,6 +643,25 @@ if you want to run a zfs trim daily. > .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_trim_zfs_default_threshold >+.Pq Vt int >+Number of days between a trim if no pool-specific threshold is set. >+If not set, the default value is 14, corresponding to 2 weeks. >+.It Va daily_trim_zfs_ Ns Ao Ar poolname Ac Ns Va _threshold >+.Pq Vt int >+The same as >+.Va daily_trim_zfs_default_threshold >+but specific to the pool >+.Ao Ar poolname Ac Ns . >+.It Va daily_trim_zfs_default_rate >+.Pq Vt str >+Controls the rate at which the TRIM operation progresses. >+.It Va daily_trim_zfs_ Ns Ao Ar poolname Ac Ns Va _threshold >+.Pq Vt int >+The same as >+.Va daily_trim_zfs_default_rate >+but specific to the pool >+.Ao Ar poolname Ac Ns . > .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 >index 17d2ce217..acd124b0a 100755 >--- a/usr.sbin/periodic/etc/daily/801.trim-zfs >+++ b/usr.sbin/periodic/etc/daily/801.trim-zfs >@@ -4,14 +4,15 @@ > > # 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 >+: ${daily_trim_zfs_default_threshold=14} >+ >+case "${daily_trim_zfs_enable}" in > [Yy][Ee][Ss]) > echo > echo 'Trimming of zfs pools:' >@@ -34,20 +35,69 @@ case "$daily_trim_zfs_enable" in > case ${_status} in > FAULTED) > rc=3 >- echo "Skipping faulted pool: ${pool}" >- continue ;; >+ echo " skipping faulted pool '${pool}'" >+ continue >+ ;; > UNAVAIL) > rc=4 >- echo "Skipping unavailable pool: ${pool}" >- continue ;; >+ 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" >+ if zpool status ${pool} | grep -q "trimming"; then >+ echo " trimming of pool '${pool}' already in progress, skipping" >+ echo " consult 'zpool status -t ${pool}' for the result" >+ continue >+ fi >+ >+ # determine how many days shall be between trimming >+ eval _pool_threshold=\${daily_trim_zfs_$(echo "${pool}" | tr ".:-" "_")_threshold:-${daily_trim_zfs_default_threshold}} >+ >+ _last_trim=$(zpool history ${pool} | \ >+ sed -Ene 's/^([0-9.:-]{19}) zpool trim .*$/\1/p' | tail -1) >+ if [ -z "${_last_trim}" ]; then >+ # creation time of the pool if no trim was done >+ _last_trim=$(zpool history ${pool} | \ >+ sed -Ene '2s/^([0-9.:-]{19}) .*$/\1/p') >+ fi >+ if [ -z "${_last_trim}" ]; then >+ rc=2 >+ echo " skipping trimming of pool '${pool}':" >+ echo " can't get last trimming date" >+ continue >+ fi >+ >+ # Now minus last trim (both in seconds) converted to days >+ _trim_diff=$(expr -e \( $(date +%s) - \ >+ $(date -j -v -70M -f %F.%T ${_last_trim} +%s) \) / 60 / 60 / 24) >+ if [ ${_trim_diff} -lt ${_pool_threshold} ]; then >+ echo " skipping trimming of pool '${pool}':" >+ echo " last trimming is ${_trim_diff} days ago, threshold is set to ${_pool_threshold} days" >+ continue > fi >+ >+ # determine the rate at which the TRIM operation is performed >+ eval _trim_rate=\${daily_trim_zfs_$(echo "${pool}" | tr ".:-" "_")_rate:-${daily_trim_zfs_default_rate}} >+ if [ -n "${_trim_rate}" ]; then >+ _trim_flags="-r ${_trim_rate}" >+ fi >+ >+ _status="$(zpool status ${pool} | grep scan:)" >+ case "${_status}" in >+ *"scrub in progress"*) >+ echo " scrubbing of pool '${pool}' is in progress, skipping" >+ ;; >+ *"resilver in progress"*) >+ echo " resilvering of pool '${pool}' is in progress, skipping" >+ ;; >+ *) >+ echo " starting TRIM of pool '${pool}'" >+ echo " consult 'zpool status -t ${pool}' for the result" >+ zpool trim ${_trim_flags} ${pool} >+ [ $rc -eq 0 ] && rc=1 >+ ;; >+ esac > done > ;; > >diff --git a/usr.sbin/periodic/periodic.conf b/usr.sbin/periodic/periodic.conf >index 608a199b3..030b95f03 100644 >--- a/usr.sbin/periodic/periodic.conf >+++ b/usr.sbin/periodic/periodic.conf >@@ -183,6 +183,10 @@ daily_scrub_zfs_default_threshold="35" # days between scrubs > daily_trim_zfs_enable="NO" > daily_trim_zfs_pools="" # empty string selects all pools > daily_trim_zfs_flags="" # zpool-trim(8) flags >+daily_trim_zfs_default_threshold="14" # days between trim >+#daily_trim_zfs_${poolname}_threshold="14" # pool specific threshold >+daily_trim_zfs_default_rate="" # trim rate >+#daily_trim_zfs_${poolname}_rate="" # pool specific rate > > # 999.local > daily_local="/etc/daily.local" # Local scripts
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 275965
:
247294
| 250113 |
252519