Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>,
	Naohiro Aota <naohiro.aota@wdc.com>, Qu Wenruo <wqu@suse.com>,
	Mark Korenberg <socketpair@gmail.com>,
	Dongjiang Zhu <zhudongjiang@fygo.io>
Subject: Re: [PATCH 3/4] btrfs-progs: zoned: add btrfs_get_max_active_zones()
Date: Tue, 17 Nov 2026 04:03:48 -0800	[thread overview]
Message-ID: <99260fd7-796c-464b-8a9d-d13622945156@kernel.org> (raw)
In-Reply-To: <20261117084948.3848762-4-johannes.thumshirn@wdc.com>

On 11/17/26 00:49, Johannes Thumshirn wrote:
> Return the active zone limit the kernel uses for a device, the same as
> btrfs_get_max_active_zones() there: the smaller non-zero of
> max_active_zones and max_open_zones, a default otherwise, at least
> BTRFS_MIN_ACTIVE_ZONES.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  kernel-shared/zoned.c | 23 +++++++++++++++++++++++
>  kernel-shared/zoned.h |  1 +
>  2 files changed, 24 insertions(+)
> 
> diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c
> index 48313ccc..89ba544a 100644
> --- a/kernel-shared/zoned.c
> +++ b/kernel-shared/zoned.c
> @@ -67,6 +67,7 @@ static u64 emulated_zone_size = DEFAULT_EMULATED_ZONE_SIZE;
>   * - 1 zone for relocation
>   */
>  #define BTRFS_MIN_ACTIVE_ZONES		(BTRFS_SUPER_MIRROR_MAX + 5)
> +#define BTRFS_DEFAULT_MAX_ACTIVE_ZONES	128
>  
>  static int btrfs_get_dev_zone_info(struct btrfs_device *device);
>  
> @@ -155,6 +156,28 @@ static unsigned int max_active_zone_count(const char *file)
>  	return strtoul((const char *)buf, NULL, 10);
>  }
>  
> +/*
> + * Same limit as btrfs_get_max_active_zones() in the kernel. Unlike the kernel
> + * this returns it instead of setting zone_info->max_active_zones, which stays
> + * the device's max_active_zones in progs.
> + */
> +unsigned int btrfs_get_max_active_zones(struct btrfs_device *device)
> +{
> +	unsigned int max_active_zones = max_active_zone_count(device->name);
> +	unsigned int max_open_zones = 0;
> +	char buf[32];
> +
> +	if (device_get_queue_param(device->name, "max_open_zones", buf, sizeof(buf)) > 0)
> +		max_open_zones = strtoul(buf, NULL, 10);
> +	if (!max_active_zones || (max_open_zones && max_open_zones < max_active_zones))
> +		max_active_zones = max_open_zones;
> +	if (max_active_zones == 0)
> +		max_active_zones = min_t(u32, device->zone_info->nr_zones / 4,
> +					 BTRFS_DEFAULT_MAX_ACTIVE_ZONES);
> +
> +	return max_t(unsigned int, max_active_zones, BTRFS_MIN_ACTIVE_ZONES);

I am confused here. If we endup with max_active_zones being lower than
BTRFS_MIN_ACTIVE_ZONES, because the max open zone limit is lower or the drive
indeed has a lower limit than 128, it seems to be very wrong to return the
larger BTRFS_MIN_ACTIVE_ZONES...

So shouldn't this be:

	if (max_active_zones)
		return max_active_zones;
	return BTRFS_MIN_ACTIVE_ZONES;
	

> +}
> +
>  #ifdef BTRFS_ZONED
>  /*
>   * Emulate blkdev_report_zones() for a non-zoned device. It slices up the block
> diff --git a/kernel-shared/zoned.h b/kernel-shared/zoned.h
> index 363ef4a7..e323baf1 100644
> --- a/kernel-shared/zoned.h
> +++ b/kernel-shared/zoned.h
> @@ -99,6 +99,7 @@ static inline void btrfs_free_zoned_device_info(struct btrfs_zoned_device_info *
>  }
>  
>  int btrfs_get_dev_zone_info_all_devices(struct btrfs_fs_info *fs_info);
> +unsigned int btrfs_get_max_active_zones(struct btrfs_device *device);
>  int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
>  
>  #ifdef BTRFS_ZONED


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2026-11-17 12:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  8:49 [PATCH 0/4] btrfs-progs: zoned: detect and repair FS with exhausted active zones Johannes Thumshirn
2026-11-17  8:49 ` [PATCH 1/4] btrfs-progs: zoned: use cached zone reports if available Johannes Thumshirn
2026-11-17 11:59   ` Damien Le Moal
2026-11-17  8:49 ` [PATCH 2/4] btrfs-progs: zoned: add btrfs_finish_dev_zone() Johannes Thumshirn
2026-11-17 11:59   ` Damien Le Moal
2026-11-17  8:49 ` [PATCH 3/4] btrfs-progs: zoned: add btrfs_get_max_active_zones() Johannes Thumshirn
2026-11-17 12:03   ` Damien Le Moal [this message]
2026-11-17  8:49 ` [PATCH 4/4] btrfs-progs: check: detect and repair exhausted zoned active zones 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=99260fd7-796c-464b-8a9d-d13622945156@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=naohiro.aota@wdc.com \
    --cc=socketpair@gmail.com \
    --cc=wqu@suse.com \
    --cc=zhudongjiang@fygo.io \
    /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