diff mbox series

[3/9] block: default the discard granularity to sector size

Message ID 20231228075545.362768-4-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/9] block: remove two comments in bio_split_discard | expand

Commit Message

Christoph Hellwig Dec. 28, 2023, 7:55 a.m. UTC
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(-)

Comments

John Pittman Jan. 2, 2024, 10:11 p.m. UTC | #1
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
>
>
Christoph Hellwig Jan. 3, 2024, 7:57 a.m. UTC | #2
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.
diff mbox series

Patch

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;