From: Wang Yugui <wangyugui@e16-tech.com>
To: Stefan Roesch <shr@fb.com>
Cc: <linux-btrfs@vger.kernel.org>, <kernel-team@fb.com>
Subject: Re: [PATCH v6 1/4] btrfs: store chunk size in space-info struct.
Date: Sat, 23 Jul 2022 07:49:37 +0800 [thread overview]
Message-ID: <20220723074936.30FD.409509F4@e16-tech.com> (raw)
In-Reply-To: <20211203220445.2312182-2-shr@fb.com>
Hi,
In this patch, the max chunk size is changed from
BTRFS_MAX_DATA_CHUNK_SIZE(10G) to SZ_1G without any comment ?
Best Regards
Wang Yugui (wangyugui@e16-tech.com)
2022/07/23
> The chunk size is stored in the btrfs_space_info structure.
> It is initialized at the start and is then used.
>
> A new api is added to update the current chunk size.
>
> This api is used to be able to expose the chunk_size
> as a sysfs setting.
>
> Signed-off-by: Stefan Roesch <shr@fb.com>
> ---
> fs/btrfs/space-info.c | 41 +++++++++++++++++++++++++++++++++++++++++
> fs/btrfs/space-info.h | 3 +++
> fs/btrfs/volumes.c | 28 +++++++++-------------------
> 3 files changed, 53 insertions(+), 19 deletions(-)
>
> diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
> index 79fe0ad17acf..437d1240f491 100644
> --- a/fs/btrfs/space-info.c
> +++ b/fs/btrfs/space-info.c
> @@ -181,6 +181,46 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info)
> found->full = 0;
> }
>
> +/*
> + * Compute chunk size depending on block type for regular volumes.
> + */
> +static u64 compute_chunk_size_regular(struct btrfs_fs_info *info, u64 flags)
> +{
> + ASSERT(flags & BTRFS_BLOCK_GROUP_TYPE_MASK);
> +
> + if (flags & BTRFS_BLOCK_GROUP_DATA)
> + return SZ_1G;
> + else if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
> + return SZ_32M;
> +
> + /* Handle BTRFS_BLOCK_GROUP_METADATA */
> + if (info->fs_devices->total_rw_bytes > 50ULL * SZ_1G)
> + return SZ_1G;
> +
> + return SZ_256M;
> +}
> +
> +/*
> + * Compute chunk size depending on volume type.
> + */
> +static u64 compute_chunk_size(struct btrfs_fs_info *info, u64 flags)
> +{
> + if (btrfs_is_zoned(info))
> + return info->zone_size;
> +
> + return compute_chunk_size_regular(info, flags);
> +}
> +
> +/*
> + * Update default chunk size.
> + *
> + */
> +void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
> + u64 chunk_size)
> +{
> + atomic64_set(&space_info->chunk_size, chunk_size);
> +}
> +
> static int create_space_info(struct btrfs_fs_info *info, u64 flags)
> {
>
> @@ -202,6 +242,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
> INIT_LIST_HEAD(&space_info->tickets);
> INIT_LIST_HEAD(&space_info->priority_tickets);
> space_info->clamp = 1;
> + btrfs_update_space_info_chunk_size(space_info, compute_chunk_size(info, flags));
>
> ret = btrfs_sysfs_add_space_info_type(info, space_info);
> if (ret)
> diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
> index d841fed73492..c1a64bbfb6d1 100644
> --- a/fs/btrfs/space-info.h
> +++ b/fs/btrfs/space-info.h
> @@ -23,6 +23,7 @@ struct btrfs_space_info {
> u64 max_extent_size; /* This will hold the maximum extent size of
> the space info if we had an ENOSPC in the
> allocator. */
> + atomic64_t chunk_size; /* chunk size in bytes */
>
> int clamp; /* Used to scale our threshold for preemptive
> flushing. The value is >> clamp, so turns
> @@ -115,6 +116,8 @@ void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags,
> u64 total_bytes, u64 bytes_used,
> u64 bytes_readonly, u64 bytes_zone_unusable,
> struct btrfs_space_info **space_info);
> +void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info,
> + u64 chunk_size);
> struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info,
> u64 flags);
> u64 __pure btrfs_space_info_used(struct btrfs_space_info *s_info,
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index f38c230111be..546c39551648 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5106,26 +5106,16 @@ static void init_alloc_chunk_ctl_policy_regular(
> struct btrfs_fs_devices *fs_devices,
> struct alloc_chunk_ctl *ctl)
> {
> - u64 type = ctl->type;
> + struct btrfs_space_info *space_info;
>
> - if (type & BTRFS_BLOCK_GROUP_DATA) {
> - ctl->max_stripe_size = SZ_1G;
> - ctl->max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE;
> - } else if (type & BTRFS_BLOCK_GROUP_METADATA) {
> - /* For larger filesystems, use larger metadata chunks */
> - if (fs_devices->total_rw_bytes > 50ULL * SZ_1G)
> - ctl->max_stripe_size = SZ_1G;
> - else
> - ctl->max_stripe_size = SZ_256M;
> - ctl->max_chunk_size = ctl->max_stripe_size;
> - } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) {
> - ctl->max_stripe_size = SZ_32M;
> - ctl->max_chunk_size = 2 * ctl->max_stripe_size;
> - ctl->devs_max = min_t(int, ctl->devs_max,
> - BTRFS_MAX_DEVS_SYS_CHUNK);
> - } else {
> - BUG();
> - }
> + space_info = btrfs_find_space_info(fs_devices->fs_info, ctl->type);
> + ASSERT(space_info);
> +
> + ctl->max_chunk_size = atomic64_read(&space_info->chunk_size);
> + ctl->max_stripe_size = ctl->max_chunk_size;
> +
> + if (ctl->type & BTRFS_BLOCK_GROUP_SYSTEM)
> + ctl->devs_max = min_t(int, ctl->devs_max, BTRFS_MAX_DEVS_SYS_CHUNK);
>
> /* We don't want a chunk larger than 10% of writable space */
> ctl->max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1),
> --
> 2.30.2
next prev parent reply other threads:[~2022-07-22 23:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-03 22:04 [PATCH v6 0/4] btrfs: sysfs: set / query btrfs chunk size Stefan Roesch
2021-12-03 22:04 ` [PATCH v6 1/4] btrfs: store chunk size in space-info struct Stefan Roesch
2022-07-22 23:49 ` Wang Yugui [this message]
2022-07-25 13:41 ` David Sterba
2022-07-25 22:25 ` Wang Yugui
2022-07-26 17:08 ` David Sterba
2022-07-29 1:23 ` Wang Yugui
2022-07-29 2:05 ` Wang Yugui
2022-07-29 3:14 ` Wang Yugui
2022-07-29 4:44 ` Wang Yugui
2022-08-18 6:32 ` Qu Wenruo
2021-12-03 22:04 ` [PATCH v6 2/4] btrfs: expose chunk size in sysfs Stefan Roesch
2021-12-03 22:04 ` [PATCH v6 3/4] btrfs: add force_chunk_alloc sysfs entry to force allocation Stefan Roesch
2021-12-03 22:04 ` [PATCH v6 4/4] btrfs: increase metadata alloc size to 5GB for volumes > 50GB Stefan Roesch
2022-08-18 10:40 ` [PATCH v6 0/4] btrfs: sysfs: set / query btrfs chunk size Qu Wenruo
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=20220723074936.30FD.409509F4@e16-tech.com \
--to=wangyugui@e16-tech.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=shr@fb.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 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).