Linux block layer
 help / color / mirror / Atom feed
* [PATCH] zloop: round capacity up to a zone-size multiple
@ 2026-08-03  9:58 raoxu
  2026-08-03 13:02 ` Damien Le Moal
  0 siblings, 1 reply; 7+ messages in thread
From: raoxu @ 2026-08-03  9:58 UTC (permalink / raw)
  To: dlemoal; +Cc: axboe, hch, linux-block, linux-kernel, raoxu, stable

From: Xu Rao <raoxu@uniontech.com>

zloop_ctl_add() derives the number of zones by shifting the requested
capacity by ilog2(zone_size). Since zone_size is validated as a power of
two, this is equivalent to integer division and discards any remainder.
However, Documentation/admin-guide/blockdev/zoned_loop.rst specifies that
capacity_mb is always rounded up to the nearest higher multiple of the
zone size.

Only configurations whose requested capacity is not aligned to the zone
size are affected. Aligned configurations, including the defaults of
16384 MiB capacity and 256 MiB zones, keep the same geometry. An affected
device is also internally consistent and remains usable, but it is
smaller than requested. For example, capacity_mb=130 with
zone_size_mb=64 currently creates two zones and exposes 128 MiB instead
of the documented three zones and 192 MiB. Since this does not cause an
error or an I/O failure, and normal test configurations generally use an
integral number of zones, the discrepancy can remain unnoticed.

Calculate the number of zones with DIV_ROUND_UP_SECTOR_T() so a partial
final zone request is represented by one additional full zone. This
matches the documented control interface while preserving the existing
sector_t handling on both 32-bit and 64-bit architectures.

Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
Cc: stable@vger.kernel.org
Signed-off-by: Xu Rao <raoxu@uniontech.com>
---
 drivers/block/zloop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index b69d798f203c..e29d82ff52ae 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -1187,7 +1187,7 @@ static int zloop_ctl_add(struct zloop_options *opts)

 	__module_get(THIS_MODULE);

-	nr_zones = opts->capacity >> ilog2(opts->zone_size);
+	nr_zones = DIV_ROUND_UP_SECTOR_T(opts->capacity, opts->zone_size);
 	if (opts->nr_conv_zones >= nr_zones) {
 		pr_err("Invalid number of conventional zones %u\n",
 		       opts->nr_conv_zones);
--
2.50.1


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

* Re: [PATCH] zloop: round capacity up to a zone-size multiple
  2026-08-03  9:58 [PATCH] zloop: round capacity up to a zone-size multiple raoxu
@ 2026-08-03 13:02 ` Damien Le Moal
  2026-08-04  3:41   ` [PATCH v2] Documentation: block: zloop: clarify capacity alignment raoxu
  0 siblings, 1 reply; 7+ messages in thread
From: Damien Le Moal @ 2026-08-03 13:02 UTC (permalink / raw)
  To: raoxu; +Cc: axboe, hch, linux-block, linux-kernel, stable

On 8/3/26 18:58, raoxu wrote:
> From: Xu Rao <raoxu@uniontech.com>
> 
> zloop_ctl_add() derives the number of zones by shifting the requested
> capacity by ilog2(zone_size). Since zone_size is validated as a power of
> two, this is equivalent to integer division and discards any remainder.
> However, Documentation/admin-guide/blockdev/zoned_loop.rst specifies that
> capacity_mb is always rounded up to the nearest higher multiple of the
> zone size.
> 
> Only configurations whose requested capacity is not aligned to the zone
> size are affected. Aligned configurations, including the defaults of
> 16384 MiB capacity and 256 MiB zones, keep the same geometry. An affected
> device is also internally consistent and remains usable, but it is
> smaller than requested. For example, capacity_mb=130 with
> zone_size_mb=64 currently creates two zones and exposes 128 MiB instead
> of the documented three zones and 192 MiB. Since this does not cause an
> error or an I/O failure, and normal test configurations generally use an
> integral number of zones, the discrepancy can remain unnoticed.
> 
> Calculate the number of zones with DIV_ROUND_UP_SECTOR_T() so a partial
> final zone request is represented by one additional full zone. This
> matches the documented control interface while preserving the existing
> sector_t handling on both 32-bit and 64-bit architectures.
> 
> Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xu Rao <raoxu@uniontech.com>
> ---
>  drivers/block/zloop.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
> index b69d798f203c..e29d82ff52ae 100644
> --- a/drivers/block/zloop.c
> +++ b/drivers/block/zloop.c
> @@ -1187,7 +1187,7 @@ static int zloop_ctl_add(struct zloop_options *opts)
> 
>  	__module_get(THIS_MODULE);
> 
> -	nr_zones = opts->capacity >> ilog2(opts->zone_size);
> +	nr_zones = DIV_ROUND_UP_SECTOR_T(opts->capacity, opts->zone_size);

Your explanation and this change are consistent, but this is going to break many
things because we do not maintain the size of zone per zone and instead always
use zlo->zone_size, assuming that all zones have the same size.
Your change would result in bad things. For instance, zloop_finish_zone()
truncates a zone file to zlo->zone_size, which would be too big for a last runt
zone smaller than other zones.

So nack for this patch. Instead, I think we should fix the documentation to make
more explicit that we do not support a smaller last zone.

>  	if (opts->nr_conv_zones >= nr_zones) {
>  		pr_err("Invalid number of conventional zones %u\n",
>  		       opts->nr_conv_zones);
> --
> 2.50.1
> 


-- 
Damien Le Moal
Western Digital Research

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

* [PATCH v2] Documentation: block: zloop: clarify capacity alignment
  2026-08-03 13:02 ` Damien Le Moal
@ 2026-08-04  3:41   ` raoxu
  2026-08-04  4:29     ` Damien Le Moal
  0 siblings, 1 reply; 7+ messages in thread
From: raoxu @ 2026-08-04  3:41 UTC (permalink / raw)
  To: dlemoal; +Cc: axboe, hch, linux-block, linux-kernel, raoxu, stable

From: Xu Rao <raoxu@uniontech.com>

zloop divides the requested capacity by the zone size to determine the
number of zones. Since it uses one zone size for all zones, a smaller last
zone is not supported and an unaligned capacity is rounded down.

The capacity_mb description incorrectly states that the capacity is rounded
up. Correct it to document the actual behavior.

Fixes: 9e4f11c1228c ("Documentation: Document the new zoned loop block device driver")
Suggested-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Xu Rao <raoxu@uniontech.com>
---
Changes in v2:
- Replace the code change with a documentation correction.
- State that a smaller last zone is unsupported and that an unaligned
  capacity is rounded down.

 Documentation/admin-guide/blockdev/zoned_loop.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/blockdev/zoned_loop.rst b/Documentation/admin-guide/blockdev/zoned_loop.rst
index f4f1f31..fd99e5c 100644
--- a/Documentation/admin-guide/blockdev/zoned_loop.rst
+++ b/Documentation/admin-guide/blockdev/zoned_loop.rst
@@ -71,8 +71,9 @@ follows.
 ===================   =========================================================
 id                    Device number (the X in /dev/zloopX).
                       Default: automatically assigned.
-capacity_mb           Device total capacity in MiB. This is always rounded up
-                      to the nearest higher multiple of the zone size.
+capacity_mb           Device total capacity in MiB. A smaller last zone is not
+                      supported, so an unaligned value is rounded down to a
+                      zone-size multiple.
                       Default: 16384 MiB (16 GiB).
 zone_size_mb          Device zone size in MiB. Default: 256 MiB.
 zone_capacity_mb      Device zone capacity (must always be equal to or lower
--
2.47.3



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

* Re: [PATCH v2] Documentation: block: zloop: clarify capacity alignment
  2026-08-04  3:41   ` [PATCH v2] Documentation: block: zloop: clarify capacity alignment raoxu
@ 2026-08-04  4:29     ` Damien Le Moal
  2026-08-04  5:29       ` [PATCH v3] " raoxu
  0 siblings, 1 reply; 7+ messages in thread
From: Damien Le Moal @ 2026-08-04  4:29 UTC (permalink / raw)
  To: raoxu; +Cc: axboe, hch, linux-block, linux-kernel, stable

On 8/4/26 12:41, raoxu wrote:
> From: Xu Rao <raoxu@uniontech.com>
> 
> zloop divides the requested capacity by the zone size to determine the
> number of zones. Since it uses one zone size for all zones, a smaller last
> zone is not supported and an unaligned capacity is rounded down.
> 
> The capacity_mb description incorrectly states that the capacity is rounded
> up. Correct it to document the actual behavior.
> 
> Fixes: 9e4f11c1228c ("Documentation: Document the new zoned loop block device driver")
> Suggested-by: Damien Le Moal <dlemoal@kernel.org>
> Signed-off-by: Xu Rao <raoxu@uniontech.com>
> ---
> Changes in v2:
> - Replace the code change with a documentation correction.
> - State that a smaller last zone is unsupported and that an unaligned
>   capacity is rounded down.
> 
>  Documentation/admin-guide/blockdev/zoned_loop.rst | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/admin-guide/blockdev/zoned_loop.rst b/Documentation/admin-guide/blockdev/zoned_loop.rst
> index f4f1f31..fd99e5c 100644
> --- a/Documentation/admin-guide/blockdev/zoned_loop.rst
> +++ b/Documentation/admin-guide/blockdev/zoned_loop.rst
> @@ -71,8 +71,9 @@ follows.
>  ===================   =========================================================
>  id                    Device number (the X in /dev/zloopX).
>                        Default: automatically assigned.
> -capacity_mb           Device total capacity in MiB. This is always rounded up
> -                      to the nearest higher multiple of the zone size.
> +capacity_mb           Device total capacity in MiB. A smaller last zone is not
> +                      supported, so an unaligned value is rounded down to a
> +                      zone-size multiple.

Let's make this a proper sentence:

capacity_mb		Device total capacity in MiB. A smaller last zone is not
			supported, so a capacity value that is not multiple of
			the zone size is rounded down to the closest multiple of
			the zone-size.

With that,

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

>                        Default: 16384 MiB (16 GiB).
>  zone_size_mb          Device zone size in MiB. Default: 256 MiB.
>  zone_capacity_mb      Device zone capacity (must always be equal to or lower
> --
> 2.47.3
> 
> 


-- 
Damien Le Moal
Western Digital Research

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

* [PATCH v3] Documentation: block: zloop: clarify capacity alignment
  2026-08-04  4:29     ` Damien Le Moal
@ 2026-08-04  5:29       ` raoxu
  2026-08-04 13:05         ` Christoph Hellwig
  2026-08-04 13:21         ` Jens Axboe
  0 siblings, 2 replies; 7+ messages in thread
From: raoxu @ 2026-08-04  5:29 UTC (permalink / raw)
  To: dlemoal; +Cc: axboe, hch, linux-block, linux-kernel, raoxu, stable

From: Xu Rao <raoxu@uniontech.com>

zloop divides the requested capacity by the zone size to determine the
number of zones. Since it uses one zone size for all zones, a smaller last
zone is not supported and an unaligned capacity is rounded down.

The capacity_mb description incorrectly states that the capacity is rounded
up. Correct it to document the actual behavior.

Fixes: 9e4f11c1228c ("Documentation: Document the new zoned loop block device driver")
Suggested-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Xu Rao <raoxu@uniontech.com>
---
Changes in v2:
- Replace the code change with a documentation correction.
- State that a smaller last zone is unsupported and that an unaligned
  capacity is rounded down.

Changes in v3:
- Reword the capacity_mb description as suggested by Damien.

 Documentation/admin-guide/blockdev/zoned_loop.rst | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/blockdev/zoned_loop.rst b/Documentation/admin-guide/blockdev/zoned_loop.rst
index f4f1f3121bf9..abaf36f21945 100644
--- a/Documentation/admin-guide/blockdev/zoned_loop.rst
+++ b/Documentation/admin-guide/blockdev/zoned_loop.rst
@@ -71,8 +71,10 @@ follows.
 ===================   =========================================================
 id                    Device number (the X in /dev/zloopX).
                       Default: automatically assigned.
-capacity_mb           Device total capacity in MiB. This is always rounded up
-                      to the nearest higher multiple of the zone size.
+capacity_mb           Device total capacity in MiB. A smaller last zone is not
+                      supported, so a capacity value that is not a multiple of
+                      the zone size is rounded down to the closest multiple of
+                      the zone size.
                       Default: 16384 MiB (16 GiB).
 zone_size_mb          Device zone size in MiB. Default: 256 MiB.
 zone_capacity_mb      Device zone capacity (must always be equal to or lower
--
2.50.1

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

* Re: [PATCH v3] Documentation: block: zloop: clarify capacity alignment
  2026-08-04  5:29       ` [PATCH v3] " raoxu
@ 2026-08-04 13:05         ` Christoph Hellwig
  2026-08-04 13:21         ` Jens Axboe
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2026-08-04 13:05 UTC (permalink / raw)
  To: raoxu; +Cc: dlemoal, axboe, hch, linux-block, linux-kernel, stable

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


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

* Re: [PATCH v3] Documentation: block: zloop: clarify capacity alignment
  2026-08-04  5:29       ` [PATCH v3] " raoxu
  2026-08-04 13:05         ` Christoph Hellwig
@ 2026-08-04 13:21         ` Jens Axboe
  1 sibling, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2026-08-04 13:21 UTC (permalink / raw)
  To: dlemoal, raoxu; +Cc: hch, linux-block, linux-kernel, stable


On Tue, 04 Aug 2026 13:29:41 +0800, raoxu wrote:
> zloop divides the requested capacity by the zone size to determine the
> number of zones. Since it uses one zone size for all zones, a smaller last
> zone is not supported and an unaligned capacity is rounded down.
> 
> The capacity_mb description incorrectly states that the capacity is rounded
> up. Correct it to document the actual behavior.
> 
> [...]

Applied, thanks!

[1/1] Documentation: block: zloop: clarify capacity alignment
      commit: d73b5b0690e36b2a9e6022f6712e9fa7fd338632

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2026-08-04 13:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03  9:58 [PATCH] zloop: round capacity up to a zone-size multiple raoxu
2026-08-03 13:02 ` Damien Le Moal
2026-08-04  3:41   ` [PATCH v2] Documentation: block: zloop: clarify capacity alignment raoxu
2026-08-04  4:29     ` Damien Le Moal
2026-08-04  5:29       ` [PATCH v3] " raoxu
2026-08-04 13:05         ` Christoph Hellwig
2026-08-04 13:21         ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox