mirror of
https://github.com/torvalds/linux.git
synced 2026-07-31 03:27:03 +02:00
btrfs: reduce block group critical section in btrfs_add_reserved_bytes()
We are doing some things inside the block group's critical section that are relevant only to the space_info: updating the space_info counters bytes_reserved and bytes_may_use as well as trying to grant tickets (calling btrfs_try_granting_tickets()), and this later can take some time. So move all those updates to outside the block group's critical section and still inside the space_info's critical section. Like this we keep the block group's critical section only for block group updates and can help reduce contention on a block group's lock. 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>
This commit is contained in:
parent
8b6fa164ab
commit
a270cb420c
|
|
@ -3813,30 +3813,38 @@ int btrfs_add_reserved_bytes(struct btrfs_block_group *cache,
|
|||
spin_lock(&cache->lock);
|
||||
if (cache->ro) {
|
||||
ret = -EAGAIN;
|
||||
goto out;
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
if (btrfs_block_group_should_use_size_class(cache)) {
|
||||
size_class = btrfs_calc_block_group_size_class(num_bytes);
|
||||
ret = btrfs_use_block_group_size_class(cache, size_class, force_wrong_size_class);
|
||||
if (ret)
|
||||
goto out;
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
cache->reserved += num_bytes;
|
||||
space_info->bytes_reserved += num_bytes;
|
||||
trace_btrfs_space_reservation(cache->fs_info, "space_info",
|
||||
space_info->flags, num_bytes, 1);
|
||||
btrfs_space_info_update_bytes_may_use(space_info, -ram_bytes);
|
||||
if (delalloc)
|
||||
cache->delalloc_bytes += num_bytes;
|
||||
|
||||
trace_btrfs_space_reservation(cache->fs_info, "space_info",
|
||||
space_info->flags, num_bytes, 1);
|
||||
spin_unlock(&cache->lock);
|
||||
|
||||
space_info->bytes_reserved += num_bytes;
|
||||
btrfs_space_info_update_bytes_may_use(space_info, -ram_bytes);
|
||||
|
||||
/*
|
||||
* Compression can use less space than we reserved, so wake tickets if
|
||||
* that happens.
|
||||
*/
|
||||
if (num_bytes < ram_bytes)
|
||||
btrfs_try_granting_tickets(space_info);
|
||||
out:
|
||||
spin_unlock(&space_info->lock);
|
||||
|
||||
return 0;
|
||||
|
||||
out_error:
|
||||
spin_unlock(&cache->lock);
|
||||
spin_unlock(&space_info->lock);
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user