Hi all, the somewhat confusing name of the discard_alignment queue limit, that really is an offset for the discard granularity mislead a lot of driver authors to set it to an incorrect value. This series tries to fix up all these cases. Diffstat: arch/um/drivers/ubd_kern.c | 1 - drivers/block/loop.c | 1 - drivers/block/nbd.c | 3 --- drivers/block/null_blk/main.c | 1 - drivers/block/rnbd/rnbd-srv-dev.h | 2 +- drivers/block/virtio_blk.c | 7 ++++--- drivers/block/xen-blkback/xenbus.c | 4 ++-- drivers/md/dm-zoned-target.c | 2 +- drivers/md/raid5.c | 1 - drivers/nvme/host/core.c | 1 - drivers/s390/block/dasd_fba.c | 1 - 11 files changed, 8 insertions(+), 16 deletions(-)
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 01/11] ubd: don't set the discard_alignment queue limit
The discard_alignment queue limit is named a bit misleading means the offset into the block device at which the discard granularity starts. Setting it to the discard granularity as done by ubd is mostly harmless but also useless. Signed-off-by: Christoph Hellwig <hch at lst.de> --- arch/um/drivers/ubd_kern.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 085ffdf98e57e..c4344b67628dd 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -799,7 +799,6 @@ static int ubd_open_dev(struct ubd *ubd_dev) } if (ubd_dev->no_trim == 0) { ubd_dev->queue->limits.discard_granularity = SECTOR_SIZE; - ubd_dev->queue->limits.discard_alignment = SECTOR_SIZE; blk_queue_max_discard_sectors(ubd_dev->queue, UBD_MAX_REQUEST); blk_queue_max_write_zeroes_sectors(ubd_dev->queue, UBD_MAX_REQUEST); } -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 02/11] nbd: don't set the discard_alignment queue limit
The discard_alignment queue limit is named a bit misleading means the offset into the block device at which the discard granularity starts. Setting it to the discard granularity as done by nbd is mostly harmless but also useless. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/block/nbd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 4729aef8c6462..102597a4277b9 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -333,7 +333,6 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, if (nbd->config->flags & NBD_FLAG_SEND_TRIM) { nbd->disk->queue->limits.discard_granularity = blksize; - nbd->disk->queue->limits.discard_alignment = blksize; blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX); } blk_queue_logical_block_size(nbd->disk->queue, blksize); @@ -1316,7 +1315,6 @@ static void nbd_config_put(struct nbd_device *nbd) nbd->tag_set.timeout = 0; nbd->disk->queue->limits.discard_granularity = 0; - nbd->disk->queue->limits.discard_alignment = 0; blk_queue_max_discard_sectors(nbd->disk->queue, 0); mutex_unlock(&nbd->config_lock); @@ -1781,7 +1779,6 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs) blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, disk->queue); disk->queue->limits.discard_granularity = 0; - disk->queue->limits.discard_alignment = 0; blk_queue_max_discard_sectors(disk->queue, 0); blk_queue_max_segment_size(disk->queue, UINT_MAX); blk_queue_max_segments(disk->queue, USHRT_MAX); -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 03/11] null_blk: don't set the discard_alignment queue limit
The discard_alignment queue limit is named a bit misleading means the offset into the block device at which the discard granularity starts. Setting it to the discard granularity as done by null_blk is mostly harmless but also useless. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/block/null_blk/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 5cb4c92cdffea..a521e914a9843 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1765,7 +1765,6 @@ static void null_config_discard(struct nullb *nullb) } nullb->q->limits.discard_granularity = nullb->dev->blocksize; - nullb->q->limits.discard_alignment = nullb->dev->blocksize; blk_queue_max_discard_sectors(nullb->q, UINT_MAX >> 9); } -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 04/11] virtio_blk: fix the discard_granularity and discard_alignment queue limits
The discard_alignment queue limit is named a bit misleading means the offset into the block device at which the discard granularity starts. On the other hand the discard_sector_alignment from the virtio 1.1 looks similar to what Linux uses as discard granularity (even if not very well described): "discard_sector_alignment can be used by OS when splitting a request based on alignment. " And at least qemu does set it to the discard granularity. So stop setting the discard_alignment and use the virtio discard_sector_alignment to set the discard granularity. Fixes: 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support") Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/block/virtio_blk.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 6ccf15253dee1..d624cc8eddc3c 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -867,11 +867,12 @@ static int virtblk_probe(struct virtio_device *vdev) blk_queue_io_opt(q, blk_size * opt_io_size); if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) { - q->limits.discard_granularity = blk_size; - virtio_cread(vdev, struct virtio_blk_config, discard_sector_alignment, &v); - q->limits.discard_alignment = v ? v << SECTOR_SHIFT : 0; + if (v) + q->limits.discard_granularity = v << SECTOR_SHIFT; + else + q->limits.discard_granularity = blk_size; virtio_cread(vdev, struct virtio_blk_config, max_discard_sectors, &v); -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 05/11] dm-zoned: don't set the discard_alignment queue limit
The discard_alignment queue limit is named a bit misleading means the offset into the block device at which the discard granularity starts. Setting it to the discard granularity as done by dm-zoned is mostly harmless but also useless. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/md/dm-zoned-target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c index cac295cc8840e..0ec5d8b9b1a4e 100644 --- a/drivers/md/dm-zoned-target.c +++ b/drivers/md/dm-zoned-target.c @@ -1001,7 +1001,7 @@ static void dmz_io_hints(struct dm_target *ti, struct queue_limits *limits) blk_limits_io_min(limits, DMZ_BLOCK_SIZE); blk_limits_io_opt(limits, DMZ_BLOCK_SIZE); - limits->discard_alignment = DMZ_BLOCK_SIZE; + limits->discard_alignment = 0; limits->discard_granularity = DMZ_BLOCK_SIZE; limits->max_discard_sectors = chunk_sectors; limits->max_hw_discard_sectors = chunk_sectors; -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 06/11] raid5: don't set the discard_alignment queue limit
The discard_alignment queue limit is named a bit misleading means the offset into the block device at which the discard granularity starts. Setting it to the discard granularity as done by raid5 is mostly harmless but also useless. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/md/raid5.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 59f91e392a2ae..39b0afdf40d0a 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7749,7 +7749,6 @@ static int raid5_run(struct mddev *mddev) */ stripe = stripe * PAGE_SIZE; stripe = roundup_pow_of_two(stripe); - mddev->queue->limits.discard_alignment = stripe; mddev->queue->limits.discard_granularity = stripe; blk_queue_max_write_zeroes_sectors(mddev->queue, 0); -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 07/11] dasd: don't set the discard_alignment queue limit
The discard_alignment queue limit is named a bit misleading means the offset into the block device at which the discard granularity starts. Setting it to PAGE_SIZE while the discard granularity is the block size that is smaller or the same as PAGE_SIZE as done by dasd is mostly harmless but also useless. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/s390/block/dasd_fba.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c index 8bd5665db9198..60be7f7bf2d16 100644 --- a/drivers/s390/block/dasd_fba.c +++ b/drivers/s390/block/dasd_fba.c @@ -782,7 +782,6 @@ static void dasd_fba_setup_blk_queue(struct dasd_block *block) blk_queue_segment_boundary(q, PAGE_SIZE - 1); q->limits.discard_granularity = logical_block_size; - q->limits.discard_alignment = PAGE_SIZE; /* Calculate max_discard_sectors and make it PAGE aligned */ max_bytes = USHRT_MAX * logical_block_size; -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 08/11] loop: remove a spurious clear of discard_alignment
The loop driver never sets a discard_alignment, so it also doens't need to clear it to zero. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/block/loop.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 976cf987b3920..61b642b966a08 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -789,7 +789,6 @@ static void loop_config_discard(struct loop_device *lo) blk_queue_max_discard_sectors(q, 0); blk_queue_max_write_zeroes_sectors(q, 0); } - q->limits.discard_alignment = 0; } struct loop_worker { -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 09/11] nvme: remove a spurious clear of discard_alignment
The nvme driver never sets a discard_alignment, so it also doens't need to clear it to zero. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/nvme/host/core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index b9b0fbde97c80..76a9ccd5d064a 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1628,7 +1628,6 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) BUILD_BUG_ON(PAGE_SIZE / sizeof(struct nvme_dsm_range) < NVME_DSM_MAX_RANGES); - queue->limits.discard_alignment = 0; queue->limits.discard_granularity = size; /* If discard is already enabled, don't reset queue limits */ -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 10/11] rnbd-srv: use bdev_discard_alignment
Use bdev_discard_alignment to calculate the correct discard alignment offset even for partitions instead of just looking at the queue limit. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/block/rnbd/rnbd-srv-dev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/rnbd/rnbd-srv-dev.h b/drivers/block/rnbd/rnbd-srv-dev.h index d080a0de59225..4309e52524691 100644 --- a/drivers/block/rnbd/rnbd-srv-dev.h +++ b/drivers/block/rnbd/rnbd-srv-dev.h @@ -59,7 +59,7 @@ static inline int rnbd_dev_get_discard_granularity(const struct rnbd_dev *dev) static inline int rnbd_dev_get_discard_alignment(const struct rnbd_dev *dev) { - return bdev_get_queue(dev->bdev)->limits.discard_alignment; + return bdev_discard_alignment(dev->bdev); } #endif /* RNBD_SRV_DEV_H */ -- 2.30.2
Christoph Hellwig
2022-Apr-18 04:53 UTC
[PATCH 11/11] xen-blkback: use bdev_discard_alignment
Use bdev_discard_alignment to calculate the correct discard alignment offset even for partitions instead of just looking at the queue limit. Also switch to use bdev_discard_granularity to get rid of the last direct queue reference in xen_blkbk_discard. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/block/xen-blkback/xenbus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index b21bffc9c50bc..04c90cb8955f6 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -583,14 +583,14 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info if (bdev_max_discard_sectors(bdev)) { err = xenbus_printf(xbt, dev->nodename, "discard-granularity", "%u", - q->limits.discard_granularity); + bdev_discard_granularity(bdev)); if (err) { dev_warn(&dev->dev, "writing discard-granularity (%d)", err); return; } err = xenbus_printf(xbt, dev->nodename, "discard-alignment", "%u", - q->limits.discard_alignment); + bdev_discard_alignment(bdev)); if (err) { dev_warn(&dev->dev, "writing discard-alignment (%d)", err); return; -- 2.30.2
Christoph,> the somewhat confusing name of the discard_alignment queue limit, that > really is an offset for the discard granularity mislead a lot of > driver authors to set it to an incorrect value. This series tries to > fix up all these cases.Not sure how I ended up with "discard_alignment" when I called the corresponding I/O parameter "alignment_offset". Anyway. All this looks good to me. Reviewed-by: Martin K. Petersen <martin.petersen at oracle.com> -- Martin K. Petersen Oracle Linux Engineering
On Mon, 18 Apr 2022 06:53:03 +0200, Christoph Hellwig wrote:> the somewhat confusing name of the discard_alignment queue limit, that > really is an offset for the discard granularity mislead a lot of driver > authors to set it to an incorrect value. This series tries to fix up > all these cases. > > Diffstat: > arch/um/drivers/ubd_kern.c | 1 - > drivers/block/loop.c | 1 - > drivers/block/nbd.c | 3 --- > drivers/block/null_blk/main.c | 1 - > drivers/block/rnbd/rnbd-srv-dev.h | 2 +- > drivers/block/virtio_blk.c | 7 ++++--- > drivers/block/xen-blkback/xenbus.c | 4 ++-- > drivers/md/dm-zoned-target.c | 2 +- > drivers/md/raid5.c | 1 - > drivers/nvme/host/core.c | 1 - > drivers/s390/block/dasd_fba.c | 1 - > 11 files changed, 8 insertions(+), 16 deletions(-) > > [...]Applied, thanks! [01/11] ubd: don't set the discard_alignment queue limit commit: 07c6e92a8478770a7302f7dde72f03a5465901bd [02/11] nbd: don't set the discard_alignment queue limit commit: 4a04d517c56e0616c6f69afc226ee2691e543712 [03/11] null_blk: don't set the discard_alignment queue limit commit: fb749a87f4536d2fa86ea135ae4eff1072903438 [04/11] virtio_blk: fix the discard_granularity and discard_alignment queue limits commit: 62952cc5bccd89b76d710de1d0b43244af0f2903 [05/11] dm-zoned: don't set the discard_alignment queue limit commit: 44d583702f4429763c558624fac763650a1f05bf [06/11] raid5: don't set the discard_alignment queue limit commit: 3d50d368c92ade2f98a3d0d28b842a57c35284e9 [07/11] dasd: don't set the discard_alignment queue limit commit: c3f765299632727fa5ea5a0acf118665227a4f1a [08/11] loop: remove a spurious clear of discard_alignment commit: 4418bfd8fb9602d9cd8747c3ad52fdbaa02e2ffd [09/11] nvme: remove a spurious clear of discard_alignment commit: 4e7f0ece41e1be8f876f320a0972a715daec0a50 [10/11] rnbd-srv: use bdev_discard_alignment commit: 18292faa89d2bff3bdd33ab9c065f45fb6710e47 [11/11] xen-blkback: use bdev_discard_alignment commit: c899b23533866910c90ef4386b501af50270d320 Best regards, -- Jens Axboe