]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: avoid starting new transaction when flushing delayed items and refs
authorFilipe Manana <fdmanana@suse.com>
Wed, 26 Jul 2023 15:57:10 +0000 (16:57 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Aug 2023 12:52:18 +0000 (14:52 +0200)
When flushing space we join a transaction to flush delayed items and
delayed references, in order to try to release space. However using
btrfs_join_transaction() not only joins an existing transaction as well
as it starts a new transaction if there is none open. If there is no
transaction open, we don't have neither delayed items nor delayed
references, so creating a new transaction is a waste of time, IO and
creates an unnecessary rotation of the backup roots without gaining any
benefits (including releasing space).

So use btrfs_join_transaction_nostart() when attempting to flush delayed
items and references.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/space-info.c

index be5ce209b918d12916e008a6b7131a2583167851..2db92a2016978866de4877bf992099cdae73bcfe 100644 (file)
@@ -725,9 +725,11 @@ static void flush_space(struct btrfs_fs_info *fs_info,
                else
                        nr = -1;
 
-               trans = btrfs_join_transaction(root);
+               trans = btrfs_join_transaction_nostart(root);
                if (IS_ERR(trans)) {
                        ret = PTR_ERR(trans);
+                       if (ret == -ENOENT)
+                               ret = 0;
                        break;
                }
                ret = btrfs_run_delayed_items_nr(trans, nr);
@@ -743,9 +745,11 @@ static void flush_space(struct btrfs_fs_info *fs_info,
                break;
        case FLUSH_DELAYED_REFS_NR:
        case FLUSH_DELAYED_REFS:
-               trans = btrfs_join_transaction(root);
+               trans = btrfs_join_transaction_nostart(root);
                if (IS_ERR(trans)) {
                        ret = PTR_ERR(trans);
+                       if (ret == -ENOENT)
+                               ret = 0;
                        break;
                }
                if (state == FLUSH_DELAYED_REFS_NR)