]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: reduce space_info critical section in btrfs_chunk_alloc()
authorFilipe Manana <fdmanana@suse.com>
Mon, 20 Oct 2025 11:39:52 +0000 (12:39 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:13:25 +0000 (22:13 +0100)
There's no need to update local variables while holding the space_info's
spinlock, since the update isn't using anything from the space_info. So
move these updates outside the critical section to shorten it.

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/block-group.c

index ec1e4fc0cd51ec0d04faffa0ff7cc4b102855da2..ebd4c514c2c85ffa0293e56af3e3625d79d186cb 100644 (file)
@@ -4191,11 +4191,11 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans,
                should_alloc = should_alloc_chunk(fs_info, space_info, force);
                if (space_info->full) {
                        /* No more free physical space */
+                       spin_unlock(&space_info->lock);
                        if (should_alloc)
                                ret = -ENOSPC;
                        else
                                ret = 0;
-                       spin_unlock(&space_info->lock);
                        return ret;
                } else if (!should_alloc) {
                        spin_unlock(&space_info->lock);
@@ -4207,16 +4207,16 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans,
                         * recheck if we should continue with our allocation
                         * attempt.
                         */
+                       spin_unlock(&space_info->lock);
                        wait_for_alloc = true;
                        force = CHUNK_ALLOC_NO_FORCE;
-                       spin_unlock(&space_info->lock);
                        mutex_lock(&fs_info->chunk_mutex);
                        mutex_unlock(&fs_info->chunk_mutex);
                } else {
                        /* Proceed with allocation */
                        space_info->chunk_alloc = true;
-                       wait_for_alloc = false;
                        spin_unlock(&space_info->lock);
+                       wait_for_alloc = false;
                }
 
                cond_resched();