]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: avoid starting new transaction and commit in relocate_block_group()
authorFilipe Manana <fdmanana@suse.com>
Mon, 9 Feb 2026 19:45:06 +0000 (19:45 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 16:55:55 +0000 (18:55 +0200)
We join a transaction with the goal of catching the current transaction
and then commit it to get rid of pinned extents and reclaim free space,
but a join can create a new transaction if there isn't any running, and if
right before we did the join the current transaction happened to be
committed by someone else (like the transaction kthread for example),
we end up starting and committing a new transaction, causing rotation of
the super block backup roots besides extra and useless IO.

So instead of doing a transaction join followed by a commit, use the
helper btrfs_commit_current_transaction() which ensures no transaction is
created if there isn't any running.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/relocation.c

index 0612e260b52af9a6983b3024a4060bd8703b8f8f..1c42c5180bddd508c97d018a720af9839a077884 100644 (file)
@@ -3642,12 +3642,7 @@ restart:
        btrfs_block_rsv_release(fs_info, rc->block_rsv, (u64)-1, NULL);
 
        /* get rid of pinned extents */
-       trans = btrfs_join_transaction(rc->extent_root);
-       if (IS_ERR(trans)) {
-               err = PTR_ERR(trans);
-               goto out_free;
-       }
-       ret = btrfs_commit_transaction(trans);
+       ret = btrfs_commit_current_transaction(rc->extent_root);
        if (ret && !err)
                err = ret;
 out_free: