kdave / btrfs-progs

Development of userspace BTRFS tools
GNU General Public License v2.0
563 stars 243 forks source link

scrub start: set bwlimit using cgroups or systemd-start #402

Open kdave opened 3 years ago

kdave commented 3 years ago

Bandwidth limit per device can be set by systemd-run -p IOBandwidthReadMax=/dev/sdx 10M' btrfs scrub start -B / . The cgroup2 is set up on systems by default.

kdave commented 11 months ago

Now documented, there's a new command btrfs scrub limit to show the limits, setting will be possible in the future too.

Werkov commented 11 months ago

IIUC, the scrub IO is carried out from the actual btrfs-prog process? (I.e. no deferral to kthreads.)

When a scrub thread waits for IO, can it possibly (exclusively) hold any (btr)fs locks?

kdave commented 10 months ago

No, the user space part of scrub starts an ioctl and all the io is done by kernel, running from the user process context, ie. no kthread. The locks are managed by kernel and user space cannot interfere with that.

Werkov commented 10 months ago

user space cannot interfere with that.

No argument about that. But the holder could be waiting (longer) for a throttled IO. Or are locks released before issuing the IO?

Edit: I only want to warn about possible "propagation" of the throttling via a shared lock to other FS users. If there is no such lock, this throttling likely nails the issue of too greedy scrub.

kdave commented 9 months ago

I haven't found any logic that would block threads outside of scrub. It's running from its own context and the throttling happens on the IO submission, no big locks are held there for a long time (other than to set up data for io, like any other regular io). The special case of device replace can hold some locks longer but still during the setup phase.