btrfs: fail metadata async reclaim early if filesystem is aborted
PATCH 1/1 btrfs: fail metadata async reclaim early if filesystem is aborted
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.
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.
--- fs/btrfs/space-info.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/btrfs/space-info.c +8 -0
@@ -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++;
Signature · 1 line
2.25.1
Quoted 9 lines · Jiasheng Jiang
Currently,
do_async_reclaim_metadata_spacecycles through all flush states even if the filesystem has been aborted. In contrast, the data reclaim path (do_async_reclaim_data_space) explicitly checks forBTRFS_FS_ERRORand 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.
Quoted 4 lines
Fix this by adding a
BTRFS_FS_ERRORcheck 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.
Quoted 29 lines
Signed-off-by Jiasheng Jiang <[email protected]>--- fs/btrfs/space-info.c | 8 ++++++++ 1 file changed, 8 insertions(+)fs/btrfs/space-info.c +8
-1@@ -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