diff mbox series

block: floor the discard granularity to the physical block size

Message ID 20240103081622.508754-1-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series block: floor the discard granularity to the physical block size | expand

Commit Message

Christoph Hellwig Jan. 3, 2024, 8:16 a.m. UTC
Discarding less than a physical block doesn't make sense.  This fixes
the existing behavior for zram before the recent changes to default
the discard granularity to the logical block size, and is also a
generally useful sanity check.

Fixes: 3753039def5d ("zram: use the default discard granularity")
Reported-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-settings.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jens Axboe Jan. 4, 2024, 11:10 p.m. UTC | #1
On Wed, 03 Jan 2024 08:16:22 +0000, Christoph Hellwig wrote:
> Discarding less than a physical block doesn't make sense.  This fixes
> the existing behavior for zram before the recent changes to default
> the discard granularity to the logical block size, and is also a
> generally useful sanity check.
> 
> 

Applied, thanks!

[1/1] block: floor the discard granularity to the physical block size
      commit: 458aa1a09939a56e044768013c86b5ef06e1c4f1

Best regards,
Sergey Senozhatsky Jan. 6, 2024, 1:31 a.m. UTC | #2
On (24/01/03 08:16), Christoph Hellwig wrote:
> 
> Discarding less than a physical block doesn't make sense.  This fixes
> the existing behavior for zram before the recent changes to default
> the discard granularity to the logical block size, and is also a
> generally useful sanity check.
> 
> Fixes: 3753039def5d ("zram: use the default discard granularity")
> Reported-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

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

Patch

diff --git a/block/blk-settings.c b/block/blk-settings.c
index d993d20dab3c6d..06ea91e51b8b2e 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -342,6 +342,9 @@  void blk_queue_physical_block_size(struct request_queue *q, unsigned int size)
 	if (q->limits.physical_block_size < q->limits.logical_block_size)
 		q->limits.physical_block_size = q->limits.logical_block_size;
 
+	if (q->limits.discard_granularity < q->limits.physical_block_size)
+		q->limits.discard_granularity = q->limits.physical_block_size;
+
 	if (q->limits.io_min < q->limits.physical_block_size)
 		q->limits.io_min = q->limits.physical_block_size;
 }