blk-mq scheduling framework
Subsystems (2)
PATCH v2 1/1 blk-mq scheduling framework
As a followup to this posting from yesterday:
https://marc.info/?l=linux-block&m=148115232806065&w=2
this is version 2. I wanted to post a new one fairly quickly, as there ended up being a number of potential crashes in v1. This one should be solid, I've run mq-deadline on both NVMe and regular rotating storage, and we handle the various merging cases correctly.
You can download it from git as well:
git://git.kernel.dk/linux-block blk-mq-sched.2
Note that this is based on for-4.10/block, which is in turn based on v4.9-rc1. I suggest pulling it into my for-next branch, which would then merge nicely with 'master' as well.
Changes since v1:
- Add Kconfig entries to allow the user to choose what the default scheduler should be for blk-mq, and whether that depends on the number of hardware queues.
- Properly abstract the whole get/put of a request, so we can manage the life time properly.
- Enable full merging on mq-deadline (front/back, bio-to-rq, rq-to-rq). Has full feature parity with deadline now.
- Export necessary symbols for compiling mq-deadline as a module.
- Various API adjustments for the mq schedulers.
- Various cleanups and improvements.
- Fix a lot of bugs. A lot. Upgrade!
block/Kconfig.iosched | 37 ++ block/Makefile | 3 block/blk-core.c | 9 block/blk-exec.c | 3 block/blk-flush.c | 7 block/blk-merge.c | 3 block/blk-mq-sched.c | 265 +++++++++++++++++++ block/blk-mq-sched.h | 188 +++++++++++++ block/blk-mq-tag.c | 1 block/blk-mq.c | 254 ++++++++++-------- block/blk-mq.h | 35 +- block/elevator.c | 194 ++++++++++---- block/mq-deadline.c | 647 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/nvme/host/pci.c | 1 include/linux/blk-mq.h | 4 include/linux/elevator.h | 34 ++ 16 files changed, 1495 insertions(+), 190 deletions(-)
PATCH 1/7 blk-mq: add blk_mq_start_stopped_hw_queue()
We have a variant for all hardware queues, but not one for a single hardware queue.
--- block/blk-mq.c | 18 +++++++++++------- include/linux/blk-mq.h | 1 + 2 files changed, 12 insertions(+), 7 deletions(-)
block/blk-mq.c +11 -7
@@ -1064,18 +1064,22 @@ void blk_mq_start_hw_queues(struct request_queue *q) }EXPORT_SYMBOL (blk_mq_start_hw_queues); +void blk_mq_start_stopped_hw_queue (struct blk_mq_hw_ctx *hctx,bool async) +{ +if (!blk_mq_hctx_stopped (hctx)) +return ; + +clear_bit (BLK_MQ_S_STOPPED , &hctx->state); +blk_mq_run_hw_queue (hctx, async); +} +void blk_mq_start_stopped_hw_queues (struct request_queue *q,bool async) {struct blk_mq_hw_ctx *hctx;int i; -queue_for_each_hw_ctx (q, hctx, i) { -if (!blk_mq_hctx_stopped (hctx)) -continue ; - -clear_bit (BLK_MQ_S_STOPPED , &hctx->state); -blk_mq_run_hw_queue (hctx, async); - } +queue_for_each_hw_ctx (q, hctx, i) +blk_mq_start_stopped_hw_queue (hctx, async); }EXPORT_SYMBOL (blk_mq_start_stopped_hw_queues);
include/linux/blk-mq.h +1 -0
@@ -231,6 +231,7 @@ void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx);void blk_mq_start_hw_queue (struct blk_mq_hw_ctx *hctx);void blk_mq_stop_hw_queues (struct request_queue *q);void blk_mq_start_hw_queues (struct request_queue *q); +void blk_mq_start_stopped_hw_queue (struct blk_mq_hw_ctx *hctx,bool async);void blk_mq_start_stopped_hw_queues (struct request_queue *q,bool async);void blk_mq_run_hw_queues (struct request_queue *q,bool async);void blk_mq_delay_queue (struct blk_mq_hw_ctx *hctx,unsigned long msecs);
Signature · 1 line
2.7.4
Re: [PATCH 1/7] blk-mq: add blk_mq_start_stopped_hw_queue()
Quoted 2 lines · Jens Axboe
We have a variant for all hardware queues, but not one for a single hardware queue.
PATCH 2/7 blk-mq: abstract out blk_mq_dispatch_rq_list() helper
In reply to Jens AxboeTakes a list of requests, and dispatches it. Moves any residual requests to the dispatch list.
--- block/blk-mq.c | 85 ++++++++++++++++++++++++++++++++-------------------------- block/blk-mq.h | 1 + 2 files changed, 48 insertions(+), 38 deletions(-)
block/blk-mq.c +47 -38
@@ -821,41 +821,13 @@ static inline unsigned int queued_to_index(unsigned int queued)return min (BLK_MQ_MAX_DISPATCH_ORDER -1 ,ilog2 (queued) +1 ); } -/* -* Run this hardware queue, pulling any software queues mapped to it in. -* Note that this function currently has various problems around ordering -* of IO. In particular, we'd like FIFO behaviour on handling existing -* items on the hctx->dispatch list. Ignore that for now. -*/ -static void blk_mq_process_rq_list (struct blk_mq_hw_ctx *hctx) +bool blk_mq_dispatch_rq_list (struct blk_mq_hw_ctx *hctx,struct list_head *list) {struct request_queue *q = hctx->queue;struct request *rq; -LIST_HEAD (rq_list);LIST_HEAD (driver_list);struct list_head *dptr; -int queued; - -if (unlikely (blk_mq_hctx_stopped (hctx))) -return ; - - hctx->run++; - -/* -* Touch any software queue that has pending entries. -*/ -flush_busy_ctxs (hctx, &rq_list); - -/* -* If we have previous entries on our dispatch list, grab them -* and stuff them at the front for more fair dispatch. -*/ -if (!list_empty_careful (&hctx->dispatch)) { -spin_lock (&hctx->lock); -if (!list_empty (&hctx->dispatch)) -list_splice_init (&hctx->dispatch, &rq_list); -spin_unlock (&hctx->lock); - } +int queued, ret =BLK_MQ_RQ_QUEUE_OK ;/* * Start off with dptr being NULL, so we start the first request
@@ -867,16 +839,15 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)* Now process all the entries, sending them to the driver. */ queued =0 ; -while (!list_empty (&rq_list)) { +while (!list_empty (list)) {struct blk_mq_queue_data bd; -int ret; - rq = list_first_entry(&rq_list, struct request, queuelist); + rq = list_first_entry(list, struct request, queuelist);list_del_init (&rq->queuelist); bd.rq = rq; bd.list = dptr; - bd.last =list_empty (&rq_list); + bd.last =list_empty (list); ret = q->mq_ops->queue_rq (hctx, &bd);switch (ret) {
@@ -884,7 +855,7 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx) queued++;break ;case BLK_MQ_RQ_QUEUE_BUSY : -list_add (&rq->queuelist, &rq_list); +list_add (&rq->queuelist, list);__blk_mq_requeue_request (rq);break ;default :
@@ -902,7 +873,7 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)* We've done the first request. If we have more than 1 * left in the list, set dptr to defer issue. */ -if (!dptr && rq_list.next != rq_list.prev) +if (!dptr && list->next != list->prev) dptr = &driver_list; }
@@ -912,10 +883,11 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)* Any items that need requeuing? Stuff them into hctx->dispatch, * that is where we will continue on next queue run. */ -if (!list_empty (&rq_list)) { +if (!list_empty (list)) {spin_lock (&hctx->lock); -list_splice (&rq_list, &hctx->dispatch); +list_splice (list, &hctx->dispatch);spin_unlock (&hctx->lock); +/* * the queue is expected stopped with BLK_MQ_RQ_QUEUE_BUSY, but * it's possible the queue is stopped and restarted again
@@ -927,6 +899,43 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)**/ blk_mq_run_hw_queue (hctx, true); } + +return ret !=BLK_MQ_RQ_QUEUE_BUSY ; +} + +/* +* Run this hardware queue, pulling any software queues mapped to it in. +* Note that this function currently has various problems around ordering +* of IO. In particular, we'd like FIFO behaviour on handling existing +* items on the hctx->dispatch list. Ignore that for now. +*/ +static void blk_mq_process_rq_list (struct blk_mq_hw_ctx *hctx) +{ +LIST_HEAD (rq_list); +LIST_HEAD (driver_list); + +if (unlikely (blk_mq_hctx_stopped (hctx))) +return ; + + hctx->run++; + +/* +* Touch any software queue that has pending entries. +*/ +flush_busy_ctxs (hctx, &rq_list); + +/* +* If we have previous entries on our dispatch list, grab them +* and stuff them at the front for more fair dispatch. +*/ +if (!list_empty_careful (&hctx->dispatch)) { +spin_lock (&hctx->lock); +if (!list_empty (&hctx->dispatch)) +list_splice_init (&hctx->dispatch, &rq_list); +spin_unlock (&hctx->lock); + } + +blk_mq_dispatch_rq_list (hctx, &rq_list); }static void __blk_mq_run_hw_queue (struct blk_mq_hw_ctx *hctx)
block/blk-mq.h +1 -0
@@ -31,6 +31,7 @@ void blk_mq_freeze_queue(struct request_queue *q);void blk_mq_free_queue (struct request_queue *q);int blk_mq_update_nr_requests (struct request_queue *q,unsigned int nr);void blk_mq_wake_waiters (struct request_queue *q); +bool blk_mq_dispatch_rq_list (struct blk_mq_hw_ctx *,struct list_head *);/* * CPU hotplug helpers
Signature · 1 line
2.7.4
Re: [PATCH 2/7] blk-mq: abstract out blk_mq_dispatch_rq_list() helper
Quoted 9 lines · Jens Axboe
Takes a list of requests, and dispatches it. Moves any residual requests to the dispatch list.
Signed-off-by Jens Axboe <[email protected]>--- block/blk-mq.c | 85 ++++++++++++++++++++++++++++++++-------------------------- block/blk-mq.h | 1 + 2 files changed, 48 insertions(+), 38 deletions(-)
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG N�rnberg)
Re: [PATCH 2/7] blk-mq: abstract out blk_mq_dispatch_rq_list() helper
In reply to Jens Axboeblock/blk-mq.c static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx) · line 915
Quoted 4 lines · Jens Axboe
block/blk-mq.c +4
-0+static void blk_mq_process_rq_list (struct blk_mq_hw_ctx *hctx) +{ +LIST_HEAD (rq_list); +LIST_HEAD (driver_list);
Hello Jens,
driver_list is not used in this function so please consider removing that variable from blk_mq_process_rq_list(). Otherwise this patch looks fine to me.
Bart.
Re: [PATCH 2/7] blk-mq: abstract out blk_mq_dispatch_rq_list() helper
Quoted 11 lines · Bart Van Assche
block/blk-mq.c static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx) · line 915
Quoted 4 lines · Jens Axboe
block/blk-mq.c +4
-0+static void blk_mq_process_rq_list (struct blk_mq_hw_ctx *hctx) +{ +LIST_HEAD (rq_list); +LIST_HEAD (driver_list);Hello Jens,
driver_listis not used in this function so please consider removing that variable fromblk_mq_process_rq_list(). Otherwise this patch looks fine to me.
Thanks Bart, this already got fixed up in the current branch.
Signature · 1 line
Jens Axboe
Re: [PATCH 2/7] blk-mq: abstract out blk_mq_dispatch_rq_list() helper
In reply to Jens AxboeMinor comments.
Quoted 117 lines · Jens Axboe
Takes a list of requests, and dispatches it. Moves any residual requests to the dispatch list.
Signed-off-by Jens Axboe <[email protected]>--- block/blk-mq.c | 85 ++++++++++++++++++++++++++++++++-------------------------- block/blk-mq.h | 1 + 2 files changed, 48 insertions(+), 38 deletions(-)block/blk-mq.c +14
-38@@ -821,41 +821,13 @@ static inline unsigned int queued_to_index(unsigned int queued)return min (BLK_MQ_MAX_DISPATCH_ORDER -1 ,ilog2 (queued) +1 ); } -/* -* Run this hardware queue, pulling any software queues mapped to it in. -* Note that this function currently has various problems around ordering -* of IO. In particular, we'd like FIFO behaviour on handling existing -* items on the hctx->dispatch list. Ignore that for now. -*/ -static void blk_mq_process_rq_list (struct blk_mq_hw_ctx *hctx) +bool blk_mq_dispatch_rq_list (struct blk_mq_hw_ctx *hctx,struct list_head *list) {struct request_queue *q = hctx->queue;struct request *rq; -LIST_HEAD (rq_list);LIST_HEAD (driver_list);struct list_head *dptr; -int queued; - -if (unlikely (blk_mq_hctx_stopped (hctx))) -return ; - - hctx->run++; - -/* -* Touch any software queue that has pending entries. -*/ -flush_busy_ctxs (hctx, &rq_list); - -/* -* If we have previous entries on our dispatch list, grab them -* and stuff them at the front for more fair dispatch. -*/ -if (!list_empty_careful (&hctx->dispatch)) { -spin_lock (&hctx->lock); -if (!list_empty (&hctx->dispatch)) -list_splice_init (&hctx->dispatch, &rq_list); -spin_unlock (&hctx->lock); - } +int queued, ret =BLK_MQ_RQ_QUEUE_OK ;/* * Start off with dptr being NULL, so we start the first request @@ -867,16 +839,15 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)* Now process all the entries, sending them to the driver. */ queued =0 ; -while (!list_empty (&rq_list)) { +while (!list_empty (list)) {struct blk_mq_queue_data bd; -int ret; - rq = list_first_entry(&rq_list, struct request, queuelist); + rq = list_first_entry(list, struct request, queuelist);list_del_init (&rq->queuelist); bd.rq = rq; bd.list = dptr; - bd.last =list_empty (&rq_list); + bd.last =list_empty (list); ret = q->mq_ops->queue_rq (hctx, &bd);switch (ret) {@@ -884,7 +855,7 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx) queued++;break ;case BLK_MQ_RQ_QUEUE_BUSY : -list_add (&rq->queuelist, &rq_list); +list_add (&rq->queuelist, list);__blk_mq_requeue_request (rq);break ;default :@@ -902,7 +873,7 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)* We've done the first request. If we have more than 1 * left in the list, set dptr to defer issue. */ -if (!dptr && rq_list.next != rq_list.prev) +if (!dptr && list->next != list->prev) dptr = &driver_list; }@@ -912,10 +883,11 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)* Any items that need requeuing? Stuff them into hctx->dispatch, * that is where we will continue on next queue run. */ -if (!list_empty (&rq_list)) { +if (!list_empty (list)) {spin_lock (&hctx->lock); -list_splice (&rq_list, &hctx->dispatch); +list_splice (list, &hctx->dispatch);spin_unlock (&hctx->lock); +/* * the queue is expected stopped with BLK_MQ_RQ_QUEUE_BUSY, but * it's possible the queue is stopped and restarted again @@ -927,6 +899,43 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)**/ blk_mq_run_hw_queue (hctx, true); } + +return ret !=BLK_MQ_RQ_QUEUE_BUSY ; +} +
block/blk-mq.c static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx) · line 915
Quoted 10 lines
block/blk-mq.c +10
-0+/* +* Run this hardware queue, pulling any software queues mapped to it in. +* Note that this function currently has various problems around ordering +* of IO. In particular, we'd like FIFO behaviour on handling existing +* items on the hctx->dispatch list. Ignore that for now. +*/ +static void blk_mq_process_rq_list (struct blk_mq_hw_ctx *hctx) +{ +LIST_HEAD (rq_list); +LIST_HEAD (driver_list);
driver_list is not required. since not used in this function anymore.
Quoted 8 lines
block/blk-mq.c +8
-0+ +if (unlikely (blk_mq_hctx_stopped (hctx))) +return ; + + hctx->run++; + +/* +* Touch any software queue that has pending entries.
block/blk-mq.c static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx) · line 933
Quoted 10 lines
block/blk-mq.c +10
-0+*/ +flush_busy_ctxs (hctx, &rq_list); + +/* +* If we have previous entries on our dispatch list, grab them +* and stuff them at the front for more fair dispatch. +*/ +if (!list_empty_careful (&hctx->dispatch)) { +spin_lock (&hctx->lock); +if (!list_empty (&hctx->dispatch))
list_splice_init already checks for list_empty. So this may be redundant. Please check.
Quoted 21 lines
block/blk-mq.c +5
-0+list_splice_init (&hctx->dispatch, &rq_list); +spin_unlock (&hctx->lock); + } + +blk_mq_dispatch_rq_list (hctx, &rq_list); }static void __blk_mq_run_hw_queue (struct blk_mq_hw_ctx *hctx)block/blk-mq.h +1
-0@@ -31,6 +31,7 @@ void blk_mq_freeze_queue(struct request_queue *q);void blk_mq_free_queue (struct request_queue *q);int blk_mq_update_nr_requests (struct request_queue *q,unsigned int nr);void blk_mq_wake_waiters (struct request_queue *q); +bool blk_mq_dispatch_rq_list (struct blk_mq_hw_ctx *,struct list_head *);/* * CPU hotplug helpers
Re: [PATCH 2/7] blk-mq: abstract out blk_mq_dispatch_rq_list() helper
Quoted 6 lines · Ritesh Harjani
block/blk-mq.c static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx) · line 933
Quoted 3 lines · Jens Axboe
block/blk-mq.c +3
-0+if (!list_empty_careful (&hctx->dispatch)) { +spin_lock (&hctx->lock); +if (!list_empty (&hctx->dispatch))
list_splice_initalready checks forlist_empty. So this may be redundant. Please check.
Hello Ritesh,
I think the list_empty() check is on purpose and is intended as a performance optimization.
Bart.
PATCH 3/7 elevator: make the rqhash helpers exported
In reply to Jens Axboe--- block/elevator.c | 8 ++++---- include/linux/elevator.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-)
block/elevator.c +4 -4
@@ -248,13 +248,13 @@ static inline void __elv_rqhash_del(struct request *rq) rq->rq_flags &= ~RQF_HASHED ; } -static void elv_rqhash_del (struct request_queue *q,struct request *rq) +void elv_rqhash_del (struct request_queue *q,struct request *rq) {if (ELV_ON_HASH (rq))__elv_rqhash_del (rq); } -static void elv_rqhash_add (struct request_queue *q,struct request *rq) +void elv_rqhash_add (struct request_queue *q,struct request *rq) {struct elevator_queue *e = q->elevator;
@@ -263,13 +263,13 @@ static void elv_rqhash_add(struct request_queue *q, struct request *rq) rq->rq_flags |=RQF_HASHED ; } -static void elv_rqhash_reposition (struct request_queue *q,struct request *rq) +void elv_rqhash_reposition (struct request_queue *q,struct request *rq) {__elv_rqhash_del (rq);elv_rqhash_add (q, rq); } -static struct request *elv_rqhash_find (struct request_queue *q,sector_t offset) +struct request *elv_rqhash_find (struct request_queue *q,sector_t offset) {struct elevator_queue *e = q->elevator;struct hlist_node *next;
include/linux/elevator.h +5 -0
@@ -108,6 +108,11 @@ struct elevator_type#define ELV_HASH_BITS 6 +void elv_rqhash_del (struct request_queue *q,struct request *rq); +void elv_rqhash_add (struct request_queue *q,struct request *rq); +void elv_rqhash_reposition (struct request_queue *q,struct request *rq); +struct request *elv_rqhash_find (struct request_queue *q,sector_t offset); +/* * each queue has an elevator_queue associated with it */
Signature · 1 line
2.7.4
Re: [PATCH 3/7] elevator: make the rqhash helpers exported
Quoted 6 lines · Jens Axboe
Signed-off-by Jens Axboe <[email protected]>--- block/elevator.c | 8 ++++---- include/linux/elevator.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-)
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG N�rnberg)
PATCH 4/7 blk-flush: run the queue when inserting blk-mq flush
In reply to Jens AxboeCurrently we pass in to run the queue async, but don't flag the queue to be run. We don't need to run it async here, but we should run it. So fixup the parameters.
--- block/blk-flush.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-flush.c +1 -1
@@ -426,7 +426,7 @@ void blk_insert_flush(struct request *rq)if ((policy &REQ_FSEQ_DATA ) && !(policy & (REQ_FSEQ_PREFLUSH |REQ_FSEQ_POSTFLUSH ))) {if (q->mq_ops) { -blk_mq_insert_request (rq, false, false, true); +blk_mq_insert_request (rq, false, true, false); }else list_add_tail (&rq->queuelist, &q->queue_head);return ;
Signature · 1 line
2.7.4
Re: [PATCH 4/7] blk-flush: run the queue when inserting blk-mq flush
Quoted 15 lines · Jens Axboe
Currently we pass in to run the queue async, but don't flag the queue to be run. We don't need to run it async here, but we should run it. So fixup the parameters.
Signed-off-by Jens Axboe <[email protected]>--- block/blk-flush.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/blk-flush.c +0
-0
block/blk-flush.c void blk_insert_flush(struct request *rq) · line 432
Quoted 8 lines
block/blk-flush.c +1
-1@@ -426,7 +426,7 @@ void blk_insert_flush(struct request *rq)if ((policy &REQ_FSEQ_DATA ) && !(policy & (REQ_FSEQ_PREFLUSH |REQ_FSEQ_POSTFLUSH ))) {if (q->mq_ops) { -blk_mq_insert_request (rq, false, false, true); +blk_mq_insert_request (rq, false, true, false); }else list_add_tail (&rq->queuelist, &q->queue_head);return ;
Cheers,
Hannes
Signature · 5 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG N�rnberg)
PATCH 5/7 blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens Axboe--- block/Makefile | 2 +- block/blk-core.c | 9 +- block/blk-exec.c | 3 +- block/blk-flush.c | 7 +- block/blk-merge.c | 3 + block/blk-mq-sched.c | 246 +++++++++++++++++++++++++++++++++++++++++++++++ block/blk-mq-sched.h | 187 +++++++++++++++++++++++++++++++++++ block/blk-mq-tag.c | 1 + block/blk-mq.c | 150 +++++++++++++++-------------- block/blk-mq.h | 34 +++---- block/elevator.c | 181 ++++++++++++++++++++++++++-------- include/linux/blk-mq.h | 2 +- include/linux/elevator.h | 29 +++++- 13 files changed, 713 insertions(+), 141 deletions(-) create mode 100644 block/blk-mq-sched.c create mode 100644 block/blk-mq-sched.h
block/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-tag.o blk-sysfs.o \ blk-flush.o blk-settings.o blk-ioc.o blk-map.o \ blk-exec.o blk-merge.o blk-softirq.o blk-timeout.o \ blk-lib.o blk-mq.o blk-mq-tag.o blk-stat.o \ - blk-mq-sysfs.o blk-mq-cpumap.o ioctl.o \ + blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \ genhd.o scsi_ioctl.o partition-generic.o ioprio.o \ badblocks.o partitions/
block/blk-core.c +6 -3
@@ -39,6 +39,7 @@#include "blk.h" #include "blk-mq.h" +#include "blk-mq-sched.h" #include "blk-wbt.h" EXPORT_TRACEPOINT_SYMBOL_GPL (block_bio_remap);
@@ -1428,7 +1429,7 @@ void __blk_put_request(struct request_queue *q, struct request *req)return ;if (q->mq_ops) { -blk_mq_free_request (req); +blk_mq_sched_put_request (req);return ; }
@@ -1464,7 +1465,7 @@ void blk_put_request(struct request *req)struct request_queue *q = req->q;if (q->mq_ops) -blk_mq_free_request (req); +blk_mq_sched_put_request (req);else {unsigned long flags;
@@ -1528,6 +1529,7 @@ bool bio_attempt_back_merge(struct request_queue *q, struct request *req,blk_account_io_start (req, false);return true; } +EXPORT_SYMBOL_GPL (bio_attempt_back_merge);bool bio_attempt_front_merge (struct request_queue *q,struct request *req,struct bio *bio)
@@ -1552,6 +1554,7 @@ bool bio_attempt_front_merge(struct request_queue *q, struct request *req,blk_account_io_start (req, false);return true; } +EXPORT_SYMBOL_GPL (bio_attempt_front_merge);/** * blk_attempt_plug_merge - try to merge with %current's plugged list
@@ -2173,7 +2176,7 @@ int blk_insert_cloned_request(struct request_queue *q, struct request *rq)if (q->mq_ops) {if (blk_queue_io_stat (q))blk_account_io_start (rq, true); -blk_mq_insert_request (rq, false, true, false); +blk_mq_sched_insert_request (rq, false, true, false);return 0 ; }
block/blk-exec.c +2 -1
@@ -9,6 +9,7 @@#include <linux/sched/sysctl.h> #include "blk.h" +#include "blk-mq-sched.h" /* * for max sense size
@@ -65,7 +66,7 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,* be reused after dying flag is set */ if (q->mq_ops) { -blk_mq_insert_request (rq, at_head, true, false); +blk_mq_sched_insert_request (rq, at_head, true, false);return ; }
block/blk-flush.c +4 -3
@@ -74,6 +74,7 @@#include "blk.h" #include "blk-mq.h" #include "blk-mq-tag.h" +#include "blk-mq-sched.h" /* FLUSH/FUA sequences */ enum {
@@ -425,9 +426,9 @@ void blk_insert_flush(struct request *rq)*/ if ((policy &REQ_FSEQ_DATA ) && !(policy & (REQ_FSEQ_PREFLUSH |REQ_FSEQ_POSTFLUSH ))) { -if (q->mq_ops) { -blk_mq_insert_request (rq, false, true, false); - }else +if (q->mq_ops) +blk_mq_sched_insert_request (rq, false, true, false); +else list_add_tail (&rq->queuelist, &q->queue_head);return ; }
block/blk-merge.c +3 -0
@@ -766,6 +766,7 @@ int attempt_back_merge(struct request_queue *q, struct request *rq)return 0 ; } +EXPORT_SYMBOL_GPL (attempt_back_merge);int attempt_front_merge (struct request_queue *q,struct request *rq) {
@@ -776,6 +777,7 @@ int attempt_front_merge(struct request_queue *q, struct request *rq)return 0 ; } +EXPORT_SYMBOL_GPL (attempt_front_merge);int blk_attempt_req_merge (struct request_queue *q,struct request *rq,struct request *next)
@@ -825,3 +827,4 @@ int blk_try_merge(struct request *rq, struct bio *bio)return ELEVATOR_FRONT_MERGE ;return ELEVATOR_NO_MERGE ; } +EXPORT_SYMBOL_GPL (blk_try_merge);
block/blk-mq-sched.c new file +246 -0
246 lines not on this page · raw message
block/blk-mq-sched.h new file +187 -0
187 lines not on this page · raw message
block/blk-mq-tag.c +1 -0
@@ -12,6 +12,7 @@#include "blk.h" #include "blk-mq.h" #include "blk-mq-tag.h" +#include "blk-mq-sched.h" bool blk_mq_has_free_tags (struct blk_mq_tags *tags) {
block/blk-mq.c +78 -72
349 lines not on this page · raw message
block/blk-mq.h +14 -20
@@ -84,26 +84,6 @@ static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)put_cpu (); } -struct blk_mq_alloc_data { -/* input parameter */ -struct request_queue *q; -unsigned int flags; - -/* input & output parameter */ -struct blk_mq_ctx *ctx; -struct blk_mq_hw_ctx *hctx; -}; - -static inline void blk_mq_set_alloc_data (struct blk_mq_alloc_data *data, -struct request_queue *q,unsigned int flags, -struct blk_mq_ctx *ctx,struct blk_mq_hw_ctx *hctx) -{ - data->q = q; - data->flags = flags; - data->ctx = ctx; - data->hctx = hctx; -} -static inline bool blk_mq_hctx_stopped (struct blk_mq_hw_ctx *hctx) {return test_bit (BLK_MQ_S_STOPPED , &hctx->state);
@@ -114,4 +94,18 @@ static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx) return hctx->nr_ctx && hctx->tags; } +void blk_mq_free_rq_map (struct blk_mq_tag_set *set,struct blk_mq_tags *tags, +unsigned int hctx_idx); +struct blk_mq_tags *blk_mq_init_rq_map (struct blk_mq_tag_set *set, +unsigned int hctx_idx); +void blk_mq_rq_ctx_init (struct request_queue *q,struct blk_mq_ctx *ctx, +struct request *rq,unsigned int op); +void __blk_mq_free_request (struct blk_mq_hw_ctx *hctx,struct blk_mq_ctx *ctx, +struct request *rq); +struct request *__blk_mq_alloc_request (struct blk_mq_alloc_data *data, +unsigned int op); +void __blk_mq_insert_request (struct blk_mq_hw_ctx *hctx,struct request *rq, +bool at_head); +void blk_mq_process_sw_list (struct blk_mq_hw_ctx *hctx); +#endif
block/elevator.c +142 -39
380 lines not on this page · raw message
include/linux/blk-mq.h +1 -1
@@ -22,6 +22,7 @@ struct blk_mq_hw_ctx {unsigned long flags;/* BLK_MQ_F_* flags */ +void *sched_data;struct request_queue *queue;struct blk_flush_queue *fq;
@@ -179,7 +180,6 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set);void blk_mq_flush_plug_list (struct blk_plug *plug,bool from_schedule); -void blk_mq_insert_request (struct request *,bool ,bool ,bool );void blk_mq_free_request (struct request *rq);void blk_mq_free_hctx_request (struct blk_mq_hw_ctx *,struct request *rq);bool blk_mq_can_queue (struct blk_mq_hw_ctx *);
include/linux/elevator.h +28 -1
@@ -77,6 +77,28 @@ struct elevator_opselevator_registered_fn *elevator_registered_fn; }; +struct blk_mq_alloc_data ; +struct blk_mq_hw_ctx ; + +struct elevator_mq_ops { +int (*init_sched)(struct request_queue *,struct elevator_type *); +void (*exit_sched)(struct elevator_queue *); + +bool (*allow_merge)(struct request_queue *,struct request *,struct bio *); +bool (*bio_merge)(struct blk_mq_hw_ctx *,struct bio *); +void (*requests_merged)(struct request_queue *,struct request *,struct request *); +struct request *(*get_request)(struct request_queue *,unsigned int ,struct blk_mq_alloc_data *); +void (*put_request)(struct request *); +void (*insert_request)(struct blk_mq_hw_ctx *,struct request *,bool ); +struct request *(*dispatch_request)(struct blk_mq_hw_ctx *); +bool (*has_work)(struct blk_mq_hw_ctx *); +void (*completed_request)(struct blk_mq_hw_ctx *,struct request *); +void (*started_request)(struct request *); +void (*requeue_request)(struct request *); +struct request *(*former_request)(struct request_queue *,struct request *); +struct request *(*next_request)(struct request_queue *,struct request *); +}; +#define ELV_NAME_MAX (16)struct elv_fs_entry {
@@ -94,12 +116,16 @@ struct elevator_typestruct kmem_cache *icq_cache;/* fields provided by elevator implementation */ -struct elevator_ops ops; +union { +struct elevator_ops ops; +struct elevator_mq_ops mq_ops; + };size_t icq_size;/* see iocontext.h */ size_t icq_align;/* ditto */ struct elv_fs_entry *elevator_attrs;char elevator_name[ELV_NAME_MAX ];struct module *elevator_owner; +bool uses_mq;/* managed by elevator core */ char icq_cache_name[ELV_NAME_MAX +5 ];/* elvname + "_io_cq" */
@@ -123,6 +149,7 @@ struct elevator_queuestruct kobject kobj;struct mutex sysfs_lock; unsigned int registered:1; + unsigned int uses_mq:1;DECLARE_HASHTABLE (hash,ELV_HASH_BITS ); };
Signature · 1 line
2.7.4
Re: [PATCH 5/7] blk-mq-sched: add framework for MQ capable IO schedulers
block/blk-mq-sched.c line 16
Quoted 6 lines · Jens Axboe
block/blk-mq-sched.c new file +6
-0+/* +* Empty set +*/ +static struct blk_mq_ops mq_sched_tag_ops = { + .queue_rq =NULL , +};
Hello Jens,
Would "static struct blk_mq_ops mq_sched_tag_ops;" have been sufficient? Can this data structure be declared 'const' if the blk_mq_ops pointers in struct blk_mq_tag_set and struct request_queue are also declared const?
block/blk-mq-sched.c line 79
Quoted 5 lines
block/blk-mq-sched.c new file +5
-0+struct request *blk_mq_sched_alloc_shadow_request (struct request_queue *q, +struct blk_mq_alloc_data *data, +struct blk_mq_tags *tags, +atomic_t *wait_index) +{
Using the word "shadow" in the function name suggests to me that there is a shadow request for every request and a request for every shadow request. However, my understanding from the code is that there can be requests without shadow requests (for e.g. a flush) and shadow requests without requests. Shouldn't the name of this function reflect that, e.g. by using "sched" or "elv" in the function name instead of "shadow"?
block/blk-mq-sched.c line 189
Quoted 3 lines
block/blk-mq-sched.c new file +3
-0+struct request * +blk_mq_sched_request_from_shadow (struct blk_mq_hw_ctx *hctx, +struct request *(*get_sched_rq)(struct blk_mq_hw_ctx *))
This function dequeues a request from the I/O scheduler queue, allocates a request, copies the relevant request structure members into that request and makes the request refer to the shadow request. Isn't the request dispatching more important than associating the request with the shadow request? If so, how about making the function name reflect that?
Quoted 14 lines
block/blk-mq-sched.c new file +14
-0+{ +struct blk_mq_alloc_data data; +struct request *sched_rq, *rq; + + data.q = hctx->queue; + data.flags =BLK_MQ_REQ_NOWAIT ; + data.ctx =blk_mq_get_ctx (hctx->queue); + data.hctx = hctx; + + rq =__blk_mq_alloc_request (&data,0 ); +blk_mq_put_ctx (data.ctx); + +if (!rq) { +blk_mq_stop_hw_queue (hctx);
block/blk-mq-sched.c line 213
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+return NULL ; + } + + sched_rq =get_sched_rq (hctx); + +if (!sched_rq) { +blk_queue_enter_live (hctx->queue); +__blk_mq_free_request (hctx, data.ctx, rq); +return NULL ; + }
The mq deadline scheduler calls this function with get_sched_rq == __dd_dispatch_request. If __blk_mq_alloc_request() fails, shouldn't the request that was removed from the scheduler queue be pushed back onto that queue? Additionally, are you sure it's necessary to call blk_queue_enter_live() from the error path?
Bart.
Re: [PATCH 5/7] blk-mq-sched: add framework for MQ capable IO schedulers
Quoted 10 lines · Bart Van Assche
block/blk-mq-sched.c line 16
Quoted 6 lines · Jens Axboe
block/blk-mq-sched.c new file +6
-0+/* +* Empty set +*/ +static struct blk_mq_ops mq_sched_tag_ops = { + .queue_rq =NULL , +};Hello Jens,
Quoted 3 lines
Would "static struct
blk_mq_opsmq_sched_tag_ops;" have been sufficient? Can this data structure be declared 'const' if theblk_mq_opspointers in structblk_mq_tag_setand structrequest_queueare also declared const?
Yes, the static should be enough to ensure that it's all zeroes. I did have this as const, but then realized I'd have to change a few other places too. I'll make that change, hopefully it'll just work out.
Quoted 4 lines
Quoted 4 lines
block/blk-mq-sched.c new file +4
-0+struct request *blk_mq_sched_alloc_shadow_request (struct request_queue *q, +struct blk_mq_alloc_data *data, +struct blk_mq_tags *tags, +atomic_t *wait_index)
Quoted 8 lines
Quoted 1 line
+{
Using the word "shadow" in the function name suggests to me that there is a shadow request for every request and a request for every shadow request. However, my understanding from the code is that there can be requests without shadow requests (for e.g. a flush) and shadow requests without requests. Shouldn't the name of this function reflect that, e.g. by using "sched" or "elv" in the function name instead of "shadow"?
Shadow might not be the best name. Most do have shadows though, it's only the rare exception like the flush, that you mention. I'll see if I can come up with a better name.
Quoted 9 lines
block/blk-mq-sched.c line 189
Quoted 3 lines
block/blk-mq-sched.c new file +3
-0+struct request * +blk_mq_sched_request_from_shadow (struct blk_mq_hw_ctx *hctx, +struct request *(*get_sched_rq)(struct blk_mq_hw_ctx *))This function dequeues a request from the I/O scheduler queue, allocates a request, copies the relevant request structure members into that request and makes the request refer to the shadow request. Isn't the request dispatching more important than associating the request with the shadow request? If so, how about making the function name reflect that?
Sure, I can update the naming. Will need to anyway, if we get rid of the shadow naming.
Quoted 22 lines
Quoted 22 lines
block/blk-mq-sched.c new file +22
-0+{ +struct blk_mq_alloc_data data; +struct request *sched_rq, *rq; + + data.q = hctx->queue; + data.flags =BLK_MQ_REQ_NOWAIT ; + data.ctx =blk_mq_get_ctx (hctx->queue); + data.hctx = hctx; + + rq =__blk_mq_alloc_request (&data,0 ); +blk_mq_put_ctx (data.ctx); + +if (!rq) { +blk_mq_stop_hw_queue (hctx); +return NULL ; + } + + sched_rq =get_sched_rq (hctx); + +if (!sched_rq) { +blk_queue_enter_live (hctx->queue); +__blk_mq_free_request (hctx, data.ctx, rq);
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return NULL; + }The mq deadline scheduler calls this function with
get_sched_rq==__dd_dispatch_request. If__blk_mq_alloc_request()fails, shouldn't the request that was removed from the scheduler queue be pushed back onto that queue? Additionally, are you sure it's necessary to callblk_queue_enter_live()from the error path?
If __blk_mq_alloc_request() fails, we haven't pulled a request from the scheduler yet. The extra ref is needed because __blk_mq_alloc_request() doesn't get a ref on the request, however __blk_mq_free_request() does put one.
Signature · 1 line
Jens Axboe
Re: [PATCH 5/7] blk-mq-sched: add framework for MQ capable IO schedulers
Quoted 15 lines · Jens Axboe
Quoted 13 lines · Bart Van Assche
block/blk-mq-sched.c line 79
Quoted 5 lines · Jens Axboe
block/blk-mq-sched.c new file +5
-0+struct request *blk_mq_sched_alloc_shadow_request (struct request_queue *q, +struct blk_mq_alloc_data *data, +struct blk_mq_tags *tags, +atomic_t *wait_index) +{Using the word "shadow" in the function name suggests to me that there is a shadow request for every request and a request for every shadow request. However, my understanding from the code is that there can be requests without shadow requests (for e.g. a flush) and shadow requests without requests. Shouldn't the name of this function reflect that, e.g. by using "sched" or "elv" in the function name instead of "shadow"?
Quoted 3 lines
Shadow might not be the best name. Most do have shadows though, it's only the rare exception like the flush, that you mention. I'll see if I can come up with a better name.
Hello Jens,
One aspect of this patch series that might turn out to be a maintenance burden is the copying between original and shadow requests. It is easy to overlook that rq_copy() has to be updated if a field would ever be added to struct request. Additionally, having to allocate two requests structures per I/O instead of one will have a runtime overhead. Do you think the following approach would work?
- Instead of using two request structures per I/O, only use a single request structure.
- Instead of storing one tag in the request structure, store two tags in that structure. One tag comes from the I/O scheduler tag set (size: nr_requests) and the other from the tag set associated with the block driver (size: HBA queue depth).
- Only add a request to the hctx dispatch list after a block driver tag has been assigned. This means that an I/O scheduler must keep a request structure on a list it manages itself as long as no block driver tag has been assigned.
- sysfs_list_show() is modified such that it shows both tags.
Thanks,
Bart.
Re: [PATCH 5/7] blk-mq-sched: add framework for MQ capable IO schedulers
Quoted 31 lines · Bart Van Assche
Quoted 15 lines · Jens Axboe
Quoted 13 lines · Bart Van Assche
block/blk-mq-sched.c line 79
Quoted 5 lines · Jens Axboe
block/blk-mq-sched.c new file +5
-0+struct request *blk_mq_sched_alloc_shadow_request (struct request_queue *q, +struct blk_mq_alloc_data *data, +struct blk_mq_tags *tags, +atomic_t *wait_index) +{Using the word "shadow" in the function name suggests to me that there is a shadow request for every request and a request for every shadow request. However, my understanding from the code is that there can be requests without shadow requests (for e.g. a flush) and shadow requests without requests. Shouldn't the name of this function reflect that, e.g. by using "sched" or "elv" in the function name instead of "shadow"?
Quoted 3 lines
Shadow might not be the best name. Most do have shadows though, it's only the rare exception like the flush, that you mention. I'll see if I can come up with a better name.
Hello Jens,
One aspect of this patch series that might turn out to be a maintenance burden is the copying between original and shadow requests. It is easy to overlook that
rq_copy()has to be updated if a field would ever be added to struct request. Additionally, having to allocate two requests structures per I/O instead of one will have a runtime overhead. Do you think the following approach would work?
- Instead of using two request structures per I/O, only use a single request structure.
- Instead of storing one tag in the request structure, store two tags
Quoted 8 lines
in that structure. One tag comes from the I/O scheduler tag set (size:
nr_requests) and the other from the tag set associated with the block driver (size: HBA queue depth).
- Only add a request to the hctx dispatch list after a block driver tag has been assigned. This means that an I/O scheduler must keep a request structure on a list it manages itself as long as no block driver tag has been assigned.
-sysfs_list_show()is modified such that it shows both tags.
I have considered doing exactly that, decided to go down the other path. I may still revisit, it's not that I'm a huge fan of the shadow requests and the necessary copying. We don't update the request that often, so I don't think it's going to be a big maintenance burden. But it'd be hard to claim that it's super pretty...
I'll play with the idea.
Signature · 1 line
Jens Axboe
Re: [PATCH 5/7] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens Axboeblock/blk-mq-sched.h line 77
Quoted 10 lines · Jens Axboe
block/blk-mq-sched.h new file +10
-0+static inline void blk_mq_sched_put_request (struct request *rq) +{ +struct request_queue *q = rq->q; +struct elevator_queue *e = q->elevator; + +if (e && e->type->mq_ops.put_request) + e->type->mq_ops.put_request (rq); +else +blk_mq_free_request (rq); +}
blk_mq_free_request() always triggers a call of blk_queue_exit(). dd_put_request() only triggers a call of blk_queue_exit() if it is not a shadow request. Is that on purpose?
Quoted 16 lines
block/blk-mq-sched.h new file +16
-0+static inline struct request * +blk_mq_sched_get_request (struct request_queue *q,unsigned int op, +struct blk_mq_alloc_data *data) +{ +struct elevator_queue *e = q->elevator; +struct blk_mq_hw_ctx *hctx; +struct blk_mq_ctx *ctx; +struct request *rq; + +blk_queue_enter_live (q); + ctx =blk_mq_get_ctx (q); + hctx =blk_mq_map_queue (q, ctx->cpu); + +blk_mq_set_alloc_data (data, q,0 , ctx, hctx); + +if (e && e->type->mq_ops.get_request)
block/blk-mq-sched.h line 104
Quoted 10 lines
block/blk-mq-sched.h new file +10
-0+ rq = e->type->mq_ops.get_request (q, op, data); + else + rq =__blk_mq_alloc_request (data, op); + +if (rq) + data->hctx->queued++; + +return rq; + +}
Some but not all callers of blk_mq_sched_get_request() call blk_queue_exit() if this function returns NULL. Please consider to move the blk_queue_exit() call from the blk_mq_alloc_request() error path into this function. I think that will make it a lot easier to verify whether or not the blk_queue_enter() / blk_queue_exit() calls are balanced properly.
Additionally, since blk_queue_enter() / blk_queue_exit() calls by blk_mq_sched_get_request() and blk_mq_sched_put_request() must be balanced and since the latter function only calls blk_queue_exit() for non-shadow requests, shouldn't blk_mq_sched_get_request() call blk_queue_enter_live() only if __blk_mq_alloc_request() is called?
Thanks,
Bart.
Re: [PATCH 5/7] blk-mq-sched: add framework for MQ capable IO schedulers
Quoted 15 lines · Bart Van Assche
block/blk-mq-sched.h line 77
Quoted 10 lines · Jens Axboe
block/blk-mq-sched.h new file +10
-0+static inline void blk_mq_sched_put_request (struct request *rq) +{ +struct request_queue *q = rq->q; +struct elevator_queue *e = q->elevator; + +if (e && e->type->mq_ops.put_request) + e->type->mq_ops.put_request (rq); +else +blk_mq_free_request (rq); +}
blk_mq_free_request()always triggers a call ofblk_queue_exit().dd_put_request()only triggers a call ofblk_queue_exit()if it is not a shadow request. Is that on purpose?
If the scheduler doesn't define get/put requests, then the lifetime follows the normal setup. If we do define them, then dd_put_request() only wants to put the request if it's one where we did setup a shadow.
Quoted 24 lines
Quoted 24 lines
block/blk-mq-sched.h new file +24
-0+static inline struct request * +blk_mq_sched_get_request (struct request_queue *q,unsigned int op, +struct blk_mq_alloc_data *data) +{ +struct elevator_queue *e = q->elevator; +struct blk_mq_hw_ctx *hctx; +struct blk_mq_ctx *ctx; +struct request *rq; + +blk_queue_enter_live (q); + ctx =blk_mq_get_ctx (q); + hctx =blk_mq_map_queue (q, ctx->cpu); + +blk_mq_set_alloc_data (data, q,0 , ctx, hctx); + +if (e && e->type->mq_ops.get_request) + rq = e->type->mq_ops.get_request (q, op, data); +else + rq =__blk_mq_alloc_request (data, op); + +if (rq) + data->hctx->queued++; + +return rq;
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ +}Some but not all callers of
blk_mq_sched_get_request()callblk_queue_exit()if this function returns NULL. Please consider to move theblk_queue_exit()call from theblk_mq_alloc_request()error path into this function. I think that will make it a lot easier to verify whether or not theblk_queue_enter()/blk_queue_exit()calls are balanced properly.
Agree, I'll make the change, it'll be easier to read then.
Quoted 5 lines
Additionally, since
blk_queue_enter()/blk_queue_exit()calls byblk_mq_sched_get_request()andblk_mq_sched_put_request()must be balanced and since the latter function only callsblk_queue_exit()for non-shadow requests, shouldn'tblk_mq_sched_get_request()callblk_queue_enter_live()only if__blk_mq_alloc_request()is called?
I'll double check that part, there might be a bug or at least a chance to clean this up a bit. I did verify most of this at some point, and tested it with the scheduler switching. That part falls apart pretty quickly, if the references aren't matched exactly.
Signature · 1 line
Jens Axboe
PATCH 6/7 mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens Axboe--- block/Kconfig.iosched | 6 + block/Makefile | 1 + block/mq-deadline.c | 647 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 654 insertions(+) create mode 100644 block/mq-deadline.c
block/Kconfig.iosched +6 -0
@@ -32,6 +32,12 @@ config IOSCHED_CFQ This is the default I/O scheduler. +config MQ_IOSCHED_DEADLINE + tristate "MQ deadline I/O scheduler" + default y + ---help--- + MQ version of the deadline IO scheduler. + config CFQ_GROUP_IOSCHED bool "CFQ Group Scheduling support" depends on IOSCHED_CFQ && BLK_CGROUP
block/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_BLK_DEV_THROTTLING) += blk-throttle.o obj-$(CONFIG_IOSCHED_NOOP) += noop-iosched.o obj-$(CONFIG_IOSCHED_DEADLINE) += deadline-iosched.o obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o +obj-$(CONFIG_MQ_IOSCHED_DEADLINE) += mq-deadline.o obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o obj-$(CONFIG_BLK_CMDLINE_PARSER) += cmdline-parser.o
block/mq-deadline.c new file +647 -0
647 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH 6/7] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 12 lines · Jens Axboe
block/mq-deadline.c new file +12
-0+static int dd_init_queue (struct request_queue *q,struct elevator_type *e) +{ +struct deadline_data *dd; +struct elevator_queue *eq; + + eq =elevator_alloc (q, e); +if (!eq) +return -ENOMEM ; + + dd =kzalloc_node (sizeof (*dd),GFP_KERNEL , q->node); +if (!dd) { +kobject_put (&eq->kobj);
block/mq-deadline.c line 322
Quoted 10 lines
block/mq-deadline.c new file +10
-0+return -ENOMEM ; + } + eq->elevator_data = dd; + + dd->tags =blk_mq_sched_alloc_requests (256 , q->node); +if (!dd->tags) { +kfree (dd); +kobject_put (&eq->kobj); +return -ENOMEM ; + }
Hello Jens,
Please add a comment that explains where the number 256 comes from.
Thanks,
Bart.
Re: [PATCH 6/7] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 26 lines · Bart Van Assche
Quoted 12 lines · Jens Axboe
block/mq-deadline.c new file +12
-0+static int dd_init_queue (struct request_queue *q,struct elevator_type *e) +{ +struct deadline_data *dd; +struct elevator_queue *eq; + + eq =elevator_alloc (q, e); +if (!eq) +return -ENOMEM ; + + dd =kzalloc_node (sizeof (*dd),GFP_KERNEL , q->node); +if (!dd) { +kobject_put (&eq->kobj);block/mq-deadline.c line 322
Quoted 10 lines
block/mq-deadline.c new file +10
-0+return -ENOMEM ; + } + eq->elevator_data = dd; + + dd->tags =blk_mq_sched_alloc_requests (256 , q->node); +if (!dd->tags) { +kfree (dd); +kobject_put (&eq->kobj); +return -ENOMEM ; + }Hello Jens,
Quoted 1 line
Please add a comment that explains where the number 256 comes from.
Pulled out of my... I'll add a comment! Really this should just be ->nr_requests soft setting, the 256 is just a random sane default that I chose for now. I had forgotten about that, thanks.
Signature · 1 line
Jens Axboe
Re: [PATCH 6/7] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens Axboeblock/mq-deadline.c line 28
Quoted 4 lines · Jens Axboe
block/mq-deadline.c new file +4
-0+static inline bool dd_rq_is_shadow (struct request *rq) +{ +return rq->rq_flags &RQF_ALLOCED ; +}
Hello Jens,
Something minor: because req_flags_t has been defined using __bitwise (typedef __u32 __bitwise req_flags_t) sparse complains for the above function about converting req_flags_t into bool. How about changing the body of that function into "return (rq->rq_flags & RQF_ALLOCED) != 0" to keep sparse happy?
Bart.
Re: [PATCH 6/7] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 8 lines · Bart Van Assche
block/mq-deadline.c line 28
Quoted 4 lines · Jens Axboe
block/mq-deadline.c new file +4
-0+static inline bool dd_rq_is_shadow (struct request *rq) +{ +return rq->rq_flags &RQF_ALLOCED ; +}Hello Jens,
Quoted 5 lines
Something minor: because
req_flags_thas been defined using__bitwise(typedef__u32__bitwisereq_flags_t) sparse complains for the above function about convertingreq_flags_tinto bool. How about changing the body of that function into "return (rq->rq_flags&RQF_ALLOCED) != 0" to keep sparse happy?
Sure, I can fold in that change.
Signature · 1 line
Jens Axboe
PATCH 7/7 blk-mq-sched: allow setting of default IO scheduler
In reply to Jens Axboe--- block/Kconfig.iosched | 43 +++++++++++++++++++++++++++++++++++++------ block/blk-mq-sched.c | 19 +++++++++++++++++++ block/blk-mq-sched.h | 1 + block/blk-mq.c | 3 +++ block/elevator.c | 5 ++++- drivers/nvme/host/pci.c | 1 + include/linux/blk-mq.h | 1 + 7 files changed, 66 insertions(+), 7 deletions(-)
block/Kconfig.iosched +37 -6
@@ -32,12 +32,6 @@ config IOSCHED_CFQ This is the default I/O scheduler. -config MQ_IOSCHED_DEADLINE - tristate "MQ deadline I/O scheduler" - default y - ---help--- - MQ version of the deadline IO scheduler. - config CFQ_GROUP_IOSCHED bool "CFQ Group Scheduling support" depends on IOSCHED_CFQ && BLK_CGROUP
@@ -69,6 +63,43 @@ config DEFAULT_IOSCHED default "cfq" if DEFAULT_CFQ default "noop" if DEFAULT_NOOP +config MQ_IOSCHED_DEADLINE + tristate "MQ deadline I/O scheduler" + default y + ---help--- + MQ version of the deadline IO scheduler. + +config MQ_IOSCHED_NONE + bool + default y + +choice + prompt "Default MQ I/O scheduler" + default MQ_IOSCHED_NONE + help + Select the I/O scheduler which will be used by default for all + blk-mq managed block devices. + + config DEFAULT_MQ_DEADLINE + bool "MQ Deadline" if MQ_IOSCHED_DEADLINE=y + + config DEFAULT_MQ_NONE + bool "None" + +endchoice + +config DEFAULT_MQ_IOSCHED + string + default "mq-deadline" if DEFAULT_MQ_DEADLINE + default "none" if DEFAULT_MQ_NONE + endmenu +config MQ_IOSCHED_ONLY_SQ + bool "Enable blk-mq IO scheduler only for single queue devices" + default y + help + Say Y here, if you only want to enable IO scheduling on block + devices that have a single queue registered. + endif
block/blk-mq-sched.c +19 -0
@@ -244,3 +244,22 @@ void __blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)blk_mq_dispatch_rq_list (hctx, &rq_list); } + +int blk_mq_sched_init (struct request_queue *q) +{ +int ret; + +#if defined(CONFIG_DEFAULT_MQ_NONE ) +return 0 ; +#endif +#if defined(CONFIG_MQ_IOSCHED_ONLY_SQ ) +if (q->nr_hw_queues >1 ) +return 0 ; +#endif + +mutex_lock (&q->sysfs_lock); + ret =elevator_init (q,NULL ); +mutex_unlock (&q->sysfs_lock); + +return ret; +}
block/blk-mq-sched.h +1 -0
@@ -25,6 +25,7 @@ struct request * blk_mq_sched_request_from_shadow(struct blk_mq_hw_ctx *hctx, struct request *(*get_sched_rq)(struct blk_mq_hw_ctx *)); +int blk_mq_sched_init (struct request_queue *q);struct blk_mq_alloc_data {/* input parameter */
block/blk-mq.c +3 -0
@@ -2141,6 +2141,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,INIT_LIST_HEAD (&q->requeue_list);spin_lock_init (&q->requeue_lock); +if (!(set->flags &BLK_MQ_F_NO_SCHED )) +blk_mq_sched_init (q); +if (q->nr_hw_queues >1 )blk_queue_make_request (q, blk_mq_make_request);else
block/elevator.c +4 -1
@@ -219,7 +219,10 @@ int elevator_init(struct request_queue *q, char *name) }if (!e) { - e =elevator_get (CONFIG_DEFAULT_IOSCHED , false); +if (q->mq_ops) + e =elevator_get (CONFIG_DEFAULT_MQ_IOSCHED , false); +else + e =elevator_get (CONFIG_DEFAULT_IOSCHED , false);if (!e) {printk (KERN_ERR "Default I/O scheduler not found. " \
drivers/nvme/host/pci.c +1 -0
@@ -1186,6 +1186,7 @@ static int nvme_alloc_admin_tags(struct nvme_dev *dev) dev->admin_tagset.timeout =ADMIN_TIMEOUT ; dev->admin_tagset.numa_node =dev_to_node (dev->dev); dev->admin_tagset.cmd_size =nvme_cmd_size (dev); + dev->admin_tagset.flags =BLK_MQ_F_NO_SCHED ; dev->admin_tagset.driver_data = dev;if (blk_mq_alloc_tag_set (&dev->admin_tagset))
include/linux/blk-mq.h +1 -0
@@ -152,6 +152,7 @@ enum {BLK_MQ_F_SG_MERGE =1 <<2 ,BLK_MQ_F_DEFER_ISSUE =1 <<4 ,BLK_MQ_F_BLOCKING =1 <<5 , +BLK_MQ_F_NO_SCHED =1 <<6 ,BLK_MQ_F_ALLOC_POLICY_START_BIT =8 , BLK_MQ_F_ALLOC_POLICY_BITS = 1,
Signature · 1 line
2.7.4
Re: [PATCH 7/7] blk-mq-sched: allow setting of default IO scheduler
Quoted 5 lines · Jens Axboe
block/Kconfig.iosched +5
-0+config DEFAULT_MQ_IOSCHED + string + default "mq-deadline" if DEFAULT_MQ_DEADLINE + default "none" if DEFAULT_MQ_NONE +
block/Kconfig.iosched config DEFAULT_IOSCHED · line 105
Quoted 10 lines
block/Kconfig.iosched +7
-0endmenu +config MQ_IOSCHED_ONLY_SQ + bool "Enable blk-mq IO scheduler only for single queue devices" + default y + help + Say Y here, if you only want to enable IO scheduling on block + devices that have a single queue registered. + endif
Hello Jens,
Shouln't the MQ_IOSCHED_ONLY_SQ entry be placed before "endmenu" such that it is displayed in the I/O scheduler menu instead of the block menu?
Bart.
Re: [PATCH 7/7] blk-mq-sched: allow setting of default IO scheduler
Quoted 19 lines · Bart Van Assche
Quoted 5 lines · Jens Axboe
block/Kconfig.iosched +5
-0+config DEFAULT_MQ_IOSCHED + string + default "mq-deadline" if DEFAULT_MQ_DEADLINE + default "none" if DEFAULT_MQ_NONE +block/Kconfig.iosched config DEFAULT_IOSCHED · line 105
Quoted 10 lines
block/Kconfig.iosched +7
-0endmenu +config MQ_IOSCHED_ONLY_SQ + bool "Enable blk-mq IO scheduler only for single queue devices" + default y + help + Say Y here, if you only want to enable IO scheduling on block + devices that have a single queue registered. + endifHello Jens,
Quoted 2 lines
Shouln't the
MQ_IOSCHED_ONLY_SQentry be placed before "endmenu" such that it is displayed in the I/O scheduler menu instead of the block menu?
Good catch, yes it should. I'll move it.
Signature · 1 line
Jens Axboe
Quoted 2 lines
Il giorno 08 dic 2016, alle ore 21:13, Jens Axboe <[email protected]> ha =
scritto:
Quoted 10 lines
=20
As a followup to this posting from yesterday:
=20
https://marc.info/?l=3Dlinux-block&m=3D148115232806065&w=3D2
=20
this is version 2. I wanted to post a new one fairly quickly, as there ended up being a number of potential crashes in v1. This one should be solid, I've run mq-deadline on both NVMe and regular rotating storage, and we handle the various merging cases correctly.
=20
Quoted 8 lines
You can download it from git as well:
=20git://git.kernel.dk/linux-blockblk-mq-sched.2
=20
Note that this is based on for-4.10/block, which is in turn based on v4.9-rc1. I suggest pulling it into my for-next branch, which would then merge nicely with 'master' as well.
=20
Hi Jens,
this is just to tell you that I have finished running some extensive tests on this patch series (throughput, responsiveness, low latency for soft real time). No regression w.r.t. blk detected, and no crashes or other anomalies.
Starting to work on BFQ port. Please be patient with my little expertise on mq environment, and with my next silly questions!
Thanks,
Paolo
Quoted 10 lines
Changes since v1:
=20
- AddKconfigentries to allow the user to choose what the default scheduler should be for blk-mq, and whether that depends on the number of hardware queues.
=20
- Properly abstract the whole get/put of a request, so we can manage the life time properly.
=20
- Enable full merging on mq-deadline (front/back, bio-to-rq, =
rq-to-rq).
Quoted 10 lines
Has full feature parity with deadline now.
=20
- Export necessary symbols for compiling mq-deadline as a module. =20
- Various API adjustments for the mq schedulers.
=20
- Various cleanups and improvements.
=20
- Fix a lot of bugs. A lot. Upgrade!
=20
Quoted 13 lines
block/Kconfig.iosched | 37 ++ block/Makefile | 3=20 block/blk-core.c | 9=20 block/blk-exec.c | 3=20 block/blk-flush.c | 7=20 block/blk-merge.c | 3=20 block/blk-mq-sched.c | 265 +++++++++++++++++++ block/blk-mq-sched.h | 188 +++++++++++++ block/blk-mq-tag.c | 1=20 block/blk-mq.c | 254 ++++++++++-------- block/blk-mq.h | 35 +- block/elevator.c | 194 ++++++++++---- block/mq-deadline.c | 647 =
+++++++++++++++++++++++++++++++++++++++++++++++
Quoted 7 lines
drivers/nvme/host/pci.c | 1=20 include/linux/blk-mq.h | 4=20 include/linux/elevator.h | 34 ++ 16 files changed, 1495 insertions(+), 190 deletions(-)=20
--
To unsubscribe from this list: send the line "unsubscribe linux-block" =
in
Quoted 2 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 21 lines · Paolo Valente
Quoted 12 lines
Il giorno 08 dic 2016, alle ore 21:13, Jens Axboe <[email protected]> ha scritto:
As a followup to this posting from yesterday:
https://marc.info/?l=linux-block&m=148115232806065&w=2
this is version 2. I wanted to post a new one fairly quickly, as there ended up being a number of potential crashes in v1. This one should be solid, I've run mq-deadline on both NVMe and regular rotating storage, and we handle the various merging cases correctly.
Quoted 8 lines
You can download it from git as well:
git://git.kernel.dk/linux-blockblk-mq-sched.2Note that this is based on for-4.10/block, which is in turn based on v4.9-rc1. I suggest pulling it into my for-next branch, which would then merge nicely with 'master' as well.
Quoted 8 lines
Hi Jens,
this is just to tell you that I have finished running some extensive tests on this patch series (throughput, responsiveness, low latency for soft real time). No regression w.r.t. blk detected, and no crashes or other anomalies.Starting to work on BFQ port. Please be patient with my little expertise on mq environment, and with my next silly questions!
No worries, ask away if you have questions. As you might have seen, it's still a little bit of a moving target, but it's getting closer every day. I'll post a v3 later today hopefully that will be a good fix point for you. I'll need to add the io context setup etc, that's not there yet, as only cfq/bfq uses that.
Signature · 1 line
Jens Axboe
Quoted 2 lines
Il giorno 13 dic 2016, alle ore 16:17, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 08 dic 2016, alle ore 21:13, Jens Axboe <[email protected]> ha =
scritto:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
=20
As a followup to this posting from yesterday:
=20
https://marc.info/?l=3Dlinux-block&m=3D148115232806065&w=3D2
=20
this is version 2. I wanted to post a new one fairly quickly, as =
there
Quoted 1 line
Quoted 1 line
Quoted 1 line
ended up being a number of potential crashes in v1. This one should =
be
Quoted 1 line
Quoted 1 line
Quoted 1 line
solid, I've run mq-deadline on both NVMe and regular rotating =
storage,
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
and we handle the various merging cases correctly.
=20
You can download it from git as well:
=20git://git.kernel.dk/linux-blockblk-mq-sched.2
=20
Note that this is based on for-4.10/block, which is in turn based on v4.9-rc1. I suggest pulling it into my for-next branch, which would then merge nicely with 'master' as well.
=20Quoted 9 lines
=20
Hi Jens,
this is just to tell you that I have finished running some extensive tests on this patch series (throughput, responsiveness, low latency for soft real time). No regression w.r.t. blk detected, and no crashes or other anomalies.
=20
Starting to work on BFQ port. Please be patient with my little expertise on mq environment, and with my next silly questions!
Quoted 2 lines
=20
No worries, ask away if you have questions. As you might have seen, =
it's
Quoted 2 lines
still a little bit of a moving target, but it's getting closer every day. I'll post a v3 later today hopefully that will be a good fix =
point
Quoted 3 lines
for you. I'll need to add the io context setup etc, that's not there yet, as only cfq/bfq uses that.
=20
You anticipated the question that was worrying me more, how to handle iocontexts :) I'll go on studying your patches while waiting for this (last, right?) missing piece for bfq.
Should you implement a modified version of cfq, to test your last extensions, I would of course appreciate very much to have a look at it (if you are willing to share it, of course).
Thanks,
Paolo
Quoted 2 lines
--=20
Jens Axboe
Quoted 41 lines · Paolo Valente
Quoted 31 lines
Il giorno 13 dic 2016, alle ore 16:17, Jens Axboe <[email protected]> ha scritto:
Quoted 27 lines · Paolo Valente
Quoted 12 lines
Il giorno 08 dic 2016, alle ore 21:13, Jens Axboe <[email protected]> ha scritto:
As a followup to this posting from yesterday:
https://marc.info/?l=linux-block&m=148115232806065&w=2
this is version 2. I wanted to post a new one fairly quickly, as there ended up being a number of potential crashes in v1. This one should be solid, I've run mq-deadline on both NVMe and regular rotating storage, and we handle the various merging cases correctly.
Quoted 8 lines
You can download it from git as well:
git://git.kernel.dk/linux-blockblk-mq-sched.2Note that this is based on for-4.10/block, which is in turn based on v4.9-rc1. I suggest pulling it into my for-next branch, which would then merge nicely with 'master' as well.
Hi Jens,
this is just to tell you that I have finished running some extensive tests on this patch series (throughput, responsiveness, low latency for soft real time). No regression w.r.t. blk detected, and no crashes or other anomalies.Quoted 9 lines
Quoted 2 lines
Starting to work on BFQ port. Please be patient with my little expertise on mq environment, and with my next silly questions!
No worries, ask away if you have questions. As you might have seen, it's still a little bit of a moving target, but it's getting closer every day. I'll post a v3 later today hopefully that will be a good fix point for you. I'll need to add the io context setup etc, that's not there yet, as only cfq/bfq uses that.
Quoted 3 lines
You anticipated the question that was worrying me more, how to handle iocontexts :) I'll go on studying your patches while waiting for this (last, right?) missing piece for bfq.
It's the last missing larger piece. We probably have a few hooks that BFQ/CFQ currently uses that aren't wired up yet in the elevator_ops for mq, so you'll probably have to do those as you go. I can take a look, but I would prefer if they be done one a as-needed basis. Perhaps we can get rid of some of them.
Quoted 3 lines
Should you implement a modified version of cfq, to test your last extensions, I would of course appreciate very much to have a look at it (if you are willing to share it, of course).
I most likely won't do that, as it would be a waste of time on my end. If you need help with the BFQ parts, I'll help you out.
Signature · 1 line
Jens Axboe
Quoted 11 lines · Jens Axboe
Quoted 10 lines
Quoted 6 lines
No worries, ask away if you have questions. As you might have seen, it's still a little bit of a moving target, but it's getting closer every day. I'll post a v3 later today hopefully that will be a good fix point for you. I'll need to add the io context setup etc, that's not there yet, as only cfq/bfq uses that.
You anticipated the question that was worrying me more, how to handle iocontexts :) I'll go on studying your patches while waiting for this (last, right?) missing piece for bfq.
Quoted 5 lines
It's the last missing larger piece. We probably have a few hooks that BFQ/CFQ currently uses that aren't wired up yet in the
elevator_opsfor mq, so you'll probably have to do those as you go. I can take a look, but I would prefer if they be done one a as-needed basis. Perhaps we can get rid of some of them.
The current 'blk-mq-sched' branch has support for getting the IO contexts setup, and assigned to requests. Only works off the task io_context for now, we ignore anything set in the bio. But that's a minor thing, generally it should work for you.
Note that the mq ops have different naming than the classic elevator ops. For instance, the set_request/put_request are get_rq_priv/put_rq_priv instead. Others are different as well. In general, refer to mq-deadline.c for how the hooks work and you can compare with deadline-iosched.c, since they are still very close.
Note that the io context linking uses the embedded queue lock, q->queue_lock, whereas for other things you are free to use a lock embedded in the your elevator data. Again, refer to mq-deadline, it uses dd->lock to protect the hash/rbtree. If mq-deadline used io contexts, it would manage those behind q->queue_lock.
Signature · 1 line
Jens Axboe