From: Qu Wenruo <wqu@suse.com>
To: Boris Burkov <boris@bur.io>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 3/4] btrfs: scrub: handle bwlimit below 512KiB
Date: Thu, 26 Nov 2026 14:13:06 +1030 [thread overview]
Message-ID: <d9e8abc6-29d2-4067-a2be-ecb5eb275b12@suse.com> (raw)
In-Reply-To: <20261126005359.GA1984368@zen.localdomain>
在 2026/11/26 11:23, Boris Burkov 写道:
> On Thu, Nov 26, 2026 at 10:15:45AM +1030, Qu Wenruo wrote:
[...]
>> For the bandwidth limit, I doubt if it's really practical to set it so low.
>> One 1GiB bg will take over 30min to scrub, which doesn't sound that sane.
>>
>
> I agree in general.
>
> We have a use-case with a remote disk and a bw budget for bg
> checking where we would like to set a low limit. If you have a small
> amount of metadata and scrub the metadata bg it can be feasible to do
> quite slow scrubs and get some good utility.
In that case, I'd argue the read-only metadata bg can be a larger
problem, as it means the metadata bg can not be utilized for over 30min
if using that low bwlimit.
But overall I agree for such bw limited storage, a lower and better
bwlimit behavior can be beneficial, just don't set the limit too low.
>
> Would it make more sense if I also sent a patch to extend the scrub
> ioctl to have it respect narrower ranges of the disk than the whole
> chunk?
Sorry but I didn't get what you mean by "respect narrower ranges of the
disk than the whole chunk".
>
>>>
>>> However, at higher limits, because the unit of sending is still 512KiB,
>>> sleeping between every IO for a naively calculated limit would be far
>>> too many sleeps and adds unacceptable sleeping overhead, ruining our
>>> ability to even submit at those limits. Therefore, we need to allow a
>>> "burst duration" as a floor for the sleeping duration. 10ms is a
>>> reasonable value: it is a similar number of sleeps at high limits (100
>>> vs 64 per second) and is a responsive duration relatively commensurate
>>> in scale with disk latencies and intuitively seems like it would not
>>> be "too bursty" at any speed.
>>
>> I agree the old sleep behavior is not that good for high limits, especially
>> considering how fast modern storage can be.
>>
>
> Sorry if I was unclear but the old behavior should be fast on high
> limits, at least as I understand it. My motivation here was:
>
> 1. slow scrub needs to sleep for required (possibly long) duration
> between IOs.
> 2. sleep for required duration between IOs done naively makes fast
> scrub sleep thousands of times for nanoseconds, now we are harassing
> the scheduler for all the sleeping/waking.
> 3. bring back the upper bound on how often we sleep by always allowing
> the burst worth of IO.
>
> So the point is to enable slow scrubs without regressing fast scrubs, I
> don't think this patch should help fast scrubs at all. Besides making
> the code a little simpler, at least IMO.
Oh, thanks a lot for correcting my misunderstanding.
Despite the changing bwlimit halfway part, now it looks overall good to me.
Thanks,
Qu
>
>>>
>>> Now that we might sleep for a rather long time rather than at most 1s,
>>> although the sleeps are cancellable, also add a wakeup/cancel path from
>>> changing the limit again. If the user tunes the limit higher, they
>>> should just start running rather than needing to cancel.
>>>
>>> Signed-off-by: Boris Burkov <boris@bur.io>
>>> ---
>>> fs/btrfs/scrub.c | 71 +++++++++++++++++++-----------------------------
>>> fs/btrfs/sysfs.c | 2 ++
>>> 2 files changed, 30 insertions(+), 43 deletions(-)
>>>
>>> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
>>> index a976897cea8d..d68e8d2f766f 100644
>>> --- a/fs/btrfs/scrub.c
>>> +++ b/fs/btrfs/scrub.c
>>> @@ -57,6 +57,9 @@ struct scrub_ctx;
>>> #define SCRUB_TOTAL_STRIPES (SCRUB_GROUPS_PER_SCTX * SCRUB_STRIPES_PER_GROUP)
>>> +/* Length of a burst of throttled scrub IO, see scrub_throttle_dev_io(). */
>>> +#define SCRUB_THROTTLE_BURST_MS 10
>>> +
>>> /* Represent one sector and its needed info to verify the content. */
>>> struct scrub_sector_verification {
>>> union {
>>> @@ -195,9 +198,8 @@ struct scrub_ctx {
>>> atomic_t cancel_req;
>>> int readonly;
>>> - /* State of IO submission throttling affecting the associated device */
>>> - ktime_t throttle_deadline;
>>> - u64 throttle_sent;
>>> + /* Earliest time the next read may be submitted under scrub_speed_max. */
>>> + ktime_t throttle_next;
>>> bool is_dev_replace;
>>> u64 write_pointer;
>>> @@ -451,16 +453,19 @@ static void scrub_blocked_if_needed(struct scrub_ctx *sctx)
>>> /*
>>> * Pause the scrub, and sleep for the throttle duration. Pausing allows the
>>> * commit to proceed unblocked.
>>> - * Scrub cancel interrupts the sleep.
>>> + * Scrub cancel or a change of the limit the sleep was computed under
>>> + * interrupts the sleep.
>>> */
>>> -static void scrub_throttle_sleep(struct scrub_ctx *sctx, ktime_t timeout)
>>> +static void scrub_throttle_sleep(struct scrub_ctx *sctx, struct btrfs_device *device,
>>> + u64 bwlimit, ktime_t timeout)
>>> {
>>> struct btrfs_fs_info *fs_info = sctx->fs_info;
>>> scrub_pause_on(sctx);
>>> wait_event_interruptible_hrtimeout(fs_info->scrub_pause_wait,
>>> atomic_read(&fs_info->scrub_cancel_req) ||
>>> - atomic_read(&sctx->cancel_req),
>>> + atomic_read(&sctx->cancel_req) ||
>>> + READ_ONCE(device->scrub_speed_max) != bwlimit,
>>
>> One question, do we really need to bother the scrub_speed_max change?
>>
>> I think this is a little overengineered, and Sashiko is already report low
>> priority problem related to this part.
>
> Yeah we can drop it, I think this was a nice-to-have UX addon. The user
> can always cancel if necessary.
>
>>
>> Thanks,
>> Qu
>>
>
> Thanks for the review!
>
next prev parent reply other threads:[~2026-11-26 3:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 21:34 [PATCH 0/4] btrfs: scrub: support low bwlimits Boris Burkov
2026-11-25 21:34 ` [PATCH 1/4] btrfs: scrub: release the commit root paths before pausing Boris Burkov
2026-11-25 23:12 ` Qu Wenruo
2026-11-25 21:34 ` [PATCH 2/4] btrfs: scrub: cancellable pause during throttle sleep Boris Burkov
2026-11-25 23:29 ` Qu Wenruo
2026-11-25 21:34 ` [PATCH 3/4] btrfs: scrub: handle bwlimit below 512KiB Boris Burkov
2026-11-25 23:45 ` Qu Wenruo
2026-11-26 0:53 ` Boris Burkov
2026-11-26 3:43 ` Qu Wenruo [this message]
2026-11-25 21:34 ` [PATCH 4/4] btrfs: scrub: size read bios to the bwlimit 10ms burst Boris Burkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d9e8abc6-29d2-4067-a2be-ecb5eb275b12@suse.com \
--to=wqu@suse.com \
--cc=boris@bur.io \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox