From: Josef Bacik <josef@toxicpanda.com>
To: Naohiro Aota <naohiro.aota@wdc.com>
Cc: linux-btrfs@vger.kernel.org,
Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: Re: [PATCH v3 06/13] btrfs: introduce space_info argument to btrfs_chunk_alloc
Date: Thu, 17 Apr 2025 08:38:49 -0400 [thread overview]
Message-ID: <20250417123849.GA3574107@perftesting> (raw)
In-Reply-To: <bf7314dc720dbeb1de64b95512cc796fdaba7ef3.1744813603.git.naohiro.aota@wdc.com>
On Wed, Apr 16, 2025 at 11:28:11PM +0900, Naohiro Aota wrote:
> Take an optional btrfs_space_info argument in btrfs_chunk_alloc(). If
> specified, btrfs_chunk_alloc() works on the space_info. If not, the default
> space_info is used as the same as before.
>
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
For consistency sake I'd prefer if you'd just update the callers to lookup the
space_info and pass that in as appropriate. In fact a lot of these callers
already have the block group or space_info available, so we could avoid the
extra overhead of doing a lookup
> ---
> fs/btrfs/block-group.c | 19 ++++++++++++-------
> fs/btrfs/block-group.h | 3 ++-
> fs/btrfs/extent-tree.c | 2 +-
> fs/btrfs/space-info.c | 2 +-
> fs/btrfs/transaction.c | 2 +-
> 5 files changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index b700d80089d3..12cc9069d4bb 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -3018,7 +3018,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
> */
> alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags);
> if (alloc_flags != cache->flags) {
> - ret = btrfs_chunk_alloc(trans, alloc_flags,
> + ret = btrfs_chunk_alloc(trans, NULL, alloc_flags,
> CHUNK_ALLOC_FORCE);
Here we just do cache->space_info;
> /*
> * ENOSPC is allowed here, we may have enough space
> @@ -3047,7 +3047,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
> goto unlock_out;
>
> alloc_flags = btrfs_get_alloc_profile(fs_info, cache->space_info->flags);
> - ret = btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE);
> + ret = btrfs_chunk_alloc(trans, NULL, alloc_flags, CHUNK_ALLOC_FORCE);
Same here.
> if (ret < 0)
> goto out;
> /*
> @@ -3899,7 +3899,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type)
> {
> u64 alloc_flags = btrfs_get_alloc_profile(trans->fs_info, type);
>
> - return btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE);
> + return btrfs_chunk_alloc(trans, NULL, alloc_flags, CHUNK_ALLOC_FORCE);
Here we'd have to lookup.
> }
>
> static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags)
> @@ -4102,12 +4102,15 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans
> * - return 0 if it doesn't need to allocate a new chunk,
> * - return 1 if it successfully allocates a chunk,
> * - return errors including -ENOSPC otherwise.
> + *
> + * @space_info can optionally be specified to make a new chunk belong to it. If
> + * it is NULL, it is set automatically.
> */
> -int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
> +int btrfs_chunk_alloc(struct btrfs_trans_handle *trans,
> + struct btrfs_space_info *space_info, u64 flags,
> enum btrfs_chunk_alloc_enum force)
> {
> struct btrfs_fs_info *fs_info = trans->fs_info;
> - struct btrfs_space_info *space_info;
> struct btrfs_block_group *ret_bg;
> bool wait_for_alloc = false;
> bool should_alloc = false;
> @@ -4146,8 +4149,10 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
> if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
> return -ENOSPC;
>
> - space_info = btrfs_find_space_info(fs_info, flags);
> - ASSERT(space_info);
> + if (!space_info) {
> + space_info = btrfs_find_space_info(fs_info, flags);
> + ASSERT(space_info);
> + }
>
> do {
> spin_lock(&space_info->lock);
> diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h
> index 36937eeab9b8..c01f3af726a1 100644
> --- a/fs/btrfs/block-group.h
> +++ b/fs/btrfs/block-group.h
> @@ -342,7 +342,8 @@ int btrfs_add_reserved_bytes(struct btrfs_block_group *cache,
> bool force_wrong_size_class);
> void btrfs_free_reserved_bytes(struct btrfs_block_group *cache,
> u64 num_bytes, int delalloc);
> -int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
> +int btrfs_chunk_alloc(struct btrfs_trans_handle *trans,
> + struct btrfs_space_info *space_info, u64 flags,
> enum btrfs_chunk_alloc_enum force);
> int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type);
> void check_system_chunk(struct btrfs_trans_handle *trans, const u64 type);
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index a68a8a07caff..1dad1a42c9c1 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -4159,7 +4159,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info,
> return ret;
> }
>
> - ret = btrfs_chunk_alloc(trans, ffe_ctl->flags,
> + ret = btrfs_chunk_alloc(trans, NULL, ffe_ctl->flags,
> CHUNK_ALLOC_FORCE_FOR_EXTENT);
We'd have to look up here.
>
> /* Do not bail out on ENOSPC since we can do more. */
> diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
> index d6d33ab754ba..2489c2a16123 100644
> --- a/fs/btrfs/space-info.c
> +++ b/fs/btrfs/space-info.c
> @@ -817,7 +817,7 @@ static void flush_space(struct btrfs_fs_info *fs_info,
> ret = PTR_ERR(trans);
> break;
> }
> - ret = btrfs_chunk_alloc(trans,
> + ret = btrfs_chunk_alloc(trans, space_info,
> btrfs_get_alloc_profile(fs_info, space_info->flags),
> (state == ALLOC_CHUNK) ? CHUNK_ALLOC_NO_FORCE :
> CHUNK_ALLOC_FORCE);
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index 39e48bf610a1..670e0527996c 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -763,7 +763,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
> if (do_chunk_alloc && num_bytes) {
> u64 flags = h->block_rsv->space_info->flags;
>
> - btrfs_chunk_alloc(h, btrfs_get_alloc_profile(fs_info, flags),
> + btrfs_chunk_alloc(h, NULL, btrfs_get_alloc_profile(fs_info, flags),
> CHUNK_ALLOC_NO_FORCE);
Here we just do h->block_rsv->space_info. Thanks,
Josef
next prev parent reply other threads:[~2025-04-17 12:38 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-16 14:28 [PATCH v3 00/13] btrfs: zoned: split out space_info for dedicated block groups Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 01/13] btrfs: take btrfs_space_info in btrfs_reserve_data_bytes Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 02/13] btrfs: take struct btrfs_inode in btrfs_free_reserved_data_space_noquota Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 03/13] btrfs: factor out init_space_info() Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 04/13] btrfs: spin out do_async_reclaim_{data,metadata}_space() Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 05/13] btrfs: factor out check_removing_space_info() Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 06/13] btrfs: introduce space_info argument to btrfs_chunk_alloc Naohiro Aota
2025-04-17 12:38 ` Josef Bacik [this message]
2025-04-18 0:59 ` Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 07/13] btrfs: pass space_info for block group creation Naohiro Aota
2025-04-17 12:40 ` Josef Bacik
2025-04-16 14:28 ` [PATCH v3 08/13] btrfs: introduce btrfs_space_info sub-group Naohiro Aota
2025-04-16 14:56 ` Johannes Thumshirn
2025-04-17 12:43 ` Josef Bacik
2025-04-16 14:28 ` [PATCH v3 09/13] btrfs: introduce tree-log sub-space_info Naohiro Aota
2025-04-16 14:57 ` Johannes Thumshirn
2025-04-17 12:44 ` Josef Bacik
2025-04-18 1:08 ` Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 10/13] btrfs: tweak extent/chunk allocation for space_info sub-space Naohiro Aota
2025-04-17 5:48 ` Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 11/13] btrfs: use proper data space_info Naohiro Aota
2025-04-16 14:59 ` Johannes Thumshirn
2025-04-17 4:35 ` Naohiro Aota
2025-04-16 14:28 ` [PATCH v3 12/13] btrfs: add block_rsv for treelog Naohiro Aota
2025-04-17 12:48 ` Josef Bacik
2025-04-16 14:28 ` [PATCH v3 13/13] btrfs: reclaim from sub-space space_info Naohiro Aota
2025-04-17 12:49 ` Josef Bacik
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=20250417123849.GA3574107@perftesting \
--to=josef@toxicpanda.com \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.