btrfs: qgroup: pre-allocate btrfs_qgroup to reduce GFP_ATOMIC usage
authorQu Wenruo <wqu@suse.com>
Tue, 29 Aug 2023 11:48:57 +0000 (19:48 +0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 12 Oct 2023 14:44:03 +0000 (16:44 +0200)
commit8d54518b5e52e5b351cb5893f83990093699e415
tree7c23fcecebee21d7a905d54a74a1fde1be0868dd
parentdce28769a33a95425b007f00842d6e12ffa28f83
btrfs: qgroup: pre-allocate btrfs_qgroup to reduce GFP_ATOMIC usage

Qgroup is the heaviest user of GFP_ATOMIC, but one call site does not
really need GFP_ATOMIC, that is add_qgroup_rb().

That function only searches the rbtree to find if we already have such
entry.  If not, then it would try to allocate memory for it.

This means we can afford to pre-allocate such structure unconditionally,
then free the memory if it's not needed.

Considering this function is not a hot path, only utilized by the
following functions:

- btrfs_qgroup_inherit()
  For "btrfs subvolume snapshot -i" option.

- btrfs_read_qgroup_config()
  At mount time, and we're ensured there would be no existing rb tree
  entry for each qgroup.

- btrfs_create_qgroup()

Thus we're completely safe to pre-allocate the extra memory for btrfs_qgroup
structure, and reduce unnecessary GFP_ATOMIC usage.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
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