Skip to contentSkip to conversation

blk: use correct sectors limitation for discard request

PATCH In review Shaohua Li 2 participants 3 messages Mar 16, 2012 – Mar 21, 2012 Block layer

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 blk: use correct sectors limitation for discard request

Subject: blk: use correct sectors limitation for discard request

max_discard_sectors doesn't equal to max_sectors/max_hw_sectors. Without this, discard request merge might be ignored.

---
 block/blk-merge.c      |   13 ++++++++-----
 include/linux/blkdev.h |    5 +++++
 2 files changed, 13 insertions(+), 5 deletions(-)
block/blk-merge.c +8 -5
Index: linux/block/blk-merge.c
===================================================================
@@ -228,9 +228,11 @@ no_merge:
 int ll_back_merge_fn(struct request_queue *q, struct request *req,
 		     struct bio *bio)
 {
-	unsigned short max_sectors;
+	unsigned int max_sectors;
 
-	if (unlikely(req->cmd_type == REQ_TYPE_BLOCK_PC))
+	if (unlikely(req->cmd_flags & REQ_DISCARD))
+		max_sectors = queue_max_discard_sectors(q);
+	else if (unlikely(req->cmd_type == REQ_TYPE_BLOCK_PC))
 		max_sectors = queue_max_hw_sectors(q);
 	else
 		max_sectors = queue_max_sectors(q);
@@ -252,14 +254,15 @@ int ll_back_merge_fn(struct request_queu
 int ll_front_merge_fn(struct request_queue *q, struct request *req,
 		      struct bio *bio)
 {
-	unsigned short max_sectors;
+	unsigned int max_sectors;
 
-	if (unlikely(req->cmd_type == REQ_TYPE_BLOCK_PC))
+	if (unlikely(req->cmd_flags & REQ_DISCARD))
+		max_sectors = queue_max_discard_sectors(q);
+	else if (unlikely(req->cmd_type == REQ_TYPE_BLOCK_PC))
 		max_sectors = queue_max_hw_sectors(q);
 	else
 		max_sectors = queue_max_sectors(q);
 
-
 	if (blk_rq_sectors(req) + bio_sectors(bio) > max_sectors) {
 		req->cmd_flags |= REQ_NOMERGE;
 		if (req == q->last_merge)
include/linux/blkdev.h +5 -0
Index: linux/include/linux/blkdev.h
===================================================================
@@ -1006,6 +1006,11 @@ static inline unsigned int queue_max_hw_
 	return q->limits.max_hw_sectors;
 }
 
+static inline unsigned int queue_max_discard_sectors(struct request_queue *q)
+{
+	return q->limits.max_discard_sectors;
+}
+
 static inline unsigned short queue_max_segments(struct request_queue *q)
 {
 	return q->limits.max_segments;
#1 lore raw
Quoted 6 lines · Shaohua Li

Subject: blk: use correct sectors limitation for discard request

max_discard_sectors doesn't equal to max_sectors/max_hw_sectors. Without this,
discard request merge might be ignored.

In other patch you are making discard request non-mergeable. So what's the purpose of this patch.

Thanks
Vivek

author
#2 lore raw

2012/3/21 Vivek Goyal <[email protected]>:

Quoted 10 lines · Shaohua Li
Quoted 6 lines

Subject: blk: use correct sectors limitation for discard request

max_discard_sectors doesn't equal to max_sectors/max_hw_sectors. Without this,
discard request merge might be ignored.

In other patch you are making discard request non-mergeable. So what's the purpose of this patch.

Yep, this one has no effect with that patch. But this is a bug, and eventually we will support discard merge. Just to make sure it doesn't slip away.