diff --git a/btrfs-balance.sh b/btrfs-balance.sh index 978c1fa..967fd8f 100755 --- a/btrfs-balance.sh +++ b/btrfs-balance.sh @@ -17,6 +17,12 @@ fi LOGIDENTIFIER='btrfs-balance' . $(dirname $(realpath "$0"))/btrfsmaintenance-functions +ioprio= +if [ "$BTRFS_BALANCE_PRIORITY" = "idle" ]; then + # ionice(3) idle proirity + ioprio="ionice -c 3" +fi + { BTRFS_BALANCE_MOUNTPOINTS=$(expand_auto_mountpoint "$BTRFS_BALANCE_MOUNTPOINTS") OIFS="$IFS" @@ -33,7 +39,7 @@ for MM in $BTRFS_BALANCE_MOUNTPOINTS; do df -H "$MM" if detect_mixed_bg "$MM"; then - btrfs balance start -musage=0 -dusage=0 "$MM" + $ioprio btrfs balance start -musage=0 -dusage=0 "$MM" # we use the MUSAGE values for both, supposedly less aggressive # values, but as the data and metadata space is shared on # mixed-bg this does not lead to the situations we want to @@ -41,18 +47,18 @@ for MM in $BTRFS_BALANCE_MOUNTPOINTS; do # blockgroups) for BB in $BTRFS_BALANCE_MUSAGE; do # quick round to clean up the unused block groups - btrfs balance start -v -musage=$BB -dusage=$BB "$MM" + $ioprio btrfs balance start -v -musage=$BB -dusage=$BB "$MM" done else - btrfs balance start -dusage=0 "$MM" + $ioprio btrfs balance start -dusage=0 "$MM" for BB in $BTRFS_BALANCE_DUSAGE; do # quick round to clean up the unused block groups - btrfs balance start -v -dusage=$BB "$MM" + $ioprio btrfs balance start -v -dusage=$BB "$MM" done - btrfs balance start -musage=0 "$MM" + $ioprio btrfs balance start -musage=0 "$MM" for BB in $BTRFS_BALANCE_MUSAGE; do # quick round to clean up the unused block groups - btrfs balance start -v -musage="$BB" "$MM" + $ioprio btrfs balance start -v -musage="$BB" "$MM" done fi diff --git a/sysconfig.btrfsmaintenance b/sysconfig.btrfsmaintenance index 4088254..caa50bd 100644 --- a/sysconfig.btrfsmaintenance +++ b/sysconfig.btrfsmaintenance @@ -50,6 +50,14 @@ BTRFS_BALANCE_MOUNTPOINTS="/" # Frequency of periodic balance. BTRFS_BALANCE_PERIOD="weekly" +## Path: System/File systems/btrfs +## Type: string(idle,normal) +## Default: "idle" +# +# Priority of IO at which the balance process will run. Idle should not degrade +# performance as much as normal. +BTRFS_BALANCE_PRIORITY="normal" + ## Path: System/File systems/btrfs ## Type: string ## Default: "1 5 10 20 30 40 50"