[PATCH] block: set reasonable default for discard max

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Suggested-by: David Jeffery <djeffery@xxxxxxxxxx>
---
 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




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux