提交 ba2986d9 编写于 作者: J Jens Axboe 提交者: Caspar Zhang

blk-mq: improve plug list sorting

to #28991349

commit 3110fc79606fb6003949246c6fb325dd43445273 upstream

Currently we only look at the software queue, but with support
for multiple maps, we should also look at the hardware queue.
This is important since we'll flush out the request list if
either the software queue or hardware queue don't match.

This sorts by software queue first, then hardware queue if
that differs. Finally we sort by request location like before.
This minimizes the flush points per plug list.
Reviewed-by: NKeith Busch <keith.busch@intel.com>
Reviewed-by: NSagi Grimberg <sagi@grimberg.me>
Reviewed-by: NHannes Reinecke <hare@suse.com>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NXiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
Reviewed-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
上级 239c0d8b
......@@ -1657,14 +1657,21 @@ void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
spin_unlock(&ctx->lock);
}
static int plug_ctx_cmp(void *priv, struct list_head *a, struct list_head *b)
static int plug_rq_cmp(void *priv, struct list_head *a, struct list_head *b)
{
struct request *rqa = container_of(a, struct request, queuelist);
struct request *rqb = container_of(b, struct request, queuelist);
return !(rqa->mq_ctx < rqb->mq_ctx ||
(rqa->mq_ctx == rqb->mq_ctx &&
blk_rq_pos(rqa) < blk_rq_pos(rqb)));
if (rqa->mq_ctx < rqb->mq_ctx)
return -1;
else if (rqa->mq_ctx > rqb->mq_ctx)
return 1;
else if (rqa->mq_hctx < rqb->mq_hctx)
return -1;
else if (rqa->mq_hctx > rqb->mq_hctx)
return 1;
return blk_rq_pos(rqa) > blk_rq_pos(rqb);
}
void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
......@@ -1680,7 +1687,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
list_splice_init(&plug->mq_list, &list);
if (plug->multiple_queues)
list_sort(NULL, &list, plug_ctx_cmp);
list_sort(NULL, &list, plug_rq_cmp);
this_q = NULL;
this_hctx = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册