From 55e5e9d0391d13ec3a45eae82f3bd269759211fe Mon Sep 17 00:00:00 2001 From: Brendan Hide Date: Sun, 25 Aug 2024 18:15:28 +0200 Subject: [PATCH 1/3] Feat: Add IO resource limits options to configuration Signed-off-by: Brendan Hide --- sysconfig.btrfsmaintenance | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/sysconfig.btrfsmaintenance b/sysconfig.btrfsmaintenance index cfaa81e..0ca8e62 100644 --- a/sysconfig.btrfsmaintenance +++ b/sysconfig.btrfsmaintenance @@ -152,3 +152,39 @@ BTRFS_TRIM_MOUNTPOINTS="/" # the timer for these tasks(s) elapsed while the system was suspended # or powered off. BTRFS_ALLOW_CONCURRENCY="false" + +## Path: System/File systems/btrfs +## Description: Configuration to allow limiting bandwidth and IOPS +## Type: boolean +## Default: "false" +# Maintenance tasks may starve system resources for other more urgent +# workloads. This enables IO resource limits when using systemd timers. +BTRFS_IO_LIMIT="false" + +## Path: System/File systems/btrfs +## Description: Configuration to specify devices with limited bandwidth and/or IOPS +## Type: string +## Default: "/dev/sda" +# With IO resource limits, this setting specifies the block devices that will +# have resource limits set +# (Colon separated paths) +BTRFS_IO_LIMIT_DEVICES="/dev/sda" + +## Path: System/File systems/btrfs +## Description: Configuration to specify IOPS limits +## Type: string +## Default: "40" +# With IO resource limits, this setting specifies the per-device IOPS limits. +# SSDs can typically perform thousands of operations per second while spindles +# can only perform up to 120 IOPS, though with terrible throughput. +BTRFS_IO_LIMIT_IOPS="40" + +## Path: System/File systems/btrfs +## Description: Configuration to specify disk bandwidth limits +## Type: string +## Default: "20M" +# With IO resource limits, this setting specifies the per-device bandwidth +# limit. The typical maximum speed of SATA SSDs is about 550MBps limited by +# the SATA protocol. Current high-end spindle drives' typical maximum speed +# is about 240MBps. +BTRFS_IO_LIMIT_BW="20M" From f02a2d4ae1698a2fd1ec7e172aa7bc28bc0ded07 Mon Sep 17 00:00:00 2001 From: Brendan Hide Date: Sun, 25 Aug 2024 18:16:02 +0200 Subject: [PATCH 2/3] Feat: Add IO resource limits to systemd service refresh Signed-off-by: Brendan Hide --- btrfsmaintenance-refresh-cron.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/btrfsmaintenance-refresh-cron.sh b/btrfsmaintenance-refresh-cron.sh index ce9fde7..bb32350 100755 --- a/btrfsmaintenance-refresh-cron.sh +++ b/btrfsmaintenance-refresh-cron.sh @@ -84,6 +84,20 @@ OnCalendar=$PERIOD EOF systemctl enable "$SERVICE".timer &> /dev/null systemctl start "$SERVICE".timer &> /dev/null + OIFS="$IFS" + IFS=: + if [ "$BTRFS_IO_LIMIT" = "true" ] ; then + mkdir -p /etc/systemd/system/"$SERVICE".service.d + echo '[Service]' > /etc/systemd/system/"$SERVICE".service.d/10-iolimits.conf + for DEVICE in $BTRFS_IO_LIMIT_DEVICES ; do + echo "IOReadBandwidthMax=$DEVICE $BTRFS_IO_LIMIT_BW" + echo "IOWriteBandwidthMax=$DEVICE $BTRFS_IO_LIMIT_BW" + echo "IOReadIOPSMax=$DEVICE $BTRFS_IO_LIMIT_IOPS" + echo "IOWriteIOPSMax=$DEVICE $BTRFS_IO_LIMIT_IOPS" + done >> /etc/systemd/system/"$SERVICE".service.d/10-iolimits.conf + systemctl daemon-reload + fi + IFS="$OIFS" ;; esac } From 87a1c7214e78826d320f50ba637036058f74eb06 Mon Sep 17 00:00:00 2001 From: Brendan Hide Date: Sun, 25 Aug 2024 18:18:55 +0200 Subject: [PATCH 3/3] Docs: New BTRFS_IO_LIMIT option Signed-off-by: Brendan Hide --- README.man | 4 ++++ README.md | 2 ++ 2 files changed, 6 insertions(+) diff --git a/README.man b/README.man index ea8cb04..2476c56 100644 --- a/README.man +++ b/README.man @@ -63,6 +63,10 @@ you can turn off the automatic repair (\fB\fCBTRFS\_SCRUB\_READ\_ONLY\fR) .IP \(bu 2 the default IO priority is set to \fIidle\fP but scrub may take long to finish, you can change priority to \fInormal\fP (\fB\fCBTRFS\_SCRUB\_PRIORITY\fR) +.IP \(bu 2 +If using systemd timers, you can also enable (`BTRFS_IO_LIMIT`) to set IO resource +.IP \(bu 2 +limits .RE diff --git a/README.md b/README.md index 30a7f69..f94e27c 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ __Tuning:__ * you can turn off the automatic repair (`BTRFS_SCRUB_READ_ONLY`) * the default IO priority is set to *idle* but scrub may take long to finish, you can change priority to *normal* (`BTRFS_SCRUB_PRIORITY`) +* If using systemd timers, you can also enable (`BTRFS_IO_LIMIT`) to set IO resource +* limits __Related commands:__