btrfs: qgroup: prealloc btrfs_qgroup_list for __add_relation_rb()
authorQu Wenruo <wqu@suse.com>
Fri, 1 Sep 2023 02:11:16 +0000 (10:11 +0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:03 +0000 (16:44 +0200)
commit79ace7b807281ed4c9c4a847ef9bce71a4f5fa97
tree9210656670c679b58574cfcae81c3e042cf97f29
parent8d54518b5e52e5b351cb5893f83990093699e415
btrfs: qgroup: prealloc btrfs_qgroup_list for __add_relation_rb()

Currently we go GFP_ATOMIC allocation for qgroup relation add, this
includes the following 3 call sites:

- btrfs_read_qgroup_config()
  This is not really needed, as at that time we're still in single
  thread mode, and no spin lock is held.

- btrfs_add_qgroup_relation()
  This one is holding a spinlock, but we're ensured to add at most one
  relation, thus we can easily do a preallocation and use the
  preallocated memory to avoid GFP_ATOMIC.

- btrfs_qgroup_inherit()
  This is a little more tricky, as we may have as many relationships as
  inherit::num_qgroups.
  Thus we have to properly allocate an array then preallocate all the
  memory.

This patch would remove the GFP_ATOMIC allocation for above involved
call sites, by doing preallocation before holding the spinlock, and let
__add_relation_rb() to handle the freeing of the structure.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/qgroup.c