Skip to contentSkip to conversation

block: avoid unnecessary plug list flush

PATCH In review Shaohua Li 2 participants 2 messages Sep 28, 2011 Block layer

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/2 block: avoid unnecessary plug list flush

get_request_wait() could sleep and flush the plug list. If the list is already flushed, don't flush again.

---
 block/blk-core.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
block/blk-core.c +9 -7
Index: linux/block/blk-core.c
===================================================================
@@ -1299,15 +1299,17 @@ get_rq:
 		 */
 		if (list_empty(&plug->list))
 			trace_block_plug(q);
-		else if (!plug->should_sort) {
-			struct request *__rq;
+		else {
+			if (!plug->should_sort) {
+				struct request *__rq;
 
-			__rq = list_entry_rq(plug->list.prev);
-			if (__rq->q != q)
-				plug->should_sort = 1;
+				__rq = list_entry_rq(plug->list.prev);
+				if (__rq->q != q)
+					plug->should_sort = 1;
+			}
+			if (request_count >= BLK_MAX_REQUEST_COUNT)
+				blk_flush_plug_list(plug, false);
 		}
-		if (request_count >= BLK_MAX_REQUEST_COUNT)
-			blk_flush_plug_list(plug, false);
 		list_add_tail(&req->queuelist, &plug->list);
 		drive_stat_acct(req, 1);
 	} else {
Reviewed-by on v1 1/2
#1 lore raw
Quoted 4 lines · Shaohua Li

get_request_wait() could sleep and flush the plug list. If the list is already flushed, don't flush again.

Good catch! If get_request_wait() updated request_count after sleeping we could live with the original code, but your change makes more sense IMHO.

Thanks.

Quoted 34 lines
---
 block/blk-core.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Index: linux/block/blk-core.c
===================================================================

block/blk-core.c +9 -7
@@ -1299,15 +1299,17 @@ get_rq:
 		 */
 		if (list_empty(&plug->list))
 			trace_block_plug(q);
-		else if (!plug->should_sort) {
-			struct request *__rq;
+		else {
+			if (!plug->should_sort) {
+				struct request *__rq;
 
-			__rq = list_entry_rq(plug->list.prev);
-			if (__rq->q != q)
-				plug->should_sort = 1;
+				__rq = list_entry_rq(plug->list.prev);
+				if (__rq->q != q)
+					plug->should_sort = 1;
+			}
+			if (request_count >= BLK_MAX_REQUEST_COUNT)
+				blk_flush_plug_list(plug, false);
 		}
-		if (request_count >= BLK_MAX_REQUEST_COUNT)
-			blk_flush_plug_list(plug, false);
 		list_add_tail(&req->queuelist, &plug->list);
 		drive_stat_acct(req, 1);
 	} else {