History

block: improve logic around when to sort a plug list

Only do it if we have requests for multiple queues in the same plug.

Jens Axboe committed 7 years ago

Commit ce5b0091 parent 4e6db0f3 files · +20 −5Browse files

Unified · Split

3 files
  1. block/blk-core.c +1 −0
  2. block/blk-mq.c +18 −5
  3. include/linux/blkdev.h +1 −0
block/blk-core.c+1−0
@@ -1780,6 +1780,7 @@ void blk_start_plug(struct blk_plug *plug) · 1779 unmodified lines
17801780 INIT_LIST_HEAD(&plug->mq_list);
17811781 INIT_LIST_HEAD(&plug->cb_list);
17821782 plug->rq_count = 0;
1783+ plug->multiple_queues = false;
17831784
17841785 /*
17851786 * Store ordering should not be needed here, since a potential
block/blk-mq.c+18−5
@@ -1677,7 +1677,8 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) · 1676 unmodified lines
16771677 list_splice_init(&plug->mq_list, &list);
16781678 plug->rq_count = 0;
16791679
1680− list_sort(NULL, &list, plug_rq_cmp);
1680+ if (plug->rq_count > 2 && plug->multiple_queues)
1681+ list_sort(NULL, &list, plug_rq_cmp);
16811682
16821683 this_q = NULL;
16831684 this_hctx = NULL;
@@ -1866,6 +1867,20 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, · 182 unmodified lines
18661867 }
18671868 }
18681869
1870+static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
1871+{
1872+ list_add_tail(&rq->queuelist, &plug->mq_list);
1873+ plug->rq_count++;
1874+ if (!plug->multiple_queues && !list_is_singular(&plug->mq_list)) {
1875+ struct request *tmp;
1876+
1877+ tmp = list_first_entry(&plug->mq_list, struct request,
1878+ queuelist);
1879+ if (tmp->q != rq->q)
1880+ plug->multiple_queues = true;
1881+ }
1882+}
1883+
18691884 static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
18701885 {
18711886 const int is_sync = op_is_sync(bio->bi_opf);
@@ -1932,8 +1947,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · 60 unmodified lines
19321947 trace_block_plug(q);
19331948 }
19341949
1935− list_add_tail(&rq->queuelist, &plug->mq_list);
1936− plug->rq_count++;
1950+ blk_add_rq_to_plug(plug, rq);
19371951 } else if (plug && !blk_queue_nomerges(q)) {
19381952 blk_mq_bio_to_request(rq, bio);
19391953
@@ -1950,8 +1964,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · 10 unmodified lines
19501964 list_del_init(&same_queue_rq->queuelist);
19511965 plug->rq_count--;
19521966 }
1953− list_add_tail(&rq->queuelist, &plug->mq_list);
1954− plug->rq_count++;
1967+ blk_add_rq_to_plug(plug, rq);
19551968
19561969 blk_mq_put_ctx(data.ctx);
19571970
include/linux/blkdev.h+1−0
@@ -1131,6 +1131,7 @@ struct blk_plug { · 1130 unmodified lines
11311131 struct list_head mq_list; /* blk-mq requests */
11321132 struct list_head cb_list; /* md requires an unplug callback */
11331133 unsigned short rq_count;
1134+ bool multiple_queues;
11341135 };
11351136 #define BLK_MAX_REQUEST_COUNT 16
11361137 #define BLK_PLUG_FLUSH_SIZE (128 * 1024)