linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: zoned: set pseudo max append zone limit in zone emulation mode
@ 2022-08-26  2:04 Shin'ichiro Kawasaki
  2022-08-26  5:39 ` Naohiro Aota
  0 siblings, 1 reply; 3+ messages in thread
From: Shin'ichiro Kawasaki @ 2022-08-26  2:04 UTC (permalink / raw)
  To: linux-btrfs, David Sterba
  Cc: Johannes Thumshirn, Naohiro Aota, Shin'ichiro Kawasaki

The commit 7d7672bc5d10 ("btrfs: convert count_max_extents() to use
fs_info->max_extent_size") introduced a division by
fs_info->max_extent_size. This max_extent_size is initialized with max
zone append limit size of the device btrfs runs on. However, in zone
emulation mode, the device is not zoned then its zone append limit is
zero. This resulted in zero value of fs_info->max_extent_size and caused
zero division error.

Fix the error by setting non-zero pseudo value to max append zone limit
in zone emulation mode. Set the pseudo value based on max_segments as
suggested in the commit c2ae7b772ef4 ("btrfs: zoned: revive
max_zone_append_bytes").

Fixes: 7d7672bc5d10 ("btrfs: convert count_max_extents() to use fs_info->max_extent_size")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 fs/btrfs/zoned.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index b150b07ba1a7..560dd0a67536 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -421,10 +421,19 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
 	 * since btrfs adds the pages one by one to a bio, and btrfs cannot
 	 * increase the metadata reservation even if it increases the number of
 	 * extents, it is safe to stick with the limit.
+	 *
+	 * When zoned btrfs is in zone emulation mode, bdev is a non-zoned
+	 * device and does not have valid max zone append size. In this case,
+	 * use max_segments * PAGE_SIZE as the pseudo max_zone_append_size.
 	 */
-	zone_info->max_zone_append_size =
-		min_t(u64, (u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT,
-		      (u64)bdev_max_segments(bdev) << PAGE_SHIFT);
+	if (bdev_is_zoned(bdev)) {
+		zone_info->max_zone_append_size = min_t(u64,
+			(u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT,
+			(u64)bdev_max_segments(bdev) << PAGE_SHIFT);
+	} else {
+		zone_info->max_zone_append_size =
+			bdev_max_segments(bdev) << PAGE_SHIFT;
+	}
 	if (!IS_ALIGNED(nr_sectors, zone_sectors))
 		zone_info->nr_zones++;
 
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: zoned: set pseudo max append zone limit in zone emulation mode
  2022-08-26  2:04 [PATCH] btrfs: zoned: set pseudo max append zone limit in zone emulation mode Shin'ichiro Kawasaki
@ 2022-08-26  5:39 ` Naohiro Aota
  2022-08-26  6:37   ` Shinichiro Kawasaki
  0 siblings, 1 reply; 3+ messages in thread
From: Naohiro Aota @ 2022-08-26  5:39 UTC (permalink / raw)
  To: Shinichiro Kawasaki; +Cc: linux-btrfs, David Sterba, Johannes Thumshirn

On Fri, Aug 26, 2022 at 11:04:00AM +0900, Shin'ichiro Kawasaki wrote:
> The commit 7d7672bc5d10 ("btrfs: convert count_max_extents() to use
> fs_info->max_extent_size") introduced a division by
> fs_info->max_extent_size. This max_extent_size is initialized with max
> zone append limit size of the device btrfs runs on. However, in zone
> emulation mode, the device is not zoned then its zone append limit is
> zero. This resulted in zero value of fs_info->max_extent_size and caused
> zero division error.
> 
> Fix the error by setting non-zero pseudo value to max append zone limit
> in zone emulation mode. Set the pseudo value based on max_segments as
> suggested in the commit c2ae7b772ef4 ("btrfs: zoned: revive
> max_zone_append_bytes").
> 
> Fixes: 7d7672bc5d10 ("btrfs: convert count_max_extents() to use fs_info->max_extent_size")
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> ---
>  fs/btrfs/zoned.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index b150b07ba1a7..560dd0a67536 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -421,10 +421,19 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
>  	 * since btrfs adds the pages one by one to a bio, and btrfs cannot
>  	 * increase the metadata reservation even if it increases the number of
>  	 * extents, it is safe to stick with the limit.
> +	 *
> +	 * When zoned btrfs is in zone emulation mode, bdev is a non-zoned
> +	 * device and does not have valid max zone append size. In this case,
> +	 * use max_segments * PAGE_SIZE as the pseudo max_zone_append_size.

Using 'zoned filesystem' or 'zoned mode' is preferred to 'zoned
btrfs'. And, 'zoned btrfs is in zone emulation mode' looks a bit wordy. So,
how about this?

   With the zoned emulation, we can have non-zoned device on the zoned
   mode. In this case, we don't have a valid max zone append size. So, use
   ...

>  	 */
> -	zone_info->max_zone_append_size =
> -		min_t(u64, (u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT,
> -		      (u64)bdev_max_segments(bdev) << PAGE_SHIFT);
> +	if (bdev_is_zoned(bdev)) {
> +		zone_info->max_zone_append_size = min_t(u64,
> +			(u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT,
> +			(u64)bdev_max_segments(bdev) << PAGE_SHIFT);
> +	} else {
> +		zone_info->max_zone_append_size =
> +			bdev_max_segments(bdev) << PAGE_SHIFT;

We need to cast it to "(u64)" to keep enough bit width.

> +	}
>  	if (!IS_ALIGNED(nr_sectors, zone_sectors))
>  		zone_info->nr_zones++;
>  
> -- 
> 2.37.2
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: zoned: set pseudo max append zone limit in zone emulation mode
  2022-08-26  5:39 ` Naohiro Aota
@ 2022-08-26  6:37   ` Shinichiro Kawasaki
  0 siblings, 0 replies; 3+ messages in thread
From: Shinichiro Kawasaki @ 2022-08-26  6:37 UTC (permalink / raw)
  To: Naohiro Aota; +Cc: linux-btrfs, David Sterba, Johannes Thumshirn

On Aug 26, 2022 / 05:39, Naohiro Aota wrote:
> On Fri, Aug 26, 2022 at 11:04:00AM +0900, Shin'ichiro Kawasaki wrote:
> > The commit 7d7672bc5d10 ("btrfs: convert count_max_extents() to use
> > fs_info->max_extent_size") introduced a division by
> > fs_info->max_extent_size. This max_extent_size is initialized with max
> > zone append limit size of the device btrfs runs on. However, in zone
> > emulation mode, the device is not zoned then its zone append limit is
> > zero. This resulted in zero value of fs_info->max_extent_size and caused
> > zero division error.
> > 
> > Fix the error by setting non-zero pseudo value to max append zone limit
> > in zone emulation mode. Set the pseudo value based on max_segments as
> > suggested in the commit c2ae7b772ef4 ("btrfs: zoned: revive
> > max_zone_append_bytes").
> > 
> > Fixes: 7d7672bc5d10 ("btrfs: convert count_max_extents() to use fs_info->max_extent_size")
> > Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> > ---
> >  fs/btrfs/zoned.c | 15 ++++++++++++---
> >  1 file changed, 12 insertions(+), 3 deletions(-)
> > 
> > diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> > index b150b07ba1a7..560dd0a67536 100644
> > --- a/fs/btrfs/zoned.c
> > +++ b/fs/btrfs/zoned.c
> > @@ -421,10 +421,19 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
> >  	 * since btrfs adds the pages one by one to a bio, and btrfs cannot
> >  	 * increase the metadata reservation even if it increases the number of
> >  	 * extents, it is safe to stick with the limit.
> > +	 *
> > +	 * When zoned btrfs is in zone emulation mode, bdev is a non-zoned
> > +	 * device and does not have valid max zone append size. In this case,
> > +	 * use max_segments * PAGE_SIZE as the pseudo max_zone_append_size.
> 
> Using 'zoned filesystem' or 'zoned mode' is preferred to 'zoned
> btrfs'. And, 'zoned btrfs is in zone emulation mode' looks a bit wordy. So,
> how about this?
> 
>    With the zoned emulation, we can have non-zoned device on the zoned
>    mode. In this case, we don't have a valid max zone append size. So, use
>    ...

Okay, will rephrase as suggested.

> 
> >  	 */
> > -	zone_info->max_zone_append_size =
> > -		min_t(u64, (u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT,
> > -		      (u64)bdev_max_segments(bdev) << PAGE_SHIFT);
> > +	if (bdev_is_zoned(bdev)) {
> > +		zone_info->max_zone_append_size = min_t(u64,
> > +			(u64)bdev_max_zone_append_sectors(bdev) << SECTOR_SHIFT,
> > +			(u64)bdev_max_segments(bdev) << PAGE_SHIFT);
> > +	} else {
> > +		zone_info->max_zone_append_size =
> > +			bdev_max_segments(bdev) << PAGE_SHIFT;
> 
> We need to cast it to "(u64)" to keep enough bit width.

Oops, thanks for the catch. Will fix it in v2.

> 
> > +	}
> >  	if (!IS_ALIGNED(nr_sectors, zone_sectors))
> >  		zone_info->nr_zones++;
> >  
> > -- 
> > 2.37.2
> > 

-- 
Shin'ichiro Kawasaki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-26  6:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26  2:04 [PATCH] btrfs: zoned: set pseudo max append zone limit in zone emulation mode Shin'ichiro Kawasaki
2022-08-26  5:39 ` Naohiro Aota
2022-08-26  6:37   ` Shinichiro Kawasaki

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).