Skip to contentSkip to conversation

block: Avoid fragmented discard splits for ATA drives

PATCH New Tom Yan 1 participant 1 message Dec 15, 2020

Subsystems (3)
lore
Share & tools
lore

Tom Yan

author
#0 lore raw

PATCH 1/1 block: Avoid fragmented discard splits for ATA drives

When 0xffffffff >> 9 are splited by 0xffff * 64, there will be a remainder of 127. Avoid these small fragments by aligning the split to 128.

---
 block/blk.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
block/blk.h +5 -2
index dfab98465db9..1dc12fc86de8 100644
@@ -281,8 +281,11 @@ static inline unsigned int bio_allowed_max_sectors(struct request_queue *q)
 static inline unsigned int bio_aligned_discard_max_sectors(
 					struct request_queue *q)
 {
-	return round_down(UINT_MAX, q->limits.discard_granularity) >>
-			SECTOR_SHIFT;
+	unsigned int granularity = q->limits.discard_granularity;
+	/* Avoid fragmented splits for ATA drives */
+	if (128 % granularity == 0)
+		granularity = 128;
+	return round_down(UINT_MAX, granularity) >> SECTOR_SHIFT;
 }
 
 /*
Signature · 1 line
2.29.2