]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: reduce block group critical section in unpin_extent_range()
authorFilipe Manana <fdmanana@suse.com>
Mon, 20 Oct 2025 14:53:01 +0000 (15:53 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:16:20 +0000 (22:16 +0100)
There's no need to update the bytes_pinned, bytes_readonly and
max_extent_size fields of the space_info while inside the critical section
delimited by the block group's lock. So move that out of the block group's
critical section, but sill inside the space_info's critical section.

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

index 36963b4a6303f78523355e681db6e90a3da07152..d839d8d3241252ae8d24c4cf648475efe095987b 100644 (file)
@@ -2747,13 +2747,12 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
        struct btrfs_free_cluster *cluster = NULL;
        u64 total_unpinned = 0;
        u64 empty_cluster = 0;
-       bool readonly;
        int ret = 0;
 
        while (start <= end) {
                u64 len;
+               bool readonly;
 
-               readonly = false;
                if (!cache ||
                    start >= cache->start + cache->length) {
                        if (cache)
@@ -2797,20 +2796,21 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
 
                spin_lock(&space_info->lock);
                spin_lock(&cache->lock);
+               readonly = cache->ro;
                cache->pinned -= len;
+               spin_unlock(&cache->lock);
+
                btrfs_space_info_update_bytes_pinned(space_info, -len);
                space_info->max_extent_size = 0;
-               if (cache->ro) {
+
+               if (readonly) {
                        space_info->bytes_readonly += len;
-                       readonly = true;
                } else if (btrfs_is_zoned(fs_info)) {
                        /* Need reset before reusing in a zoned block group */
                        btrfs_space_info_update_bytes_zone_unusable(space_info, len);
-                       readonly = true;
-               }
-               spin_unlock(&cache->lock);
-               if (!readonly && return_free_space)
+               } else if (return_free_space) {
                        btrfs_return_free_space(space_info, len);
+               }
                spin_unlock(&space_info->lock);
        }