Re: [PATCH] block: fix unexpected split in bio_discard_limit

From: Li Feng
Date: Mon Aug 21 2023 - 01:22:12 EST


Ping…

Thanks,
Li

> 2023年8月17日 下午3:55,Li Feng <fengli@xxxxxxxxxx> 写道:
>
> bio_discard_limit() enforces discard boundaries within the range of 32-bit
> unsigned integers, resulting in unexpected discard cut boundaries.
>
> For example, max discard size = 1MiB, discard_granularity = 512B, then the
> discard lengths sent in the range [0,4G) are 1MiB, 1MiB... (1MiB-512).
> The next discard offset from 4G is [4G-512, 4G-512+1MiB).
> The discard of the 4G offset boundary does not comply with the optimal 1MiB
> size.
>
> Signed-off-by: Li Feng <fengli@xxxxxxxxxx>
> ---
> block/blk-lib.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index e59c3069e835..ec95508c3593 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -32,7 +32,7 @@ static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector)
> * Align the bio size to the discard granularity to make splitting the bio
> * at discard granularity boundaries easier in the driver if needed.
> */
> - return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT;
> + return round_down(ULONG_MAX, discard_granularity) >> SECTOR_SHIFT;
> }
>
> int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
> --
> 2.41.0
>