diff options
author | Filipe Manana <fdmanana@suse.com> | 2024-05-20 13:21:12 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2024-07-11 15:33:19 +0200 |
commit | de18fba807c6b594d6ed13edf16726eb77237d32 (patch) | |
tree | c9e12cd2be1c8a33e7c79808d8113638ee2f28e2 /fs/btrfs/qgroup.c | |
parent | 42317ab440c110618b511290284c6d6c10bcffc7 (diff) |
btrfs: qgroup: avoid start/commit empty transaction when flushing reservations
When flushing reservations we are using btrfs_join_transaction() to get a
handle for the current transaction and then commit it to try to release
space. However btrfs_join_transaction() has some undesirable consequences:
1) If there's no running transaction, it will create one, and we will
commit it right after. This is unnecessary because it will not release
any space, and it will result in unnecessary IO and rotation of backup
roots in the superblock;
2) If there's a current transaction and that transaction is committing
(its state is >= TRANS_STATE_COMMIT_DOING), it will wait for that
transaction to almost finish its commit (for its state to be >=
TRANS_STATE_UNBLOCKED) and then start and return a new transaction.
We will then commit that new transaction, which is pointless because
all we wanted was to wait for the current (previous) transaction to
fully finish its commit (state == TRANS_STATE_COMPLETED), and by
starting and committing a new transaction we are wasting IO too and
causing unnecessary rotation of backup roots in the superblock.
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.
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/btrfs/qgroup.c')
-rw-r--r-- | fs/btrfs/qgroup.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index b9c5dff960de..63fdbbf61f15 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1341,12 +1341,14 @@ static int flush_reservations(struct btrfs_fs_info *fs_info) if (ret) return ret; btrfs_wait_ordered_roots(fs_info, U64_MAX, NULL); - trans = btrfs_join_transaction(fs_info->tree_root); - if (IS_ERR(trans)) - return PTR_ERR(trans); - ret = btrfs_commit_transaction(trans); - return ret; + trans = btrfs_attach_transaction_barrier(fs_info->tree_root); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + return (ret == -ENOENT) ? 0 : ret; + } + + return btrfs_commit_transaction(trans); } int btrfs_quota_disable(struct btrfs_fs_info *fs_info) |