blk-mq scheduling framework
I hacked up some support for registering blk-mq capable IO schedulers, and when that was done, I adapted deadline to work with it as a new mq-deadline scheduler.
Basically this is similar to the legacy scheduling patches I posted recently, in that we setup a list of fake requests (I called them shadows) that the IO scheduler works on. We then transform those into a real blk-mq request, when we have to dispatch to hardware.
There's a hack in place to make this work with the flush/fua requests, as those bypass the regular software queue insertion. For now we simply ensure that we allocate a real request for those. Howeer, I'd prefer if we simply inserted the request as we usually would, and then start the flush state machinery when we pull the request out of the queue. That would both be cleaner from a flush perspective, and from the scheduling side as well.
I'm reusing the existing elevator interface, just augmenting that with mq_ops and a ->uses_mq so we can tell which is which. They show up automatically, for instance on a scsi-mq device:
$ cat /sys/block/sda/queue/scheduler [mq-deadline] none
vs just a legacy device:
$ cat /sys/block/nullb0/queue/scheduler noop deadline [cfq]
Changing schedulers is done in the same way as it always has, by echoing into the 'scheduler' file. For MQ, there's a 'none' setting as well that isn't a real scheduler, it simply turns off the scheduler. Handy for comparison.
Obviously a direct deadline adaptation has performance implications, so it can be improved. A _real_ MQ scheduler is forth coming, which will sit on top of this interface. Paolo, for BFQ, this is the interface you should target. Let me know if you have any questions about how it works.
block/Kconfig.iosched | 6 block/Makefile | 3 block/blk-core.c | 3 block/blk-exec.c | 3 block/blk-flush.c | 7 block/blk-mq-sched.c | 243 ++++++++++++++++++ block/blk-mq-sched.h | 168 ++++++++++++ block/blk-mq-tag.c | 1 block/blk-mq.c | 241 ++++++++++-------- block/blk-mq.h | 33 -- block/elevator.c | 140 +++++++--- block/mq-deadline.c | 622 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/blk-mq.h | 3 include/linux/elevator.h | 30 ++ 14 files changed, 1331 insertions(+), 172 deletions(-)
Signature · 1 line
Jens Axboe
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
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
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
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
PATCH 5/7 blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens Axboe--- block/blk-mq-sched.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++ block/blk-mq-sched.h | 168 +++++++++++++++++++++++++++++++++++ 2 files changed, 411 insertions(+) create mode 100644 block/blk-mq-sched.c create mode 100644 block/blk-mq-sched.h
block/blk-mq-sched.c new file +243 -0
@@ -0,0 +1,243 @@ +#include <linux/kernel.h> +#include <linux/module.h> + +#include <linux/blk-mq.h> +#include "blk.h" +#include "blk-mq.h" +#include "blk-mq-sched.h" +#include "blk-mq-tag.h" +#include "blk-wbt.h" + +/* +* Empty set +*/ +static struct blk_mq_ops mq_sched_tag_ops = { + .queue_rq =NULL , +}; + +void blk_mq_sched_free_requests (struct blk_mq_tags *tags) +{ +blk_mq_free_rq_map (NULL , tags,0 ); +} +EXPORT_SYMBOL_GPL (blk_mq_sched_free_requests); + +struct blk_mq_tags *blk_mq_sched_alloc_requests (unsigned int depth, +unsigned int numa_node) +{ +struct blk_mq_tag_set set = { + .ops = &mq_sched_tag_ops, + .nr_hw_queues =1 , + .queue_depth = depth, + .numa_node = numa_node, + }; + +return blk_mq_init_rq_map (&set,0 ); +} +EXPORT_SYMBOL_GPL (blk_mq_sched_alloc_requests); + +void blk_mq_sched_free_hctx_data (struct request_queue *q, +void (*exit)(struct blk_mq_hw_ctx *)) +{ +struct blk_mq_hw_ctx *hctx; +int i; + +queue_for_each_hw_ctx (q, hctx, i) { +if (exit) +exit (hctx); +kfree (hctx->sched_data); + hctx->sched_data =NULL ; + } +} +EXPORT_SYMBOL_GPL (blk_mq_sched_free_hctx_data); + +int blk_mq_sched_init_hctx_data (struct request_queue *q,size_t size, +void (*init)(struct blk_mq_hw_ctx *)) +{ +struct blk_mq_hw_ctx *hctx; +int i; + +queue_for_each_hw_ctx (q, hctx, i) { + hctx->sched_data =kmalloc_node (size,GFP_KERNEL , hctx->numa_node); +if (!hctx->sched_data) + goto error; + +if (init) +init (hctx); + } + +return 0 ; +error: +blk_mq_sched_free_hctx_data (q,NULL ); +return -ENOMEM ; +} +EXPORT_SYMBOL_GPL (blk_mq_sched_init_hctx_data); + +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) +{ +struct sbq_wait_state *ws; +DEFINE_WAIT (wait); +struct request *rq; +int tag; + + tag =__sbitmap_queue_get (&tags->bitmap_tags); +if (tag !=-1 ) + goto done; + +if (data->flags &BLK_MQ_REQ_NOWAIT ) +return NULL ; + + ws =sbq_wait_ptr (&tags->bitmap_tags, wait_index); +do { +prepare_to_wait (&ws->wait, &wait,TASK_UNINTERRUPTIBLE ); + + tag =__sbitmap_queue_get (&tags->bitmap_tags); +if (tag !=-1 ) +break ; + +blk_mq_run_hw_queue (data->hctx, false); + + tag =__sbitmap_queue_get (&tags->bitmap_tags); +if (tag !=-1 ) +break ; + +blk_mq_put_ctx (data->ctx); +io_schedule (); + + data->ctx =blk_mq_get_ctx (data->q); + data->hctx =blk_mq_map_queue (data->q, data->ctx->cpu); +finish_wait (&ws->wait, &wait); + ws =sbq_wait_ptr (&tags->bitmap_tags, wait_index); + }while (1 ); + +finish_wait (&ws->wait, &wait); +done: + rq = tags->rqs[tag]; + rq->tag = tag; +return rq; +} +EXPORT_SYMBOL_GPL (blk_mq_sched_alloc_shadow_request); + +void blk_mq_sched_free_shadow_request (struct blk_mq_tags *tags, +struct request *rq) +{ +sbitmap_queue_clear (&tags->bitmap_tags, rq->tag, rq->mq_ctx->cpu); +} +EXPORT_SYMBOL_GPL (blk_mq_sched_free_shadow_request); + +static void rq_copy (struct request *rq,struct request *src) +{ +#define FIELD_COPY (dst, src, name) ((dst)->name = (src)->name) +FIELD_COPY (rq, src, cpu); +FIELD_COPY (rq, src, cmd_type); +FIELD_COPY (rq, src, cmd_flags); + rq->rq_flags |= (src->rq_flags & (RQF_PREEMPT |RQF_QUIET |RQF_PM |RQF_DONTPREP )); + rq->rq_flags &= ~RQF_IO_STAT ; +FIELD_COPY (rq, src, __data_len); +FIELD_COPY (rq, src, __sector); +FIELD_COPY (rq, src, bio); +FIELD_COPY (rq, src, biotail); +FIELD_COPY (rq, src, rq_disk); +FIELD_COPY (rq, src, part); +FIELD_COPY (rq, src, nr_phys_segments); +#if defined(CONFIG_BLK_DEV_INTEGRITY ) +FIELD_COPY (rq, src, nr_integrity_segments); +#endif +FIELD_COPY (rq, src, ioprio); +FIELD_COPY (rq, src, timeout); + +if (src->cmd_type ==REQ_TYPE_BLOCK_PC ) { +FIELD_COPY (rq, src, cmd); +FIELD_COPY (rq, src, cmd_len); +FIELD_COPY (rq, src, extra_len); +FIELD_COPY (rq, src, sense_len); +FIELD_COPY (rq, src, resid_len); +FIELD_COPY (rq, src, sense); +FIELD_COPY (rq, src, retries); + } + + src->bio = src->biotail =NULL ; +} + +static void sched_rq_end_io (struct request *rq,int error) +{ +struct request *sched_rq = rq->end_io_data; + +FIELD_COPY (sched_rq, rq, resid_len); +FIELD_COPY (sched_rq, rq, extra_len); +FIELD_COPY (sched_rq, rq, sense_len); +FIELD_COPY (sched_rq, rq, errors); +FIELD_COPY (sched_rq, rq, retries); + +blk_account_io_completion (sched_rq,blk_rq_bytes (sched_rq)); +blk_account_io_done (sched_rq); + +wbt_done (sched_rq->q->rq_wb, &sched_rq->issue_stat); + +if (sched_rq->end_io) + sched_rq->end_io (sched_rq, error); + +blk_mq_free_request (rq); +} + +struct request * +blk_mq_sched_request_from_shadow (struct blk_mq_hw_ctx *hctx, +struct request *(*get_sched_rq)(struct blk_mq_hw_ctx *)) +{ +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); +return NULL ; + } + +rq_copy (rq, sched_rq); + rq->end_io = sched_rq_end_io; + rq->end_io_data = sched_rq; + +return rq; +} +EXPORT_SYMBOL_GPL (blk_mq_sched_request_from_shadow); + +void blk_mq_sched_dispatch_requests (struct blk_mq_hw_ctx *hctx) +{ +struct elevator_queue *e = hctx->queue->elevator; +struct request *rq; +LIST_HEAD (rq_list); + +if (unlikely (blk_mq_hctx_stopped (hctx))) +return ; + + hctx->run++; + +if (!list_empty (&hctx->dispatch)) { +spin_lock (&hctx->lock); +if (!list_empty (&hctx->dispatch)) +list_splice_init (&hctx->dispatch, &rq_list); +spin_unlock (&hctx->lock); + } + +while ((rq = e->type->mq_ops.dispatch_request (hctx)) !=NULL ) +list_add_tail (&rq->queuelist, &rq_list); + +blk_mq_dispatch_rq_list (hctx, &rq_list); +}
block/blk-mq-sched.h new file +168 -0
168 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 6/7 blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens Axboe--- block/Makefile | 2 +- block/blk-core.c | 3 +- block/blk-exec.c | 3 +- block/blk-flush.c | 7 +-- block/blk-mq-tag.c | 1 + block/blk-mq.c | 138 +++++++++++++++++++++++++---------------------- block/blk-mq.h | 32 +++++------ block/elevator.c | 132 ++++++++++++++++++++++++++++++++++----------- include/linux/blk-mq.h | 2 +- include/linux/elevator.h | 25 ++++++++- 10 files changed, 222 insertions(+), 123 deletions(-)
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 +2 -1
@@ -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);
@@ -2173,7 +2174,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-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 +75 -63
307 lines not on this page · raw message
block/blk-mq.h +12 -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,16 @@ 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);#endif
block/elevator.c +100 -32
234 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 +24 -1
@@ -77,6 +77,24 @@ 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 *); +struct request *(*get_request)(struct request_queue *,struct bio *,struct blk_mq_alloc_data *); +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 *); +}; +#define ELV_NAME_MAX (16)struct elv_fs_entry {
@@ -94,12 +112,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 +145,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
PATCH 7/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 | 622 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 629 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 +622 -0
622 lines not on this page · raw message
Signature · 1 line
2.7.4