linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boris Burkov <boris@bur.io>
To: fdmanana@kernel.org
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 15/16] btrfs: add and use helper to determine if using bitmaps in free space tree
Date: Tue, 17 Jun 2025 14:41:11 -0700	[thread overview]
Message-ID: <20250617214111.GA2330659@zen.localdomain> (raw)
In-Reply-To: <3a6d4004a9bda4c4596d559c7c43b98e74151f11.1750075579.git.fdmanana@suse.com>

On Tue, Jun 17, 2025 at 05:13:10PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> When adding and removing free space to the free space tree, we need to
> lookup the respective block group's free info item in the free space tree,
> check its flags for the BTRFS_FREE_SPACE_USING_BITMAPS bit and then
> release the path.
> 
> Move these steps into a helper function and use it in both sites.
> This will also help avoiding duplicate code in a subsequent change.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
>  fs/btrfs/free-space-tree.c | 50 ++++++++++++++++++++------------------
>  1 file changed, 26 insertions(+), 24 deletions(-)
> 
> diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
> index c85ca7ce2683..3c8bb95fa044 100644
> --- a/fs/btrfs/free-space-tree.c
> +++ b/fs/btrfs/free-space-tree.c
> @@ -791,32 +791,40 @@ static int remove_free_space_extent(struct btrfs_trans_handle *trans,
>  	return update_free_space_extent_count(trans, block_group, path, new_extents);
>  }
>  
> +static int use_bitmaps(struct btrfs_block_group *bg, struct btrfs_path *path)

I think 'using_bitmaps' makes more sense, given the name of the flag.
Ditto for the next patch and the caching variables.

> +{
> +	struct btrfs_free_space_info *info;
> +	u32 flags;
> +
> +	info = btrfs_search_free_space_info(NULL, bg, path, 0);
> +	if (IS_ERR(info))
> +		return PTR_ERR(info);
> +	flags = btrfs_free_space_flags(path->nodes[0], info);
> +	btrfs_release_path(path);
> +
> +	return (flags & BTRFS_FREE_SPACE_USING_BITMAPS) ? 1 : 0;
> +}
> +
>  EXPORT_FOR_TESTS
>  int __btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans,
>  					struct btrfs_block_group *block_group,
>  					struct btrfs_path *path, u64 start, u64 size)
>  {
> -	struct btrfs_free_space_info *info;
> -	u32 flags;
>  	int ret;
>  
>  	ret = __add_block_group_free_space(trans, block_group, path);
>  	if (ret)
>  		return ret;
>  
> -	info = btrfs_search_free_space_info(NULL, block_group, path, 0);
> -	if (IS_ERR(info))
> -		return PTR_ERR(info);
> -	flags = btrfs_free_space_flags(path->nodes[0], info);
> -	btrfs_release_path(path);
> +	ret = use_bitmaps(block_group, path);
> +	if (ret < 0)
> +		return ret;
>  
> -	if (flags & BTRFS_FREE_SPACE_USING_BITMAPS) {
> +	if (ret)
>  		return modify_free_space_bitmap(trans, block_group, path,
>  						start, size, true);
> -	} else {
> -		return remove_free_space_extent(trans, block_group, path,
> -						start, size);
> -	}
> +
> +	return remove_free_space_extent(trans, block_group, path, start, size);
>  }
>  
>  int btrfs_remove_from_free_space_tree(struct btrfs_trans_handle *trans,
> @@ -984,27 +992,21 @@ int __btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans,
>  				   struct btrfs_block_group *block_group,
>  				   struct btrfs_path *path, u64 start, u64 size)
>  {
> -	struct btrfs_free_space_info *info;
> -	u32 flags;
>  	int ret;
>  
>  	ret = __add_block_group_free_space(trans, block_group, path);
>  	if (ret)
>  		return ret;
>  
> -	info = btrfs_search_free_space_info(NULL, block_group, path, 0);
> -	if (IS_ERR(info))
> -		return PTR_ERR(info);
> -	flags = btrfs_free_space_flags(path->nodes[0], info);
> -	btrfs_release_path(path);
> +	ret = use_bitmaps(block_group, path);
> +	if (ret < 0)
> +		return ret;
>  
> -	if (flags & BTRFS_FREE_SPACE_USING_BITMAPS) {
> +	if (ret)
>  		return modify_free_space_bitmap(trans, block_group, path,
>  						start, size, false);
> -	} else {
> -		return add_free_space_extent(trans, block_group, path, start,
> -					     size);
> -	}
> +
> +	return add_free_space_extent(trans, block_group, path, start, size);
>  }
>  
>  int btrfs_add_to_free_space_tree(struct btrfs_trans_handle *trans,
> -- 
> 2.47.2
> 

  reply	other threads:[~2025-06-17 21:39 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17 16:12 [PATCH 00/16] btrfs: free space tree optimization and cleanups fdmanana
2025-06-17 16:12 ` [PATCH 01/16] btrfs: remove pointless out label from add_new_free_space_info() fdmanana
2025-06-17 16:12 ` [PATCH 02/16] btrfs: remove pointless out label from update_free_space_extent_count() fdmanana
2025-06-17 16:12 ` [PATCH 03/16] btrfs: make extent_buffer_test_bit() return a boolean instead fdmanana
2025-06-17 16:12 ` [PATCH 04/16] btrfs: make free_space_test_bit() " fdmanana
2025-06-17 16:13 ` [PATCH 05/16] btrfs: remove pointless out label from modify_free_space_bitmap() fdmanana
2025-06-17 16:13 ` [PATCH 06/16] btrfs: remove pointless out label from remove_free_space_extent() fdmanana
2025-06-17 16:13 ` [PATCH 07/16] btrfs: remove pointless out label from add_free_space_extent() fdmanana
2025-06-17 16:13 ` [PATCH 08/16] btrfs: remove pointless out label from load_free_space_bitmaps() fdmanana
2025-06-17 16:13 ` [PATCH 09/16] btrfs: remove pointless out label from load_free_space_extents() fdmanana
2025-06-17 16:13 ` [PATCH 10/16] btrfs: add btrfs prefix to free space tree exported functions fdmanana
2025-06-17 16:13 ` [PATCH 11/16] btrfs: rename free_space_set_bits() and make it less confusing fdmanana
2025-06-17 16:13 ` [PATCH 12/16] btrfs: turn remove argument of modify_free_space_bitmap() to boolean fdmanana
2025-06-17 16:13 ` [PATCH 13/16] btrfs: avoid double slot decrement at btrfs_convert_free_space_to_extents() fdmanana
2025-06-17 16:13 ` [PATCH 14/16] btrfs: use fs_info from local variable in btrfs_convert_free_space_to_extents() fdmanana
2025-06-17 16:13 ` [PATCH 15/16] btrfs: add and use helper to determine if using bitmaps in free space tree fdmanana
2025-06-17 21:41   ` Boris Burkov [this message]
2025-06-17 16:13 ` [PATCH 16/16] btrfs: cache if we are using free space bitmaps for a block group fdmanana
2025-06-17 21:52   ` Boris Burkov
2025-06-17 21:59     ` Filipe Manana
2025-06-17 22:12       ` Boris Burkov
2025-06-18 11:50 ` [PATCH 00/16] btrfs: free space tree optimization and cleanups David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250617214111.GA2330659@zen.localdomain \
    --to=boris@bur.io \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).