Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: dsterba@suse.cz
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH RFC] btrfs: exit scrub and balance early if the fs is being frozen
Date: Tue, 8 Jul 2025 07:46:32 +0930	[thread overview]
Message-ID: <64c96919-5825-4cef-a456-8b625d0d176d@suse.com> (raw)
In-Reply-To: <20250707123026.GE4453@twin.jikos.cz>



在 2025/7/7 22:00, David Sterba 写道:
> On Mon, Jul 07, 2025 at 02:53:58PM +0930, Qu Wenruo wrote:
>>> Reason for RFC:
>>> I'm not sure if cancelling is the best solution, but it is the easiest
>>> one to implementation.
>>>
>>> Pause the scrub/balance is not really feasible yet, as it will still hold the
>>> mnt_want_write_file(), thus blocking freezing.
>>>
>>> Meanwhile for end users, pausing scrub/balance when freezing, and resume
>>> when thawing should be the best outcome.
>>
>> I have explored some other solutions, like dropping and grabbing the
>> s_writers.rw_sem during the balance/scrub.
>>
>> The problem of that solution is the reserved lock sequence, thus it will
>> be deadlock prune.
> 
> What do you mean by 'reserved lock sequence'?


The s_umount and s_writers.rw_sem are always locked way before any btrfs 
specific locks.

If you unhold the s_writers.rw_sem, it's very easy to cause ABBA lock 
sequence thus lockdep warnings.


> 
>> Currently I guess the best solution would be introducing a special error
>> code (maybe >0? -EGAIN may be a little too generic in this case) so that
>> if we hit that specific error code, we error out as usual.
>>
>> But at the top level where we call mnt_want_write*() function, we drop
>> the rw_sem, and retry other than exit.
>>
>> By this, we split the original long-running ioctl into several different
>> smaller sections (the split only happens after the fs being frozen), so
>> that they can properly follow the fs freeze behavior.
> 
> We have cancellable balance and scrub so there are checkpoints that can
> be extended to also handle freezing in a way that pauses the operation
> and waits until unfreeze. The sequence "drop locks/freeze/take locks"
> should work.

It will cause deadlock if you drop the lock then re-lock with any btrfs 
specific lock hold.

You have to return to where we call mnt_want_write_file() to unlock, 
thus meaning a much different resume path.

> For the exclusive ops it's guaranteed nothing else will
> start so the state will remain the same.
> 
>> The challenge is how to resume from such interruption.
>> Currently neither scrub nor balance can properly handle such resume and
>> will restart from the beginning.
>>
>> And even with that resume implementation, the checks in this patch will
>> still be needed.
> 
> The checks peek into the interals of the freezing mechanism, which I
> think is not the right.

Nope, that's completely common.

f2fs is already doing that to skip its background gc.

Thanks,
Qu


  parent reply	other threads:[~2025-07-07 22:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-07  0:25 [PATCH RFC] btrfs: exit scrub and balance early if the fs is being frozen Qu Wenruo
2025-07-07  5:23 ` Qu Wenruo
2025-07-07 12:30   ` David Sterba
2025-07-07 12:37     ` Daniel Vacek
2025-07-07 22:16     ` Qu Wenruo [this message]
2025-07-07 12:25 ` David Sterba
2025-10-12  8:23 ` Askar Safin
2025-10-12 23:56   ` Qu Wenruo
2025-10-15  4:05     ` Askar Safin
2025-10-15  7:00   ` Qu Wenruo
2025-10-15  7:59     ` Askar Safin
2025-10-15  8:07       ` Qu Wenruo
2025-10-15 11:12     ` Askar Safin
2025-10-15 23:01       ` Qu Wenruo
2025-10-16  8:40         ` Askar Safin
2025-10-16  9:46           ` Qu Wenruo

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=64c96919-5825-4cef-a456-8b625d0d176d@suse.com \
    --to=wqu@suse.com \
    --cc=dsterba@suse.cz \
    --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