diff options
author | Filipe Manana <fdmanana@suse.com> | 2024-05-21 12:57:37 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2024-07-11 15:33:19 +0200 |
commit | 0557feab7004b0366ac849b30eee6b589d8ccac6 (patch) | |
tree | 259e53cfe151c428e10f92341450da6cf07cbef1 /fs | |
parent | btrfs: send: make ensure_commit_roots_uptodate() simpler and more efficient (diff) | |
download | linux-0557feab7004b0366ac849b30eee6b589d8ccac6.tar.xz linux-0557feab7004b0366ac849b30eee6b589d8ccac6.zip |
btrfs: send: avoid create/commit empty transaction at ensure_commit_roots_uptodate()
At ensure_commit_roots_uptodate() we use btrfs_join_transaction() to
catch any running transaction and then commit it. This will however create
a new and empty transaction in case there's no running transaction anymore
(got committed by the transaction kthread or other task for example) or
there's a running transaction finishing its commit and with a state >=
TRANS_STATE_UNBLOCKED. In the former case we don't need to do anything
while in the second case we just need to wait for the transaction to
complete its commit.
So improve this by using btrfs_attach_transaction_barrier() instead, which
does not create a new transaction if there's none running, and if there's
a current transaction that is committing, it will wait for it to fully
commit and not create a new transaction. This helps avoiding creating and
committing empty transactions, saving IO, time and unnecessary rotation of
the backup roots in the super block.
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/send.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index 2c46bd1c90d3..289e5e6a6c56 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -8018,9 +8018,12 @@ commit_trans: * an unnecessary update of the root's item in the root tree when * committing the transaction if that root wasn't changed before. */ - trans = btrfs_join_transaction(root); - if (IS_ERR(trans)) - return PTR_ERR(trans); + trans = btrfs_attach_transaction_barrier(root); + if (IS_ERR(trans)) { + int ret = PTR_ERR(trans); + + return (ret == -ENOENT) ? 0 : ret; + } return btrfs_commit_transaction(trans); } |