提交 26702d43 编写于 作者: J Jens Axboe 提交者: Baolin Wang

block: improve logic around when to sort a plug list

fix #28871358

Only do it if we have requests for multiple queues in the same
plug.
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NBaolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
上级 8edf7c76
...@@ -3625,6 +3625,7 @@ void blk_start_plug(struct blk_plug *plug) ...@@ -3625,6 +3625,7 @@ void blk_start_plug(struct blk_plug *plug)
INIT_LIST_HEAD(&plug->list); INIT_LIST_HEAD(&plug->list);
INIT_LIST_HEAD(&plug->mq_list); INIT_LIST_HEAD(&plug->mq_list);
INIT_LIST_HEAD(&plug->cb_list); INIT_LIST_HEAD(&plug->cb_list);
plug->multiple_queues = false;
/* /*
* Store ordering should not be needed here, since a potential * Store ordering should not be needed here, since a potential
* preempt will imply a full memory barrier * preempt will imply a full memory barrier
......
...@@ -1664,6 +1664,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) ...@@ -1664,6 +1664,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
list_splice_init(&plug->mq_list, &list); list_splice_init(&plug->mq_list, &list);
if (plug->multiple_queues)
list_sort(NULL, &list, plug_ctx_cmp); list_sort(NULL, &list, plug_ctx_cmp);
this_q = NULL; this_q = NULL;
...@@ -1855,6 +1856,19 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, ...@@ -1855,6 +1856,19 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
} }
} }
static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
{
list_add_tail(&rq->queuelist, &plug->mq_list);
if (!plug->multiple_queues && !list_is_singular(&plug->mq_list)) {
struct request *tmp;
tmp = list_first_entry(&plug->mq_list, struct request,
queuelist);
if (tmp->q != rq->q)
plug->multiple_queues = true;
}
}
static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
{ {
const int is_sync = op_is_sync(bio->bi_opf); const int is_sync = op_is_sync(bio->bi_opf);
...@@ -1930,7 +1944,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) ...@@ -1930,7 +1944,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
trace_block_plug(q); trace_block_plug(q);
} }
list_add_tail(&rq->queuelist, &plug->mq_list); blk_add_rq_to_plug(plug, rq);
} else if (plug && !blk_queue_nomerges(q)) { } else if (plug && !blk_queue_nomerges(q)) {
blk_mq_bio_to_request(rq, bio); blk_mq_bio_to_request(rq, bio);
...@@ -1945,7 +1959,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) ...@@ -1945,7 +1959,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
same_queue_rq = NULL; same_queue_rq = NULL;
if (same_queue_rq) if (same_queue_rq)
list_del_init(&same_queue_rq->queuelist); list_del_init(&same_queue_rq->queuelist);
list_add_tail(&rq->queuelist, &plug->mq_list); blk_add_rq_to_plug(plug, rq);
blk_mq_put_ctx(data.ctx); blk_mq_put_ctx(data.ctx);
......
...@@ -1348,6 +1348,7 @@ struct blk_plug { ...@@ -1348,6 +1348,7 @@ struct blk_plug {
struct list_head list; /* requests */ struct list_head list; /* requests */
struct list_head mq_list; /* blk-mq requests */ struct list_head mq_list; /* blk-mq requests */
struct list_head cb_list; /* md requires an unplug callback */ struct list_head cb_list; /* md requires an unplug callback */
bool multiple_queues;
}; };
#define BLK_MAX_REQUEST_COUNT 16 #define BLK_MAX_REQUEST_COUNT 16
#define BLK_PLUG_FLUSH_SIZE (128 * 1024) #define BLK_PLUG_FLUSH_SIZE (128 * 1024)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册