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
1780 INIT_LIST_HEAD(&plug->mq_list);1780 INIT_LIST_HEAD(&plug->mq_list);
1781 INIT_LIST_HEAD(&plug->cb_list);1781 INIT_LIST_HEAD(&plug->cb_list);
1782 plug->rq_count = 0;1782 plug->rq_count = 0;
1783 plug->multiple_queues = false;
1783 1784
1784 /*1785 /*
1785 * Store ordering should not be needed here, since a potential1786 * 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
1677 list_splice_init(&plug->mq_list, &list);1677 list_splice_init(&plug->mq_list, &list);
1678 plug->rq_count = 0;1678 plug->rq_count = 0;
1679 1679
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);
1681 1682
1682 this_q = NULL;1683 this_q = NULL;
1683 this_hctx = NULL;1684 this_hctx = NULL;
@@ -1866,6 +1867,20 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, · 182 unmodified lines
1866 }1867 }
1867}1868}
1868 1869
1870static 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
1869static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)1884static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
1870{1885{
1871 const int is_sync = op_is_sync(bio->bi_opf);1886 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
1932 trace_block_plug(q);1947 trace_block_plug(q);
1933 }1948 }
1934 1949
1935 list_add_tail(&rq->queuelist, &plug->mq_list);1950 blk_add_rq_to_plug(plug, rq);
1936 plug->rq_count++;
1937 } else if (plug && !blk_queue_nomerges(q)) {1951 } else if (plug && !blk_queue_nomerges(q)) {
1938 blk_mq_bio_to_request(rq, bio);1952 blk_mq_bio_to_request(rq, bio);
1939 1953
@@ -1950,8 +1964,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · 10 unmodified lines
1950 list_del_init(&same_queue_rq->queuelist);1964 list_del_init(&same_queue_rq->queuelist);
1951 plug->rq_count--;1965 plug->rq_count--;
1952 }1966 }
1953 list_add_tail(&rq->queuelist, &plug->mq_list);1967 blk_add_rq_to_plug(plug, rq);
1954 plug->rq_count++;
1955 1968
1956 blk_mq_put_ctx(data.ctx);1969 blk_mq_put_ctx(data.ctx);
1957 1970
include/linux/blkdev.h+1−0
@@ -1131,6 +1131,7 @@ struct blk_plug { · 1130 unmodified lines
1131 struct list_head mq_list; /* blk-mq requests */1131 struct list_head mq_list; /* blk-mq requests */
1132 struct list_head cb_list; /* md requires an unplug callback */1132 struct list_head cb_list; /* md requires an unplug callback */
1133 unsigned short rq_count;1133 unsigned short rq_count;
1134 bool multiple_queues;
1134};1135};
1135#define BLK_MAX_REQUEST_COUNT 161136#define BLK_MAX_REQUEST_COUNT 16
1136#define BLK_PLUG_FLUSH_SIZE (128 * 1024)1137#define BLK_PLUG_FLUSH_SIZE (128 * 1024)