From: Qu Wenruo <wqu@suse.com>
To: Boris Burkov <boris@bur.io>,
linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 2/4] btrfs: scrub: cancellable pause during throttle sleep
Date: Thu, 26 Nov 2026 09:59:52 +1030 [thread overview]
Message-ID: <3ec88341-70a1-45af-a6bf-dc2cdcae330f@suse.com> (raw)
In-Reply-To: <fdeb64e3fcf92bc8f1a69d07718dc07a23a133e8.1795642270.git.boris@bur.io>
在 2026/11/26 08:04, Boris Burkov 写道:
> scrub_throttle_dev_io() sleeps with schedule_timeout_interruptible()
> without pausing the scrub, while a transaction cannot enter a critical
> section without pausing scrub. Thus, a transaction commit gets blocked
> on a scrub throttle, which is completely backwards.
>
> Furthermore, this sleep ignores attempts to cancel the scrub.
>
> Improve the scrub throttling semantics by implementing it as a cancel
> aware sleep wrapped in a pause.
>
> Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/scrub.c | 27 +++++++++++++++++++++------
> 1 file changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 1a721623813f..a976897cea8d 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -448,6 +448,23 @@ static void scrub_blocked_if_needed(struct scrub_ctx *sctx)
> scrub_pause_off(sctx->fs_info);
> }
>
> +/*
> + * Pause the scrub, and sleep for the throttle duration. Pausing allows the
> + * commit to proceed unblocked.
> + * Scrub cancel interrupts the sleep.
> + */
> +static void scrub_throttle_sleep(struct scrub_ctx *sctx, 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),
> + timeout);
> + scrub_pause_off(fs_info);
> +}
> +
> static noinline_for_stack void scrub_free_ctx(struct scrub_ctx *sctx)
> {
> int i;
> @@ -1435,12 +1452,8 @@ static void scrub_throttle_dev_io(struct scrub_ctx *sctx, struct btrfs_device *d
> delta = 0;
> }
>
> - if (delta) {
> - long timeout;
> -
> - timeout = div_u64(delta * HZ, 1000);
> - schedule_timeout_interruptible(timeout);
> - }
> + if (delta)
> + scrub_throttle_sleep(sctx, ms_to_ktime(delta));
>
> /* Next call will start the deadline period */
> sctx->throttle_deadline = 0;
> @@ -3334,6 +3347,7 @@ int btrfs_scrub_cancel(struct btrfs_fs_info *fs_info)
> }
>
> atomic_inc(&fs_info->scrub_cancel_req);
> + wake_up(&fs_info->scrub_pause_wait);
> while (atomic_read(&fs_info->scrubs_running)) {
> mutex_unlock(&fs_info->scrub_lock);
> wait_event(fs_info->scrub_pause_wait,
> @@ -3358,6 +3372,7 @@ int btrfs_scrub_cancel_dev(struct btrfs_device *dev)
> return -ENOTCONN;
> }
> atomic_inc(&sctx->cancel_req);
> + wake_up(&fs_info->scrub_pause_wait);
> while (dev->scrub_ctx) {
> mutex_unlock(&fs_info->scrub_lock);
> wait_event(fs_info->scrub_pause_wait,
next prev parent reply other threads:[~2026-11-25 23:29 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 [this message]
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
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=3ec88341-70a1-45af-a6bf-dc2cdcae330f@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