linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* provide a sane discard_granularity default
@ 2023-12-28  7:55 Christoph Hellwig
  2023-12-28  7:55 ` [PATCH 1/9] block: remove two comments in bio_split_discard Christoph Hellwig
                   ` (9 more replies)
  0 siblings, 10 replies; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

Hi Jens,

this series defaults the discard_granularity to the sector size as
that is a very logical default for devices that have no further
restrictions.  This removes the need for trivial drivers to set
a discard granularity and cleans up the interface.

Diffstat:
 arch/um/drivers/ubd_kern.c    |    1 -
 block/blk-merge.c             |    6 +-----
 block/blk-settings.c          |    5 ++++-
 drivers/block/nbd.c           |    6 +-----
 drivers/block/null_blk/main.c |    1 -
 drivers/block/zram/zram_drv.c |    1 -
 drivers/md/bcache/super.c     |    1 -
 drivers/mtd/mtd_blkdevs.c     |    4 +---
 8 files changed, 7 insertions(+), 18 deletions(-)

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

* [PATCH 1/9] block: remove two comments in bio_split_discard
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2023-12-28  7:55 ` [PATCH 2/9] bcache: discard_granularity should not be smaller than a sector Christoph Hellwig
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

A zero discard_granularity is not treated the same as a single-block one,
and not having any segments after taking alignment is perfectly fine
and does not need a warning.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-merge.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 65e75efa9bd366..2d470cf2173e29 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -115,17 +115,13 @@ static struct bio *bio_split_discard(struct bio *bio,
 
 	*nsegs = 1;
 
-	/* Zero-sector (unknown) and one-sector granularities are the same.  */
 	granularity = max(lim->discard_granularity >> 9, 1U);
 
 	max_discard_sectors =
 		min(lim->max_discard_sectors, bio_allowed_max_sectors(lim));
 	max_discard_sectors -= max_discard_sectors % granularity;
-
-	if (unlikely(!max_discard_sectors)) {
-		/* XXX: warn */
+	if (unlikely(!max_discard_sectors))
 		return NULL;
-	}
 
 	if (bio_sectors(bio) <= max_discard_sectors)
 		return NULL;
-- 
2.39.2


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

* [PATCH 2/9] bcache: discard_granularity should not be smaller than a sector
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
  2023-12-28  7:55 ` [PATCH 1/9] block: remove two comments in bio_split_discard Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2023-12-28  7:55 ` [PATCH 3/9] block: default the discard granularity to sector size Christoph Hellwig
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

Just like all block I/O, discards are in units of sectors.  Thus setting a
smaller than sector size discard limit in case of > 512 byte sectors in
bcache doesn't make sense.  Always set the discard granularity to 512
bytes instead.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index bfe1685dbae574..ecc1447f202a42 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -954,7 +954,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
 	q->limits.max_segment_size	= UINT_MAX;
 	q->limits.max_segments		= BIO_MAX_VECS;
 	blk_queue_max_discard_sectors(q, UINT_MAX);
-	q->limits.discard_granularity	= 512;
+	q->limits.discard_granularity	= block_size;
 	q->limits.io_min		= block_size;
 	q->limits.logical_block_size	= block_size;
 	q->limits.physical_block_size	= block_size;
-- 
2.39.2


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

* [PATCH 3/9] block: default the discard granularity to sector size
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
  2023-12-28  7:55 ` [PATCH 1/9] block: remove two comments in bio_split_discard Christoph Hellwig
  2023-12-28  7:55 ` [PATCH 2/9] bcache: discard_granularity should not be smaller than a sector Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2024-01-02 22:11   ` John Pittman
  2023-12-28  7:55 ` [PATCH 4/9] ubd: use the default discard granularity Christoph Hellwig
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

Current the discard granularity defaults to 0 and must be initialized by
any driver that wants to support discard.  Default to the sector size
instead, which is the smallest possible value, and a very useful default.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-settings.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index ba6e0e97118c08..d993d20dab3c6d 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -48,7 +48,7 @@ void blk_set_default_limits(struct queue_limits *lim)
 	lim->max_discard_sectors = 0;
 	lim->max_hw_discard_sectors = 0;
 	lim->max_secure_erase_sectors = 0;
-	lim->discard_granularity = 0;
+	lim->discard_granularity = 512;
 	lim->discard_alignment = 0;
 	lim->discard_misaligned = 0;
 	lim->logical_block_size = lim->physical_block_size = lim->io_min = 512;
@@ -309,6 +309,9 @@ void blk_queue_logical_block_size(struct request_queue *q, unsigned int size)
 
 	limits->logical_block_size = size;
 
+	if (limits->discard_granularity < limits->logical_block_size)
+		limits->discard_granularity = limits->logical_block_size;
+
 	if (limits->physical_block_size < size)
 		limits->physical_block_size = size;
 
-- 
2.39.2


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

* [PATCH 4/9] ubd: use the default discard granularity
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
                   ` (2 preceding siblings ...)
  2023-12-28  7:55 ` [PATCH 3/9] block: default the discard granularity to sector size Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2023-12-28 11:10   ` Richard Weinberger
  2023-12-28  7:55 ` [PATCH 5/9] nbd: " Christoph Hellwig
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

The discard granularity now defaults to a single sector, so don't set
that value explicitly.

Signed-off-by: Christoph Hellwig <hch@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 50206feac577d5..92ee2697ff3984 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -798,7 +798,6 @@ static int ubd_open_dev(struct ubd *ubd_dev)
 		ubd_dev->cow.fd = err;
 	}
 	if (ubd_dev->no_trim == 0) {
-		ubd_dev->queue->limits.discard_granularity = 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.39.2


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

* [PATCH 5/9] nbd: use the default discard granularity
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
                   ` (3 preceding siblings ...)
  2023-12-28  7:55 ` [PATCH 4/9] ubd: use the default discard granularity Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2023-12-28  7:55 ` [PATCH 6/9] null_blk: " Christoph Hellwig
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

The discard granularity now defaults to a single sector, so don't set
that value explicitly.  Also don't bother clearing it as a discard
granularity without discard_sectors doesn't mean anything.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/nbd.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b6414e1e645b76..4e72ec4e25ac5a 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -334,10 +334,8 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
 	if (!nbd->pid)
 		return 0;
 
-	if (nbd->config->flags & NBD_FLAG_SEND_TRIM) {
-		nbd->disk->queue->limits.discard_granularity = blksize;
+	if (nbd->config->flags & NBD_FLAG_SEND_TRIM)
 		blk_queue_max_discard_sectors(nbd->disk->queue, UINT_MAX);
-	}
 	blk_queue_logical_block_size(nbd->disk->queue, blksize);
 	blk_queue_physical_block_size(nbd->disk->queue, blksize);
 
@@ -1357,7 +1355,6 @@ static void nbd_config_put(struct nbd_device *nbd)
 		nbd->config = NULL;
 
 		nbd->tag_set.timeout = 0;
-		nbd->disk->queue->limits.discard_granularity = 0;
 		blk_queue_max_discard_sectors(nbd->disk->queue, 0);
 
 		mutex_unlock(&nbd->config_lock);
@@ -1850,7 +1847,6 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
 	 * Tell the block layer that we are not a rotational device
 	 */
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
-	disk->queue->limits.discard_granularity = 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.39.2


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

* [PATCH 6/9] null_blk: use the default discard granularity
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
                   ` (4 preceding siblings ...)
  2023-12-28  7:55 ` [PATCH 5/9] nbd: " Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2023-12-28  7:55 ` [PATCH 7/9] zram: " Christoph Hellwig
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

The discard granularity now defaults to a single sector, so don't set
that value explicitly.

Signed-off-by: Christoph Hellwig <hch@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 13ed446b5e198e..9f7695f00c2db8 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1880,7 +1880,6 @@ static void null_config_discard(struct nullb *nullb)
 		return;
 	}
 
-	nullb->q->limits.discard_granularity = nullb->dev->blocksize;
 	blk_queue_max_discard_sectors(nullb->q, UINT_MAX >> 9);
 }
 
-- 
2.39.2


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

* [PATCH 7/9] zram: use the default discard granularity
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
                   ` (5 preceding siblings ...)
  2023-12-28  7:55 ` [PATCH 6/9] null_blk: " Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2024-01-02  1:15   ` Sergey Senozhatsky
  2024-01-06  1:32   ` Sergey Senozhatsky
  2023-12-28  7:55 ` [PATCH 8/9] bcache: " Christoph Hellwig
                   ` (2 subsequent siblings)
  9 siblings, 2 replies; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

The discard granularity now defaults to a single sector, so don't set
that value explicitly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/zram/zram_drv.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index d77d3664ca0805..e1dec0483a012b 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -2227,7 +2227,6 @@ static int zram_add(void)
 					ZRAM_LOGICAL_BLOCK_SIZE);
 	blk_queue_io_min(zram->disk->queue, PAGE_SIZE);
 	blk_queue_io_opt(zram->disk->queue, PAGE_SIZE);
-	zram->disk->queue->limits.discard_granularity = PAGE_SIZE;
 	blk_queue_max_discard_sectors(zram->disk->queue, UINT_MAX);
 
 	/*
-- 
2.39.2


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

* [PATCH 8/9] bcache: use the default discard granularity
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
                   ` (6 preceding siblings ...)
  2023-12-28  7:55 ` [PATCH 7/9] zram: " Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2024-01-05  7:03   ` Coly Li
  2023-12-28  7:55 ` [PATCH 9/9] mtd_blkdevs: " Christoph Hellwig
  2023-12-29 15:44 ` provide a sane discard_granularity default Jens Axboe
  9 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

The discard granularity now defaults to a single sector, so don't set
that value explicitly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/bcache/super.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index ecc1447f202a42..39ec95b8613f1f 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -954,7 +954,6 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
 	q->limits.max_segment_size	= UINT_MAX;
 	q->limits.max_segments		= BIO_MAX_VECS;
 	blk_queue_max_discard_sectors(q, UINT_MAX);
-	q->limits.discard_granularity	= block_size;
 	q->limits.io_min		= block_size;
 	q->limits.logical_block_size	= block_size;
 	q->limits.physical_block_size	= block_size;
-- 
2.39.2


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

* [PATCH 9/9] mtd_blkdevs: use the default discard granularity
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
                   ` (7 preceding siblings ...)
  2023-12-28  7:55 ` [PATCH 8/9] bcache: " Christoph Hellwig
@ 2023-12-28  7:55 ` Christoph Hellwig
  2023-12-28 11:09   ` Richard Weinberger
  2023-12-29 15:44 ` provide a sane discard_granularity default Jens Axboe
  9 siblings, 1 reply; 21+ messages in thread
From: Christoph Hellwig @ 2023-12-28  7:55 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd

The discard granularity now defaults to a single sector, so don't set
that value explicitly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/mtd/mtd_blkdevs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index ff18636e088973..0da7b33849471a 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -376,10 +376,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, new->rq);
 	blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, new->rq);
 
-	if (tr->discard) {
+	if (tr->discard)
 		blk_queue_max_discard_sectors(new->rq, UINT_MAX);
-		new->rq->limits.discard_granularity = tr->blksize;
-	}
 
 	gd->queue = new->rq;
 
-- 
2.39.2


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

* Re: [PATCH 9/9] mtd_blkdevs: use the default discard granularity
  2023-12-28  7:55 ` [PATCH 9/9] mtd_blkdevs: " Christoph Hellwig
@ 2023-12-28 11:09   ` Richard Weinberger
  0 siblings, 0 replies; 21+ messages in thread
From: Richard Weinberger @ 2023-12-28 11:09 UTC (permalink / raw)
  To: hch
  Cc: Jens Axboe, anton ivanov, Josef Bacik, Minchan Kim, senozhatsky,
	Coly Li, Miquel Raynal, Vignesh Raghavendra, linux-um,
	linux-block, nbd, linux-bcache, linux-mtd

----- Ursprüngliche Mail -----
> Von: "hch" <hch@lst.de>
> An: "Jens Axboe" <axboe@kernel.dk>
> CC: "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "Josef Bacik" <josef@toxicpanda.com>,
> "Minchan Kim" <minchan@kernel.org>, "senozhatsky" <senozhatsky@chromium.org>, "Coly Li" <colyli@suse.de>, "Miquel
> Raynal" <miquel.raynal@bootlin.com>, "Vignesh Raghavendra" <vigneshr@ti.com>, "linux-um"
> <linux-um@lists.infradead.org>, "linux-block" <linux-block@vger.kernel.org>, nbd@other.debian.org, "linux-bcache"
> <linux-bcache@vger.kernel.org>, "linux-mtd" <linux-mtd@lists.infradead.org>
> Gesendet: Donnerstag, 28. Dezember 2023 08:55:45
> Betreff: [PATCH 9/9] mtd_blkdevs: use the default discard granularity

> The discard granularity now defaults to a single sector, so don't set
> that value explicitly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/mtd/mtd_blkdevs.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
> index ff18636e088973..0da7b33849471a 100644
> --- a/drivers/mtd/mtd_blkdevs.c
> +++ b/drivers/mtd/mtd_blkdevs.c
> @@ -376,10 +376,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
> 	blk_queue_flag_set(QUEUE_FLAG_NONROT, new->rq);
> 	blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, new->rq);
> 
> -	if (tr->discard) {
> +	if (tr->discard)
> 		blk_queue_max_discard_sectors(new->rq, UINT_MAX);
> -		new->rq->limits.discard_granularity = tr->blksize;
> -	}

Acked-by: Richard Weinberger <richard@nod.at>

Thanks,
//richard

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

* Re: [PATCH 4/9] ubd: use the default discard granularity
  2023-12-28  7:55 ` [PATCH 4/9] ubd: use the default discard granularity Christoph Hellwig
@ 2023-12-28 11:10   ` Richard Weinberger
  0 siblings, 0 replies; 21+ messages in thread
From: Richard Weinberger @ 2023-12-28 11:10 UTC (permalink / raw)
  To: hch
  Cc: Jens Axboe, anton ivanov, Josef Bacik, Minchan Kim, senozhatsky,
	Coly Li, Miquel Raynal, Vignesh Raghavendra, linux-um,
	linux-block, nbd, linux-bcache, linux-mtd

----- Ursprüngliche Mail -----
> Von: "hch" <hch@lst.de>
> An: "Jens Axboe" <axboe@kernel.dk>
> CC: "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "Josef Bacik" <josef@toxicpanda.com>,
> "Minchan Kim" <minchan@kernel.org>, "senozhatsky" <senozhatsky@chromium.org>, "Coly Li" <colyli@suse.de>, "Miquel
> Raynal" <miquel.raynal@bootlin.com>, "Vignesh Raghavendra" <vigneshr@ti.com>, "linux-um"
> <linux-um@lists.infradead.org>, "linux-block" <linux-block@vger.kernel.org>, nbd@other.debian.org, "linux-bcache"
> <linux-bcache@vger.kernel.org>, "linux-mtd" <linux-mtd@lists.infradead.org>
> Gesendet: Donnerstag, 28. Dezember 2023 08:55:40
> Betreff: [PATCH 4/9] ubd: use the default discard granularity

> The discard granularity now defaults to a single sector, so don't set
> that value explicitly.
> 
> Signed-off-by: Christoph Hellwig <hch@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 50206feac577d5..92ee2697ff3984 100644
> --- a/arch/um/drivers/ubd_kern.c
> +++ b/arch/um/drivers/ubd_kern.c
> @@ -798,7 +798,6 @@ static int ubd_open_dev(struct ubd *ubd_dev)
> 		ubd_dev->cow.fd = err;
> 	}
> 	if (ubd_dev->no_trim == 0) {
> -		ubd_dev->queue->limits.discard_granularity = 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);
> 	}

Acked-by: Richard Weinberger <richard@nod.at>

Thanks,
//richard

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

* Re: provide a sane discard_granularity default
  2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
                   ` (8 preceding siblings ...)
  2023-12-28  7:55 ` [PATCH 9/9] mtd_blkdevs: " Christoph Hellwig
@ 2023-12-29 15:44 ` Jens Axboe
  9 siblings, 0 replies; 21+ messages in thread
From: Jens Axboe @ 2023-12-29 15:44 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Sergey Senozhatsky, Coly Li, Miquel Raynal, Vignesh Raghavendra,
	linux-um, linux-block, nbd, linux-bcache, linux-mtd


On Thu, 28 Dec 2023 07:55:36 +0000, Christoph Hellwig wrote:
> this series defaults the discard_granularity to the sector size as
> that is a very logical default for devices that have no further
> restrictions.  This removes the need for trivial drivers to set
> a discard granularity and cleans up the interface.
> 
> Diffstat:
>  arch/um/drivers/ubd_kern.c    |    1 -
>  block/blk-merge.c             |    6 +-----
>  block/blk-settings.c          |    5 ++++-
>  drivers/block/nbd.c           |    6 +-----
>  drivers/block/null_blk/main.c |    1 -
>  drivers/block/zram/zram_drv.c |    1 -
>  drivers/md/bcache/super.c     |    1 -
>  drivers/mtd/mtd_blkdevs.c     |    4 +---
>  8 files changed, 7 insertions(+), 18 deletions(-)
> 
> [...]

Applied, thanks!

[1/9] block: remove two comments in bio_split_discard
      commit: 928a5dd3a849dc6d8298835bdcb25c360d41bccb
[2/9] bcache: discard_granularity should not be smaller than a sector
      commit: 5e7169e7f7c0989304dbe8467a1d703d614c64db
[3/9] block: default the discard granularity to sector size
      commit: 3c407dc723bbf914f3744b0c2bb82265b411a50c
[4/9] ubd: use the default discard granularity
      commit: 599d9d4eab7c3d5dc6f1e0f8f052fee9eaa54e50
[5/9] nbd: use the default discard granularity
      commit: 1e2ab2e8a98c9e0629b5b8bff8ee6f2cb3e8daac
[6/9] null_blk: use the default discard granularity
      commit: 724325477f8a48ce1defc2a49998bbc19fe85c88
[7/9] zram: use the default discard granularity
      commit: 3753039def5d0d1c43af847b507ba9b782db183a
[8/9] bcache: use the default discard granularity
      commit: 105c1a5f6ccef7f52f9e76664407ef96218272eb
[9/9] mtd_blkdevs: use the default discard granularity
      commit: 31e4fac930814f2f92eb6ebac9c4d4e3b09f7aaf

Best regards,
-- 
Jens Axboe




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

* Re: [PATCH 7/9] zram: use the default discard granularity
  2023-12-28  7:55 ` [PATCH 7/9] zram: " Christoph Hellwig
@ 2024-01-02  1:15   ` Sergey Senozhatsky
  2024-01-02 15:40     ` Jens Axboe
  2024-01-06  1:32   ` Sergey Senozhatsky
  1 sibling, 1 reply; 21+ messages in thread
From: Sergey Senozhatsky @ 2024-01-02  1:15 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Richard Weinberger, Anton Ivanov, Josef Bacik,
	Minchan Kim, Sergey Senozhatsky, Coly Li, Miquel Raynal,
	Vignesh Raghavendra, linux-um, linux-block, nbd, linux-bcache,
	linux-mtd

On (23/12/28 07:55), Christoph Hellwig wrote:
> 
> The discard granularity now defaults to a single sector, so don't set
> that value explicitly

Hmm, but sector size != PAGE_SIZE

[..]

> @@ -2227,7 +2227,6 @@ static int zram_add(void)
>  					ZRAM_LOGICAL_BLOCK_SIZE);
>  	blk_queue_io_min(zram->disk->queue, PAGE_SIZE);
>  	blk_queue_io_opt(zram->disk->queue, PAGE_SIZE);
> -	zram->disk->queue->limits.discard_granularity = PAGE_SIZE;

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

* Re: [PATCH 7/9] zram: use the default discard granularity
  2024-01-02  1:15   ` Sergey Senozhatsky
@ 2024-01-02 15:40     ` Jens Axboe
  2024-01-02 15:44       ` Jens Axboe
  0 siblings, 1 reply; 21+ messages in thread
From: Jens Axboe @ 2024-01-02 15:40 UTC (permalink / raw)
  To: Sergey Senozhatsky, Christoph Hellwig
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Coly Li, Miquel Raynal, Vignesh Raghavendra, linux-um,
	linux-block, nbd, linux-bcache, linux-mtd

On 1/1/24 6:15 PM, Sergey Senozhatsky wrote:
> On (23/12/28 07:55), Christoph Hellwig wrote:
>>
>> The discard granularity now defaults to a single sector, so don't set
>> that value explicitly
> 
> Hmm, but sector size != PAGE_SIZE
> 
> [..]
> 
>> @@ -2227,7 +2227,6 @@ static int zram_add(void)
>>  					ZRAM_LOGICAL_BLOCK_SIZE);
>>  	blk_queue_io_min(zram->disk->queue, PAGE_SIZE);
>>  	blk_queue_io_opt(zram->disk->queue, PAGE_SIZE);
>> -	zram->disk->queue->limits.discard_granularity = PAGE_SIZE;

Yep, that does indeed look buggy.

-- 
Jens Axboe



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

* Re: [PATCH 7/9] zram: use the default discard granularity
  2024-01-02 15:40     ` Jens Axboe
@ 2024-01-02 15:44       ` Jens Axboe
  2024-01-02 15:47         ` Jens Axboe
  0 siblings, 1 reply; 21+ messages in thread
From: Jens Axboe @ 2024-01-02 15:44 UTC (permalink / raw)
  To: Sergey Senozhatsky, Christoph Hellwig
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Coly Li, Miquel Raynal, Vignesh Raghavendra, linux-um,
	linux-block, nbd, linux-bcache, linux-mtd

On 1/2/24 8:40 AM, Jens Axboe wrote:
> On 1/1/24 6:15 PM, Sergey Senozhatsky wrote:
>> On (23/12/28 07:55), Christoph Hellwig wrote:
>>>
>>> The discard granularity now defaults to a single sector, so don't set
>>> that value explicitly
>>
>> Hmm, but sector size != PAGE_SIZE
>>
>> [..]
>>
>>> @@ -2227,7 +2227,6 @@ static int zram_add(void)
>>>  					ZRAM_LOGICAL_BLOCK_SIZE);
>>>  	blk_queue_io_min(zram->disk->queue, PAGE_SIZE);
>>>  	blk_queue_io_opt(zram->disk->queue, PAGE_SIZE);
>>> -	zram->disk->queue->limits.discard_granularity = PAGE_SIZE;
> 
> Yep, that does indeed look buggy.

Ah no it's fine, it'll default to the sector size of the device, which
is set before the discard limit/granularity. So should work fine as-is.

-- 
Jens Axboe



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

* Re: [PATCH 7/9] zram: use the default discard granularity
  2024-01-02 15:44       ` Jens Axboe
@ 2024-01-02 15:47         ` Jens Axboe
  0 siblings, 0 replies; 21+ messages in thread
From: Jens Axboe @ 2024-01-02 15:47 UTC (permalink / raw)
  To: Sergey Senozhatsky, Christoph Hellwig
  Cc: Richard Weinberger, Anton Ivanov, Josef Bacik, Minchan Kim,
	Coly Li, Miquel Raynal, Vignesh Raghavendra, linux-um,
	linux-block, nbd, linux-bcache, linux-mtd

On 1/2/24 8:44 AM, Jens Axboe wrote:
> On 1/2/24 8:40 AM, Jens Axboe wrote:
>> On 1/1/24 6:15 PM, Sergey Senozhatsky wrote:
>>> On (23/12/28 07:55), Christoph Hellwig wrote:
>>>>
>>>> The discard granularity now defaults to a single sector, so don't set
>>>> that value explicitly
>>>
>>> Hmm, but sector size != PAGE_SIZE
>>>
>>> [..]
>>>
>>>> @@ -2227,7 +2227,6 @@ static int zram_add(void)
>>>>  					ZRAM_LOGICAL_BLOCK_SIZE);
>>>>  	blk_queue_io_min(zram->disk->queue, PAGE_SIZE);
>>>>  	blk_queue_io_opt(zram->disk->queue, PAGE_SIZE);
>>>> -	zram->disk->queue->limits.discard_granularity = PAGE_SIZE;
>>
>> Yep, that does indeed look buggy.
> 
> Ah no it's fine, it'll default to the sector size of the device, which
> is set before the discard limit/granularity. So should work fine as-is.

Replying to myself again... It does then default it to the logical block
size, not the physical one. Which does look odd, seems like that should
be the physical size?

In any case, this does change behavior for zram.

Christoph?

-- 
Jens Axboe


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

* Re: [PATCH 3/9] block: default the discard granularity to sector size
  2023-12-28  7:55 ` [PATCH 3/9] block: default the discard granularity to sector size Christoph Hellwig
@ 2024-01-02 22:11   ` John Pittman
  2024-01-03  7:57     ` Christoph Hellwig
  0 siblings, 1 reply; 21+ messages in thread
From: John Pittman @ 2024-01-02 22:11 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Richard Weinberger, Anton Ivanov, Josef Bacik,
	Minchan Kim, Sergey Senozhatsky, Coly Li, Miquel Raynal,
	Vignesh Raghavendra, linux-um, linux-block, nbd, linux-bcache,
	linux-mtd

Hi Christoph, is there a reason you used 512 instead of SECTOR_SIZE
from include/linux/blk_types.h?  Thanks!

On Thu, Dec 28, 2023 at 2:56 AM Christoph Hellwig <hch@lst.de> wrote:
>
> Current the discard granularity defaults to 0 and must be initialized by
> any driver that wants to support discard.  Default to the sector size
> instead, which is the smallest possible value, and a very useful default.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  block/blk-settings.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index ba6e0e97118c08..d993d20dab3c6d 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -48,7 +48,7 @@ void blk_set_default_limits(struct queue_limits *lim)
>         lim->max_discard_sectors = 0;
>         lim->max_hw_discard_sectors = 0;
>         lim->max_secure_erase_sectors = 0;
> -       lim->discard_granularity = 0;
> +       lim->discard_granularity = 512;
>         lim->discard_alignment = 0;
>         lim->discard_misaligned = 0;
>         lim->logical_block_size = lim->physical_block_size = lim->io_min = 512;
> @@ -309,6 +309,9 @@ void blk_queue_logical_block_size(struct request_queue *q, unsigned int size)
>
>         limits->logical_block_size = size;
>
> +       if (limits->discard_granularity < limits->logical_block_size)
> +               limits->discard_granularity = limits->logical_block_size;
> +
>         if (limits->physical_block_size < size)
>                 limits->physical_block_size = size;
>
> --
> 2.39.2
>
>


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

* Re: [PATCH 3/9] block: default the discard granularity to sector size
  2024-01-02 22:11   ` John Pittman
@ 2024-01-03  7:57     ` Christoph Hellwig
  0 siblings, 0 replies; 21+ messages in thread
From: Christoph Hellwig @ 2024-01-03  7:57 UTC (permalink / raw)
  To: John Pittman
  Cc: Christoph Hellwig, Jens Axboe, Richard Weinberger, Anton Ivanov,
	Josef Bacik, Minchan Kim, Sergey Senozhatsky, Coly Li,
	Miquel Raynal, Vignesh Raghavendra, linux-um, linux-block, nbd,
	linux-bcache, linux-mtd

On Tue, Jan 02, 2024 at 05:11:19PM -0500, John Pittman wrote:
> Hi Christoph, is there a reason you used 512 instead of SECTOR_SIZE
> from include/linux/blk_types.h?  Thanks!

To match the logical_block_size/physical_block_size/io_min
assignments just below.

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

* Re: [PATCH 8/9] bcache: use the default discard granularity
  2023-12-28  7:55 ` [PATCH 8/9] bcache: " Christoph Hellwig
@ 2024-01-05  7:03   ` Coly Li
  0 siblings, 0 replies; 21+ messages in thread
From: Coly Li @ 2024-01-05  7:03 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Richard Weinberger, Anton Ivanov, Josef Bacik,
	Minchan Kim, Sergey Senozhatsky, Miquel Raynal,
	Vignesh Raghavendra, linux-um, linux-block, nbd, linux-bcache,
	linux-mtd

On Thu, Dec 28, 2023 at 07:55:44AM +0000, Christoph Hellwig wrote:
> The discard granularity now defaults to a single sector, so don't set
> that value explicitly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Coly Li <colyli@suse.de>

Thanks.

> ---
>  drivers/md/bcache/super.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index ecc1447f202a42..39ec95b8613f1f 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -954,7 +954,6 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
>  	q->limits.max_segment_size	= UINT_MAX;
>  	q->limits.max_segments		= BIO_MAX_VECS;
>  	blk_queue_max_discard_sectors(q, UINT_MAX);
> -	q->limits.discard_granularity	= block_size;
>  	q->limits.io_min		= block_size;
>  	q->limits.logical_block_size	= block_size;
>  	q->limits.physical_block_size	= block_size;
> -- 
> 2.39.2
> 
> 

-- 
Coly Li

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

* Re: [PATCH 7/9] zram: use the default discard granularity
  2023-12-28  7:55 ` [PATCH 7/9] zram: " Christoph Hellwig
  2024-01-02  1:15   ` Sergey Senozhatsky
@ 2024-01-06  1:32   ` Sergey Senozhatsky
  1 sibling, 0 replies; 21+ messages in thread
From: Sergey Senozhatsky @ 2024-01-06  1:32 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Richard Weinberger, Anton Ivanov, Josef Bacik,
	Minchan Kim, Sergey Senozhatsky, Coly Li, Miquel Raynal,
	Vignesh Raghavendra, linux-um, linux-block, nbd, linux-bcache,
	linux-mtd

On (23/12/28 07:55), Christoph Hellwig wrote:
> 
> The discard granularity now defaults to a single sector, so don't set
> that value explicitly.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

FWIW,
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>

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

end of thread, other threads:[~2024-01-06  1:33 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-28  7:55 provide a sane discard_granularity default Christoph Hellwig
2023-12-28  7:55 ` [PATCH 1/9] block: remove two comments in bio_split_discard Christoph Hellwig
2023-12-28  7:55 ` [PATCH 2/9] bcache: discard_granularity should not be smaller than a sector Christoph Hellwig
2023-12-28  7:55 ` [PATCH 3/9] block: default the discard granularity to sector size Christoph Hellwig
2024-01-02 22:11   ` John Pittman
2024-01-03  7:57     ` Christoph Hellwig
2023-12-28  7:55 ` [PATCH 4/9] ubd: use the default discard granularity Christoph Hellwig
2023-12-28 11:10   ` Richard Weinberger
2023-12-28  7:55 ` [PATCH 5/9] nbd: " Christoph Hellwig
2023-12-28  7:55 ` [PATCH 6/9] null_blk: " Christoph Hellwig
2023-12-28  7:55 ` [PATCH 7/9] zram: " Christoph Hellwig
2024-01-02  1:15   ` Sergey Senozhatsky
2024-01-02 15:40     ` Jens Axboe
2024-01-02 15:44       ` Jens Axboe
2024-01-02 15:47         ` Jens Axboe
2024-01-06  1:32   ` Sergey Senozhatsky
2023-12-28  7:55 ` [PATCH 8/9] bcache: " Christoph Hellwig
2024-01-05  7:03   ` Coly Li
2023-12-28  7:55 ` [PATCH 9/9] mtd_blkdevs: " Christoph Hellwig
2023-12-28 11:09   ` Richard Weinberger
2023-12-29 15:44 ` provide a sane discard_granularity default Jens Axboe

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