Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Systemd-provided cgroup IO limits #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.man
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:__

Expand Down
14 changes: 14 additions & 0 deletions btrfsmaintenance-refresh-cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
36 changes: 36 additions & 0 deletions sysconfig.btrfsmaintenance
Original file line number Diff line number Diff line change
Expand Up @@ -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"