public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: Stefan Roesch <shr@fb.com>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH v2 1/4] btrfs: store stripe size and chunk size in space-info struct.
Date: Thu, 28 Oct 2021 09:48:43 -0400	[thread overview]
Message-ID: <YXqqO7Le8sSWpOEG@localhost.localdomain> (raw)
In-Reply-To: <20211027201441.3813178-2-shr@fb.com>

On Wed, Oct 27, 2021 at 01:14:38PM -0700, Stefan Roesch wrote:
> The stripe size and chunk size are stored in the btrfs_space_info
> structure. They are initialized at the start and are then used.
> 
> Two api's are added to get the current value and one to update
> the value.
> 
> These api's will be used to be able to expose the stripe_size
> as a sysfs setting.
> 
> Signed-off-by: Stefan Roesch <shr@fb.com>
> ---
>  fs/btrfs/space-info.c | 72 +++++++++++++++++++++++++++++++++++++++++++
>  fs/btrfs/space-info.h |  4 +++
>  fs/btrfs/volumes.c    | 28 ++++++-----------
>  3 files changed, 85 insertions(+), 19 deletions(-)
> 
> diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
> index 48d77f360a24..570acfebeae4 100644
> --- a/fs/btrfs/space-info.c
> +++ b/fs/btrfs/space-info.c
> @@ -181,6 +181,74 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info)
>  		found->full = 0;
>  }
>  
> +/*
> + * Compute stripe size depending on block type for regular volumes.
> + */
> +static u64 compute_stripe_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 stripe size for zoned volumes.
> + */
> +static u64 compute_stripe_size_zoned(struct btrfs_fs_info *info)
> +{
> +	return info->zone_size;
> +}
> +
> +/*
> + * Compute stripe size depending on volume type.
> + */
> +static u64 compute_stripe_size(struct btrfs_fs_info *info, u64 flags)
> +{
> +	if (btrfs_is_zoned(info))
> +		return compute_stripe_size_zoned(info);
> +
> +	return compute_stripe_size_regular(info, flags);
> +}
> +
> +/*
> + * Compute chunk size depending on block type and stripe size.
> + */
> +static u64 compute_chunk_size(u64 flags, u64 max_stripe_size)
> +{
> +	ASSERT(flags & BTRFS_BLOCK_GROUP_TYPE_MASK);
> +
> +	if (flags & BTRFS_BLOCK_GROUP_DATA)
> +		return BTRFS_MAX_DATA_CHUNK_SIZE;
> +	else if (flags & BTRFS_BLOCK_GROUP_METADATA)
> +		return max_stripe_size;
> +
> +	/* Handle BTRFS_BLOCK_GROUP_SYSTEM */
> +	return 2 * max_stripe_size;
> +}
> +
> +/*
> + * Update maximum stripe size and chunk size.
> + *
> + */
> +void btrfs_update_space_info_max_alloc_sizes(struct btrfs_space_info *space_info,
> +					     u64 flags, u64 max_stripe_size)
> +{
> +	spin_lock(&space_info->lock);
> +	space_info->max_stripe_size = max_stripe_size;
> +	space_info->max_chunk_size = compute_chunk_size(flags,
> +						space_info->max_stripe_size);
> +	spin_unlock(&space_info->lock);
> +}
> +
>  static int create_space_info(struct btrfs_fs_info *info, u64 flags)
>  {
>  
> @@ -203,6 +271,10 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
>  	INIT_LIST_HEAD(&space_info->priority_tickets);
>  	space_info->clamp = 1;
>  
> +	space_info->max_stripe_size = compute_stripe_size(info, flags);
> +	space_info->max_chunk_size = compute_chunk_size(flags,
> +						space_info->max_stripe_size);
> +
>  	ret = btrfs_sysfs_add_space_info_type(info, space_info);
>  	if (ret)
>  		return ret;
> diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h
> index cb5056472e79..5ee3e381de38 100644
> --- a/fs/btrfs/space-info.h
> +++ b/fs/btrfs/space-info.h
> @@ -23,6 +23,8 @@ 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. */
> +	u64 max_chunk_size; /* maximum chunk size in bytes */
> +	u64 max_stripe_size; /* maximum stripe size in bytes */

max_chunk_size isn't user set-able, and can be calculated from the
max_stripe_size.  You may change the names based on my previous emails, but
whatever it ends up being you only need one of these stored, the other can be
inferred.  Thanks,

Josef

  reply	other threads:[~2021-10-28 13:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-27 20:14 [PATCH v2 0/4] btrfs: sysfs: set / query btrfs stripe size Stefan Roesch
2021-10-27 20:14 ` [PATCH v2 1/4] btrfs: store stripe size and chunk size in space-info struct Stefan Roesch
2021-10-28 13:48   ` Josef Bacik [this message]
2021-10-27 20:14 ` [PATCH v2 2/4] btrfs: expose stripe and chunk size in sysfs Stefan Roesch
2021-10-27 20:14 ` [PATCH v2 3/4] btrfs: add force_chunk_alloc sysfs entry to force allocation Stefan Roesch
2021-10-27 20:14 ` [PATCH v2 4/4] btrfs: increase metadata alloc size to 5GB for volumes > 50GB Stefan Roesch
2021-10-28  1:14   ` Wang Yugui
2021-10-28 13:43 ` [PATCH v2 0/4] btrfs: sysfs: set / query btrfs stripe size Josef Bacik
2021-10-28 14:27   ` Josef Bacik
2021-10-28 15:00     ` Johannes Thumshirn
2021-10-29  3:11       ` Stefan Roesch
2021-10-29  8:31         ` Johannes Thumshirn

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=YXqqO7Le8sSWpOEG@localhost.localdomain \
    --to=josef@toxicpanda.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