summaryrefslogtreecommitdiffstats
path: root/block/blk-settings.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2023-12-28 08:55:39 +0100
committerJens Axboe <axboe@kernel.dk>2023-12-29 16:44:12 +0100
commit3c407dc723bbf914f3744b0c2bb82265b411a50c (patch)
tree2bd3955509c1f70cee12ceecfcc17fbfd9cd9086 /block/blk-settings.c
parentbcache: discard_granularity should not be smaller than a sector (diff)
downloadlinux-3c407dc723bbf914f3744b0c2bb82265b411a50c.tar.xz
linux-3c407dc723bbf914f3744b0c2bb82265b411a50c.zip
block: default the discard granularity to sector size
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> Link: https://lore.kernel.org/r/20231228075545.362768-4-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-settings.c')
-rw-r--r--block/blk-settings.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/block/blk-settings.c b/block/blk-settings.c
index ba6e0e97118c..d993d20dab3c 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;