blk-mq: add direct dispatch support for mq-deadline
Subsystems (2)
PATCH 1/1 blk-mq: add direct dispatch support for mq-deadline
From: Kaitao Cheng <[email protected]>
On fast devices such as NVMe SSDs with spare capacity, scheduler insertion, sorting and merging may add CPU overhead with little benefit. Allowing new requests to reach the driver directly can reduce submission latency and improve bandwidth when this overhead limits performance.
Add a skip_request elevator callback to support direct dispatch for unplugged submissions and plug flushes outside the scheduling path. Implement it in mq-deadline with request accounting preserved across reinsertion and retries.
Expose a dispatch_direct tunable, enabled by default. Directly dispatched requests may bypass queued requests, including higher priority or expired requests. Setting dispatch_direct to 0 restores normal scheduler insertion.
Test sequential writes on an NVMe SSD with fio, comparing none, unmodified mq-deadline, and mq-deadline with this patch and dispatch_direct enabled.
test A:
fio -name=jobs1-4k -direct=1 -iodepth=16 -numjobs=1 -filename=fiolog.txt
-ioengine=libaio -blocksize=4k -size=10GB -rw=write -runtime=120 -time_based -ramp_time=30
test B:
fio -name=jobs10-4k -direct=1 -iodepth=16 -numjobs=10 -filename=fiolog.txt
-ioengine=libaio -blocksize=4k -size=10GB -rw=write -runtime=120 -time_based -ramp_time=30
test C:
fio -name=jobs1-32k -direct=1 -iodepth=16 -numjobs=1 -filename=fiolog.txt
-ioengine=libaio -blocksize=32k -size=10GB -rw=write -runtime=120
-time_based -ramp_time=30Bandwidth in MiB/s:
Workload none mq-deadline my-patch jobs1-4k 1209 1047 1174 jobs10-4k 2458 946 2349 jobs1-32k 2568 2565 2562
Direct dispatch improves bandwidth over unmodified mq-deadline by 12.1% with one job and 148.3% with multiple jobs for the 4 KiB workloads, reaching 97.1% and 95.6% of the bandwidth achieved with none, respectively. All three configurations achieve the same maximum bandwidth.
--- Documentation/block/deadline-iosched.rst | 14 +++++++ block/blk-mq.c | 40 ++++++++++++++----- block/elevator.h | 1 + block/mq-deadline.c | 50 +++++++++++++++++++++++- 4 files changed, 94 insertions(+), 11 deletions(-)
Documentation/block/deadline-iosched.rst +14 -0
@@ -69,4 +69,18 @@ that comes at basically 0 cost we leave that on. We simply disable the rbtree front sector lookup when the io scheduler merge function is called. +dispatch_direct (bool) +---------------------- + +Enabled by default. Allows new requests to bypass the scheduler's sort tree, +FIFO and merge hash when the hardware context is not congested, stopped or +quiesced. On fast devices such as NVMe SSDs with spare capacity, sorting and +merging may offer little benefit while adding CPU overhead and limiting +bandwidth. Direct dispatch can reduce this overhead and submission latency. + +Direct dispatch reduces opportunities for merging and sorting, and may bypass +queued requests, including higher priority or expired requests. Set +dispatch_direct to 0 to restore normal scheduler insertion. + + Nov 11 2002, Jens Axboe <[email protected]>
block/blk-mq.c +31 -9
@@ -2751,17 +2751,26 @@ static bool blk_mq_get_budget_and_tag(struct request *rq)static void blk_mq_try_issue_directly (struct blk_mq_hw_ctx *hctx,struct request *rq) { +bool use_sched = rq->rq_flags &RQF_USE_SCHED ; +bool run_queue_async = use_sched || (rq->cmd_flags &REQ_NOWAIT );blk_status_t ret;if (blk_mq_hctx_stopped (hctx) ||blk_queue_quiesced (rq->q)) {blk_mq_insert_request (rq,0 ); -blk_mq_run_hw_queue (hctx, false); +blk_mq_run_hw_queue (hctx, use_sched);return ; } -if ((rq->rq_flags &RQF_USE_SCHED ) || !blk_mq_get_budget_and_tag (rq)) { +if (use_sched) { +struct elevator_mq_ops *ops = &rq->q->elevator->type->ops; + +if (ops->skip_request) + use_sched = !ops->skip_request (rq); + } + +if (use_sched || !blk_mq_get_budget_and_tag (rq)) {blk_mq_insert_request (rq,0 ); -blk_mq_run_hw_queue (hctx, rq->cmd_flags &REQ_NOWAIT ); +blk_mq_run_hw_queue (hctx, run_queue_async);return ; }
@@ -2927,9 +2936,14 @@ static void blk_mq_dispatch_list(struct rq_list *rqs, bool from_sched)spin_unlock (&this_hctx->lock);blk_mq_run_hw_queue (this_hctx, from_sched); }else if (this_hctx->queue->elevator) { - this_hctx->queue->elevator->type->ops.insert_requests (this_hctx, - &list,0 ); -blk_mq_run_hw_queue (this_hctx, from_sched); +if (!this_hctx->dispatch_busy && !from_sched) +blk_mq_run_dispatch_ops (this_hctx->queue, +blk_mq_try_issue_list_directly (this_hctx, &list)); +if (!list_empty (&list)) { + this_hctx->queue->elevator->type->ops.insert_requests ( + this_hctx, &list,0 ); +blk_mq_run_hw_queue (this_hctx, from_sched); + } }else {blk_mq_insert_requests (this_hctx, this_ctx, &list, from_sched); }
@@ -2984,6 +2998,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)static void blk_mq_try_issue_list_directly (struct blk_mq_hw_ctx *hctx,struct list_head *list) { +struct elevator_queue *e = hctx->queue->elevator;int queued =0 ;blk_status_t ret =BLK_STS_OK ;
@@ -2991,6 +3006,14 @@ static void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, struct request *rq = list_first_entry(list, struct request, queuelist); +/* Scheduler requests need approval and dispatch accounting. */ +if (e && (READ_ONCE (hctx->dispatch_busy) || +blk_mq_hctx_stopped (hctx) || +blk_queue_quiesced (hctx->queue) || + !e->type->ops.skip_request || + !e->type->ops.skip_request (rq))) +break ; +list_del_init (&rq->queuelist); ret =blk_mq_request_issue_directly (rq,list_empty (list));switch (ret) {
@@ -3010,7 +3033,7 @@ static void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, } out: -if (ret !=BLK_STS_OK ) +if (ret !=BLK_STS_OK || !list_empty (list))blk_mq_commit_rqs (hctx, queued, false); }
@@ -3218,8 +3241,7 @@ void blk_mq_submit_bio(struct bio *bio) } hctx = rq->mq_hctx; -if ((rq->rq_flags &RQF_USE_SCHED ) || - (hctx->dispatch_busy && (q->nr_hw_queues ==1 || !is_sync))) { +if (hctx->dispatch_busy && (q->nr_hw_queues ==1 || !is_sync)) {blk_mq_insert_request (rq,0 );blk_mq_run_hw_queue (hctx, true); }else {
block/elevator.h +1 -0
@@ -74,6 +74,7 @@ struct elevator_mq_ops {void (*insert_requests)(struct blk_mq_hw_ctx *hctx,struct list_head *list,blk_insert_t flags);struct request *(*dispatch_request)(struct blk_mq_hw_ctx *); +bool (*skip_request)(struct request *rq);bool (*has_work)(struct blk_mq_hw_ctx *);void (*completed_request)(struct request *,u64 );void (*requeue_request)(struct request *);
block/mq-deadline.c +48 -2
98 lines not on this page · raw message
Signature · 1 line
2.54.0 (Apple Git-157)
Quoted 6 lines · Kaitao Cheng
Bandwidth in MiB/s:
Workload none mq-deadline my-patch jobs1-4k 1209 1047 1174 jobs10-4k 2458 946 2349 jobs1-32k 2568 2565 2562
Can I conclude from the above numbers that "none" performs better than "mq-deadline" and hence that it's better not to use and I/O scheduler rather than to complicate the mq-deadline source code?
I have removed the linux-doc and linux-kernel mailing lists from the Cc-list. Block layer patches should be posted on the linux-block mailing list only.
Thanks,
Bart.
Quoted 8 lines · Bart Van Assche
Quoted 6 lines · Kaitao Cheng
Bandwidth in MiB/s:
Workload none mq-deadline my-patch jobs1-4k 1209 1047 1174 jobs10-4k 2458 946 2349 jobs1-32k 2568 2565 2562
Quoted 4 lines
Can I conclude from the above numbers that "none" performs better than "mq-deadline" and hence that it's better not to use and I/O scheduler rather than to complicate the mq-deadline source code?
During testing, I found that the none scheduler does not outperform mq-deadline in every scenario. There seems to be a tendency for none to perform better on faster devices, but this is not always the case. My guess is that effective request merging in mq-deadline improves performance by reducing the number of requests dispatched to the driver, while lock contention among multiple threads reduces its performance. These competing effects make it difficult for users to choose a suitable I/O scheduler, or decide whether to use none. This patch could substantially broaden the range of workloads for which mq-deadline is suitable.
Some users may need scheduler features such as deadlines or priorities, or may want to add instrumentation through a scheduler. These requirements may lead them to choose mq-deadline or another custom scheduler. In such cases, this patch could provide substantial performance improvements.
This approach could potentially benefit any I/O scheduler. With the skip_request callback, a scheduler can choose whether to sort all requests unconditionally or only when the device is congested. I suspect that adapting BFQ to use this callback could provide similar benefits, and I can test this if there is interest.
The hardware available to me limits the types of storage devices I can test. But please still let me know if any additional tests are needed, and I will do my best to run them.
Quoted 3 lines
I have removed the linux-doc and linux-kernel mailing lists from the Cc-list. Block layer patches should be posted on the linux-block mailing list only.
Could the changes to Documentation/block/deadline-iosched.rst be why these mailing lists were added to Cc?
Quoted 3 lines
Thanks,
Bart.
Signature · 2 lines
Thanks Kaitao Cheng
Quoted 8 lines · Bart Van Assche
Quoted 6 lines · Kaitao Cheng
Bandwidth in MiB/s:
Workload none mq-deadline my-patch jobs1-4k 1209 1047 1174 jobs10-4k 2458 946 2349 jobs1-32k 2568 2565 2562
Quoted 9 lines
Can I conclude from the above numbers that "none" performs better than "mq-deadline" and hence that it's better not to use and I/O scheduler rather than to complicate the mq-deadline source code?
I have removed the linux-doc and linux-kernel mailing lists from the Cc-list. Block layer patches should be posted on the linux-block mailing list only.
I ran additional tests on both a SATA SSD and a SAS HDD. The results are as follows:
SATA SSD none mq-deadline my-patch
jobs1-4k 294 295 295
jobs10-4k 133 400 401
jobs1-32k 470 470 470
SAS HDD none mq-deadline my-patch
jobs1-4k 218 218 218
jobs10-4k 26.6 26.9 27.2
jobs1-32k 225 224 224The SAS HDD results show no clear performance differences. On the SATA SSD, however, mq-deadline outperforms none, and my patch preserves mq-deadline's performance. Together with the earlier NVMe SSD results, these results suggest that the patch combines the benefits of both none and mq-deadline.
I also found in the NVMe SSD tests that disabling the direct dispatch paths used with the none scheduler causes its performance to drop to the same level as mq-deadline.
Signature · 2 lines
Thanks Kaitao Cheng