Re: [PATCH] btrfs: fail metadata async reclaim early if filesystem is aborted
From: Filipe Manana
Date: Sun Jan 11 2026 - 14:28:18 EST
On Sat, Jan 10, 2026 at 8:07 PM Jiasheng Jiang
<jiashengjiangcool@xxxxxxxxx> wrote:
>
> Currently, do_async_reclaim_metadata_space cycles through all flush
> states even if the filesystem has been aborted. In contrast, the data
> reclaim path (do_async_reclaim_data_space) explicitly checks for
> BTRFS_FS_ERROR and fails all pending tickets immediately.
>
> This inconsistency causes the metadata reclaimer to waste CPU cycles
> performing useless flush operations (like attempting to commit a
> transaction or allocate chunks) on a broken filesystem.
No it doesn't.
If the fs is aborted we can't commit a transaction, etc - all flush
operations return early.
>
> Fix this by adding a BTRFS_FS_ERROR check inside the metadata reclaim
> loop, ensuring that we fail all tickets and exit as soon as a
> filesystem error is detected, matching the behavior of data reclaim.
Honestly I don't think it's worth adding this code.
Not only is flushing a no-op when the fs was aborted, having a
transaction abort is an excepcional and rare event.
Thanks.
>
> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@xxxxxxxxx>
> ---
> fs/btrfs/space-info.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
> index 6babbe333741..b3aae44a1436 100644
> --- a/fs/btrfs/space-info.c
> +++ b/fs/btrfs/space-info.c
> @@ -1189,6 +1189,14 @@ static void do_async_reclaim_metadata_space(struct btrfs_space_info *space_info)
> spin_unlock(&space_info->lock);
> return;
> }
> +
> + if (unlikely(BTRFS_FS_ERROR(fs_info))) {
> + maybe_fail_all_tickets(space_info);
> + space_info->flush = false;
> + spin_unlock(&space_info->lock);
> + return;
> + }
> +
> to_reclaim = btrfs_calc_reclaim_metadata_size(space_info);
> if (last_tickets_id == space_info->tickets_id) {
> flush_state++;
> --
> 2.25.1
>
>