]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: reduce block group critical section in pin_down_extent()
authorFilipe Manana <fdmanana@suse.com>
Mon, 20 Oct 2025 12:37:32 +0000 (13:37 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:15:13 +0000 (22:15 +0100)
There's no need to update the bytes_reserved and bytes_may_use fields of
the space_info while holding the block group's spinlock. We are only
making the critical section longer than necessary. So move the space_info
updates outside of the block group's critical section.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index ae2c3dc9957e6be43fdaa95bdbebdabc3b00f4f5..70b77fe21b9fd68fe213451b6c472f172bceb3f1 100644 (file)
@@ -2594,15 +2594,15 @@ static int pin_down_extent(struct btrfs_trans_handle *trans,
                           struct btrfs_block_group *cache,
                           u64 bytenr, u64 num_bytes, int reserved)
 {
+       const u64 reserved_bytes = (reserved ? num_bytes : 0);
+
        spin_lock(&cache->space_info->lock);
        spin_lock(&cache->lock);
        cache->pinned += num_bytes;
-       btrfs_space_info_update_bytes_pinned(cache->space_info, num_bytes);
-       if (reserved) {
-               cache->reserved -= num_bytes;
-               cache->space_info->bytes_reserved -= num_bytes;
-       }
+       cache->reserved -= reserved_bytes;
        spin_unlock(&cache->lock);
+       cache->space_info->bytes_reserved -= reserved_bytes;
+       btrfs_space_info_update_bytes_pinned(cache->space_info, num_bytes);
        spin_unlock(&cache->space_info->lock);
 
        btrfs_set_extent_bit(&trans->transaction->pinned_extents, bytenr,