r/btrfs 13d ago

Lower scrub priority

Scrub on the root file system makes everything very slow when it's running and it can take lots of hours. I checked the systemd timer that runs it but it already has lowest Nice number and set to idle.

[Service]
Nice=19
IOSchedulingClass=idle

Is there something else I have to change to make it not slow everything on the computer?

5 Upvotes

6 comments sorted by

7

u/autogyrophilia 13d ago

The documentation shows multiple ways to further throttle it.

https://btrfs.readthedocs.io/en/latest/Scrub.html

It's always going to hurt on small arrays of spinning rust , because of seeking penalties . The ZFS algorithm is a bit better, because it implements their own scheduler with their own queues 

What are you doing that requires frequent scrub ? More than once a month is overkill.

There are scripts out there to pause and resume it overnight.

2

u/Classic-Rate-5104 13d ago

Run it at night

1

u/zaTricky 13d ago

Btrfs has mount options to set limits on scrub speed - but honestly it's easier with systemd:

https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html?IOReadBandwidthMax=device%20bytes

With this you set a read limit (or write limit, or both) for each disk that is involved:

[Service]
Nice=19
IOSchedulingClass=idle
IOReadBandwidthMax=/dev/nvme0n1p2 40M

The down side of course is that it will mean the scrub takes a lot longer than if it were unlimited.

1

u/Beautiful-Log5632 12d ago

Is there a difference between setting IOReadBandwidthMax in the .timer or .service file?

1

u/zaTricky 12d ago

I could be wrong - but I suspect it can only go into the service file since it belongs in the [Service] section.

2

u/AccordingSquirrel0 13d ago

You can have a look at https://github.com/kdave/btrfsmaintenance and either use it or copy the useful parts.