Linux block layer
 help / color / mirror / Atom feed
* [PATCH] block: set reasonable default for discard max
@ 2023-06-09 18:08 John Pittman
  2023-06-09 18:46 ` Martin K. Petersen
  2023-06-13  1:37 ` Ming Lei
  0 siblings, 2 replies; 12+ messages in thread
From: John Pittman @ 2023-06-09 18:08 UTC (permalink / raw)
  To: axboe; +Cc: djeffery, loberman, emilne, minlei, linux-block, John Pittman

Some drive manufacturers export a very large supported max discard size.
However, when the operating system sends I/O of the max size to the
device, extreme I/O latency can often be encountered. Since hardware
does not provide an optimal discard value in addition to the max, and
there is no way to foreshadow how well a drive handles the large size,
take the method from max_sectors setting, and use BLK_DEF_MAX_SECTORS to
set a more reasonable default discard max. This should avoid the extreme
latency while still allowing the user to increase the value for specific
needs.

Signed-off-by: John Pittman <jpittman@redhat.com>
Suggested-by: David Jeffery <djeffery@redhat.com>
---
 Documentation/ABI/stable/sysfs-block | 4 +++-
 block/blk-settings.c                 | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block
index c57e5b7cb532..158a1e6f1f6d 100644
--- a/Documentation/ABI/stable/sysfs-block
+++ b/Documentation/ABI/stable/sysfs-block
@@ -235,7 +235,9 @@ Description:
 		large latencies when large discards are issued, setting this
 		value lower will make Linux issue smaller discards and
 		potentially help reduce latencies induced by large discard
-		operations.
+		operations. For this reason, the max is currently defaulted to
+		four times BLK_DEF_MAX_SECTORS, but can be increased via sysfs
+		as needed.
 
 
 What:		/sys/block/<disk>/queue/discard_max_hw_bytes
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 4dd59059b788..4401c0b8477e 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -179,7 +179,8 @@ void blk_queue_max_discard_sectors(struct request_queue *q,
 		unsigned int max_discard_sectors)
 {
 	q->limits.max_hw_discard_sectors = max_discard_sectors;
-	q->limits.max_discard_sectors = max_discard_sectors;
+	q->limits.max_discard_sectors = min(max_discard_sectors,
+						BLK_DEF_MAX_SECTORS * 4);
 }
 EXPORT_SYMBOL(blk_queue_max_discard_sectors);
 
-- 
2.38.1


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

end of thread, other threads:[~2023-07-20 14:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-09 18:08 [PATCH] block: set reasonable default for discard max John Pittman
2023-06-09 18:46 ` Martin K. Petersen
2023-06-10  0:22   ` John Pittman
2023-06-10 22:52     ` Chaitanya Kulkarni
2023-06-13  0:55     ` Martin K. Petersen
2023-06-13 11:23       ` Ewan Milne
2023-06-13  1:37 ` Ming Lei
2023-06-19 16:02   ` John Pittman
2023-06-20 15:06     ` Martin K. Petersen
2023-07-14 17:15       ` John Pittman
2023-07-20  1:58         ` Martin K. Petersen
2023-07-20 14:43           ` John Pittman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox