Skip to content

Commit 482505f

Browse files
authored
Add weekly and monthly systemd timers for trimming
On machines using systemd, trim timers can be enabled on a per-pool basis. Weekly and monthly timer units are provided. Timers can be enabled as follows: systemctl enable [email protected] --now systemctl enable [email protected] --now Each timer will pull in zfs-trim@${poolname}.service, which is not schedule-specific. The manpage zpool-trim has been updated accordingly. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Julian Brunner <[email protected]> Closes #13544
1 parent 87b46d6 commit 482505f

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

etc/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ systemdunit_DATA = \
5959
%D%/systemd/system/[email protected] \
6060
%D%/systemd/system/[email protected] \
6161
%D%/systemd/system/[email protected] \
62+
%D%/systemd/system/[email protected] \
63+
%D%/systemd/system/[email protected] \
64+
%D%/systemd/system/[email protected] \
6265
%D%/systemd/system/zfs-share.service \
6366
%D%/systemd/system/zfs-volume-wait.service \
6467
%D%/systemd/system/zfs-volumes.target \

etc/systemd/system/[email protected]

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Monthly zpool trim timer for %i
3+
Documentation=man:zpool-trim(8)
4+
5+
[Timer]
6+
OnCalendar=monthly
7+
Persistent=true
8+
RandomizedDelaySec=1h
9+
Unit=zfs-trim@%i.service
10+
11+
[Install]
12+
WantedBy=timers.target

etc/systemd/system/[email protected]

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Weekly zpool trim timer for %i
3+
Documentation=man:zpool-trim(8)
4+
5+
[Timer]
6+
OnCalendar=weekly
7+
Persistent=true
8+
RandomizedDelaySec=1h
9+
Unit=zfs-trim@%i.service
10+
11+
[Install]
12+
WantedBy=timers.target

etc/systemd/system/[email protected]

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=zpool trim on %i
3+
Documentation=man:zpool-trim(8)
4+
Requires=zfs.target
5+
After=zfs.target
6+
ConditionACPower=true
7+
ConditionPathIsDirectory=/sys/module/zfs
8+
9+
[Service]
10+
EnvironmentFile=-@initconfdir@/zfs
11+
ExecStart=/bin/sh -c '\
12+
if @sbindir@/zpool status %i | grep -q "(trimming)"; then\
13+
exec @sbindir@/zpool wait -t trim %i;\
14+
else exec @sbindir@/zpool trim -w %i; fi'
15+
ExecStop=-/bin/sh -c '@sbindir@/zpool trim -s %i 2>/dev/null || true'

man/man8/zpool-trim.8

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,29 @@ with no flags on the relevant target devices.
8484
.It Fl w , -wait
8585
Wait until the devices are done being trimmed before returning.
8686
.El
87+
.Sh PERIODIC TRIM
88+
On machines using systemd, trim timers can be enabled on a per-pool basis.
89+
.Nm weekly
90+
and
91+
.Nm monthly
92+
timer units are provided.
93+
.Bl -tag -width Ds
94+
.It Xo
95+
.Xc
96+
.Nm systemctl
97+
.Cm enable
98+
.Cm zfs-trim-\fIweekly\fB@\fIrpool\fB.timer
99+
.Cm --now
100+
.It Xo
101+
.Xc
102+
.Nm systemctl
103+
.Cm enable
104+
.Cm zfs-trim-\fImonthly\fB@\fIotherpool\fB.timer
105+
.Cm --now
106+
.El
87107
.
88108
.Sh SEE ALSO
109+
.Xr systemd.timer 5 ,
89110
.Xr zpoolprops 7 ,
90111
.Xr zpool-initialize 8 ,
91112
.Xr zpool-wait 8

0 commit comments

Comments
 (0)