blk-mq-scheduling framework
Subsystems (2)
PATCH v4 1/1 blk-mq-scheduling framework
This is version 4 of this patchset, version 3 was posted here:
https://marc.info/?l=linux-block&m=148178513407631&w=2
Quoted 1 line
From the discussion last time, I looked into the feasibility of having
two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
Changes since v3:
- Keep the blk_mq_free_request/__blk_mq_free_request() as the interface, and have those functions call the scheduler API instead.
- Add insertion merging from unplugging.
- Ensure that RQF_STARTED is cleared when we get a new shadow request, or merging will fail if it is already set.
- Improve the blk_mq_sched_init_hctx_data() implementation. From Omar.
- Make the shadow alloc/free interface more usable by schedulers that use the software queues. From Omar.
- Fix a bug in the io context code.
- Put the is_shadow() helper in generic code, instead of in mq-deadline.
- Add prep patch that unexports blk_mq_free_hctx_request(), it's not used by anyone.
- Remove the magic '256' queue depth from mq-deadline, replace with a module parameter, 'queue_depth', that defaults to 256.
- Various cleanups.
PATCH 1/8 block: move existing elevator ops to union
Prep patch for adding MQ ops as well, since doing anon unions with named initializers doesn't work on older compilers.
--- block/blk-ioc.c | 8 +++---- block/blk-merge.c | 4 ++-- block/blk.h | 10 ++++---- block/cfq-iosched.c | 2 +- block/deadline-iosched.c | 2 +- block/elevator.c | 60 ++++++++++++++++++++++++------------------------ block/noop-iosched.c | 2 +- include/linux/elevator.h | 4 +++- 8 files changed, 47 insertions(+), 45 deletions(-)
block/blk-ioc.c +4 -4
@@ -43,8 +43,8 @@ static void ioc_exit_icq(struct io_cq *icq)if (icq->flags &ICQ_EXITED )return ; -if (et->ops.elevator_exit_icq_fn) - et->ops.elevator_exit_icq_fn (icq); +if (et->ops.sq.elevator_exit_icq_fn) + et->ops.sq.elevator_exit_icq_fn (icq); icq->flags |=ICQ_EXITED ; }
@@ -383,8 +383,8 @@ struct io_cq *ioc_create_icq(struct io_context *ioc, struct request_queue *q,if (likely (!radix_tree_insert (&ioc->icq_tree, q->id, icq))) {hlist_add_head (&icq->ioc_node, &ioc->icq_list);list_add (&icq->q_node, &q->icq_list); -if (et->ops.elevator_init_icq_fn) - et->ops.elevator_init_icq_fn (icq); +if (et->ops.sq.elevator_init_icq_fn) + et->ops.sq.elevator_init_icq_fn (icq); }else {kmem_cache_free (et->icq_cache, icq); icq =ioc_lookup_icq (ioc, q);
block/blk-merge.c +2 -2
@@ -763,8 +763,8 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq, {struct elevator_queue *e = q->elevator; -if (e->type->ops.elevator_allow_rq_merge_fn) -if (!e->type->ops.elevator_allow_rq_merge_fn (q, rq, next)) +if (e->type->ops.sq.elevator_allow_rq_merge_fn) +if (!e->type->ops.sq.elevator_allow_rq_merge_fn (q, rq, next))return 0 ;return attempt_merge (q, rq, next);
block/blk.h +5 -5
@@ -167,7 +167,7 @@ static inline struct request *__elv_next_request(struct request_queue *q)return NULL ; }if (unlikely (blk_queue_bypass (q)) || - !q->elevator->type->ops.elevator_dispatch_fn (q,0 )) + !q->elevator->type->ops.sq.elevator_dispatch_fn (q,0 ))return NULL ; } }
@@ -176,16 +176,16 @@ static inline void elv_activate_rq(struct request_queue *q, struct request *rq) {struct elevator_queue *e = q->elevator; -if (e->type->ops.elevator_activate_req_fn) - e->type->ops.elevator_activate_req_fn (q, rq); +if (e->type->ops.sq.elevator_activate_req_fn) + e->type->ops.sq.elevator_activate_req_fn (q, rq); }static inline void elv_deactivate_rq (struct request_queue *q,struct request *rq) {struct elevator_queue *e = q->elevator; -if (e->type->ops.elevator_deactivate_req_fn) - e->type->ops.elevator_deactivate_req_fn (q, rq); +if (e->type->ops.sq.elevator_deactivate_req_fn) + e->type->ops.sq.elevator_deactivate_req_fn (q, rq); }#ifdef CONFIG_FAIL_IO_TIMEOUT
block/cfq-iosched.c +1 -1
@@ -4837,7 +4837,7 @@ static struct elv_fs_entry cfq_attrs[] = { };static struct elevator_type iosched_cfq = { - .ops = { + .ops.sq = { .elevator_merge_fn = cfq_merge, .elevator_merged_fn = cfq_merged_request, .elevator_merge_req_fn = cfq_merged_requests,
block/deadline-iosched.c +1 -1
@@ -439,7 +439,7 @@ static struct elv_fs_entry deadline_attrs[] = { };static struct elevator_type iosched_deadline = { - .ops = { + .ops.sq = { .elevator_merge_fn = deadline_merge, .elevator_merged_fn = deadline_merged_request, .elevator_merge_req_fn = deadline_merged_requests,
block/elevator.c +30 -30
162 lines not on this page · raw message
block/noop-iosched.c +1 -1
@@ -92,7 +92,7 @@ static void noop_exit_queue(struct elevator_queue *e) }static struct elevator_type elevator_noop = { - .ops = { + .ops.sq = { .elevator_merge_req_fn = noop_merged_requests, .elevator_dispatch_fn = noop_dispatch, .elevator_add_req_fn = noop_add_request,
include/linux/elevator.h +3 -1
@@ -94,7 +94,9 @@ struct elevator_typestruct kmem_cache *icq_cache;/* fields provided by elevator implementation */ -struct elevator_ops ops; +union { +struct elevator_ops sq; + } ops;size_t icq_size;/* see iocontext.h */ size_t icq_align;/* ditto */ struct elv_fs_entry *elevator_attrs;
Signature · 1 line
2.7.4
PATCH 2/8 blk-mq: make mq_ops a const pointer
In reply to Jens AxboeWe never change it, make that clear.
--- block/blk-mq.c | 2 +- include/linux/blk-mq.h | 2 +- include/linux/blkdev.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
block/blk-mq.c +1 -1
@@ -639,7 +639,7 @@ struct blk_mq_timeout_data {void blk_mq_rq_timed_out (struct request *req,bool reserved) { -struct blk_mq_ops *ops = req->q->mq_ops; +const struct blk_mq_ops *ops = req->q->mq_ops;enum blk_eh_timer_return ret =BLK_EH_RESET_TIMER ;/*
include/linux/blk-mq.h +1 -1
@@ -60,7 +60,7 @@ struct blk_mq_hw_ctx {struct blk_mq_tag_set {unsigned int *mq_map; -struct blk_mq_ops *ops; +const struct blk_mq_ops *ops;unsigned int nr_hw_queues;unsigned int queue_depth;/* max hw supported */ unsigned int reserved_tags;
include/linux/blkdev.h +1 -1
@@ -408,7 +408,7 @@ struct request_queue {dma_drain_needed_fn *dma_drain_needed;lld_busy_fn *lld_busy_fn; -struct blk_mq_ops *mq_ops; +const struct blk_mq_ops *mq_ops;unsigned int *mq_map;
Signature · 1 line
2.7.4
PATCH 3/8 block: move rq_ioc() to blk.h
In reply to Jens AxboeWe want to use it outside of blk-core.c.
--- block/blk-core.c | 16 ---------------- block/blk.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-)
block/blk-core.c +0 -16
@@ -1040,22 +1040,6 @@ static bool blk_rq_should_init_elevator(struct bio *bio) }/** -* rq_ioc - determine io_context for request allocation -* @bio: request being allocated is for this bio (can be %NULL) -* -* Determine io_context to use for request allocation for @bio. May return -* %NULL if %current->io_context doesn't exist. -*/ -static struct io_context *rq_ioc (struct bio *bio) -{ -#ifdef CONFIG_BLK_CGROUP -if (bio && bio->bi_ioc) -return bio->bi_ioc; -#endif -return current->io_context; -} - -/** * __get_request - get a free request * @rl: request list to allocate from * @op: operation and flags
block/blk.h +16 -0
@@ -264,6 +264,22 @@ void ioc_clear_queue(struct request_queue *q);int create_task_io_context (struct task_struct *task,gfp_t gfp_mask,int node);/** +* rq_ioc - determine io_context for request allocation +* @bio: request being allocated is for this bio (can be %NULL) +* +* Determine io_context to use for request allocation for @bio. May return +* %NULL if %current->io_context doesn't exist. +*/ +static inline struct io_context *rq_ioc (struct bio *bio) +{ +#ifdef CONFIG_BLK_CGROUP +if (bio && bio->bi_ioc) +return bio->bi_ioc; +#endif +return current->io_context; +} + +/** * create_io_context - try to create task->io_context * @gfp_mask: allocation mask * @node: allocation node
Signature · 1 line
2.7.4
PATCH 4/8 blk-mq: un-export blk_mq_free_hctx_request()
In reply to Jens AxboeIt's only used in blk-mq, kill it from the main exported header and kill the symbol export as well.
--- block/blk-mq.c | 5 ++--- include/linux/blk-mq.h | 1 - 2 files changed, 2 insertions(+), 4 deletions(-)
block/blk-mq.c +2 -3
@@ -337,15 +337,14 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,blk_queue_exit (q); } -void blk_mq_free_hctx_request (struct blk_mq_hw_ctx *hctx,struct request *rq) +static void blk_mq_free_hctx_request (struct blk_mq_hw_ctx *hctx, +struct request *rq) {struct blk_mq_ctx *ctx = rq->mq_ctx; ctx->rq_completed[rq_is_sync (rq)]++;__blk_mq_free_request (hctx, ctx, rq); - } -EXPORT_SYMBOL_GPL (blk_mq_free_hctx_request);void blk_mq_free_request (struct request *rq) {
include/linux/blk-mq.h +0 -1
@@ -181,7 +181,6 @@ 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 *);enum {
Signature · 1 line
2.7.4
PATCH 5/8 blk-mq: export some helpers we need to the scheduling framework
In reply to Jens Axboe--- block/blk-mq.c | 39 +++++++++++++++++++++------------------ block/blk-mq.h | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 18 deletions(-)
block/blk-mq.c +21 -18
@@ -167,8 +167,8 @@ bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx) }EXPORT_SYMBOL (blk_mq_can_queue); -static void blk_mq_rq_ctx_init (struct request_queue *q,struct blk_mq_ctx *ctx, -struct request *rq,unsigned int op) +void blk_mq_rq_ctx_init (struct request_queue *q,struct blk_mq_ctx *ctx, +struct request *rq,unsigned int op) {INIT_LIST_HEAD (&rq->queuelist);/* csd/requeue_work/fifo_time is initialized before use */
@@ -213,9 +213,10 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx, ctx->rq_dispatched[op_is_sync (op)]++; } +EXPORT_SYMBOL_GPL (blk_mq_rq_ctx_init); -static struct request * -__blk_mq_alloc_request (struct blk_mq_alloc_data *data,unsigned int op) +struct request *__blk_mq_alloc_request (struct blk_mq_alloc_data *data, +unsigned int op) {struct request *rq;unsigned int tag;
@@ -236,6 +237,7 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, unsigned int op)return NULL ; } +EXPORT_SYMBOL_GPL (__blk_mq_alloc_request);struct request *blk_mq_alloc_request (struct request_queue *q,int rw,unsigned int flags)
@@ -319,8 +321,8 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, int rw, }EXPORT_SYMBOL_GPL (blk_mq_alloc_request_hctx); -static void __blk_mq_free_request (struct blk_mq_hw_ctx *hctx, -struct blk_mq_ctx *ctx,struct request *rq) +void __blk_mq_free_request (struct blk_mq_hw_ctx *hctx,struct blk_mq_ctx *ctx, +struct request *rq) {const int tag = rq->tag;struct request_queue *q = rq->q;
@@ -802,7 +804,7 @@ static bool flush_busy_ctx(struct sbitmap *sb, unsigned int bitnr, void *data)* Process software queues that have been marked busy, splicing them * to the for-dispatch */ -static void flush_busy_ctxs (struct blk_mq_hw_ctx *hctx,struct list_head *list) +void blk_mq_flush_busy_ctxs (struct blk_mq_hw_ctx *hctx,struct list_head *list) {struct flush_busy_ctx_data data = { .hctx = hctx,
@@ -811,6 +813,7 @@ static void flush_busy_ctxs(struct blk_mq_hw_ctx *hctx, struct list_head *list)sbitmap_for_each_set (&hctx->ctx_map, flush_busy_ctx, &data); } +EXPORT_SYMBOL_GPL (blk_mq_flush_busy_ctxs);static inline unsigned int queued_to_index (unsigned int queued) {
@@ -921,7 +924,7 @@ static void blk_mq_process_rq_list(struct blk_mq_hw_ctx *hctx)/* * Touch any software queue that has pending entries. */ -flush_busy_ctxs (hctx, &rq_list); +blk_mq_flush_busy_ctxs (hctx, &rq_list);/* * If we have previous entries on our dispatch list, grab them
@@ -1135,8 +1138,8 @@ static inline void __blk_mq_insert_req_list(struct blk_mq_hw_ctx *hctx,list_add_tail (&rq->queuelist, &ctx->rq_list); } -static void __blk_mq_insert_request (struct blk_mq_hw_ctx *hctx, -struct request *rq,bool at_head) +void __blk_mq_insert_request (struct blk_mq_hw_ctx *hctx,struct request *rq, +bool at_head) {struct blk_mq_ctx *ctx = rq->mq_ctx;
@@ -1550,8 +1553,8 @@ static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio)return cookie; } -static void blk_mq_free_rq_map (struct blk_mq_tag_set *set, -struct blk_mq_tags *tags,unsigned int hctx_idx) +void blk_mq_free_rq_map (struct blk_mq_tag_set *set,struct blk_mq_tags *tags, +unsigned int hctx_idx) {struct page *page;
@@ -1588,8 +1591,8 @@ static size_t order_to_size(unsigned int order)return (size_t )PAGE_SIZE << order; } -static struct blk_mq_tags *blk_mq_init_rq_map (struct blk_mq_tag_set *set, -unsigned int hctx_idx) +struct blk_mq_tags *blk_mq_init_rq_map (struct blk_mq_tag_set *set, +unsigned int hctx_idx) {struct blk_mq_tags *tags;unsigned int i, j, entries_per_page, max_order =4 ;
@@ -2263,10 +2266,10 @@ static int blk_mq_queue_reinit_dead(unsigned int cpu)* Now CPU1 is just onlined and a request is inserted into ctx1->rq_list * and set bit0 in pending bitmap as ctx1->index_hw is still zero. * -* And then while running hw queue, flush_busy_ctxs() finds bit0 is set in -* pending bitmap and tries to retrieve requests in hctx->ctxs[0]->rq_list. -* But htx->ctxs[0] is a pointer to ctx0, so the request in ctx1->rq_list -* is ignored. +* And then while running hw queue, blk_mq_flush_busy_ctxs() finds bit0 is set +* in pending bitmap and tries to retrieve requests in hctx->ctxs[0]->rq_list. +* But htx->ctxs[0] is a pointer to ctx0, so the request in ctx1->rq_list is +* ignored. */ static int blk_mq_queue_reinit_prepare (unsigned int cpu) {
block/blk-mq.h +25 -0
@@ -32,6 +32,21 @@ 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 *); +void blk_mq_flush_busy_ctxs (struct blk_mq_hw_ctx *hctx,struct list_head *list); + +/* +* Internal helpers for allocating/freeing the request map +*/ +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); + +/* +* Internal helpers for request insertion into sw queues +*/ +void __blk_mq_insert_request (struct blk_mq_hw_ctx *hctx,struct request *rq, +bool at_head);/* * CPU hotplug helpers
@@ -103,6 +118,16 @@ static inline void blk_mq_set_alloc_data(struct blk_mq_alloc_data *data, data->hctx = hctx; } +/* +* Internal helpers for request allocation/init/free +*/ +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); +static inline bool blk_mq_hctx_stopped (struct blk_mq_hw_ctx *hctx) {return test_bit (BLK_MQ_S_STOPPED , &hctx->state);
Signature · 1 line
2.7.4
PATCH 6/8 blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens AxboeThis adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with.
--- block/Makefile | 2 +- block/blk-core.c | 3 +- block/blk-exec.c | 3 +- block/blk-flush.c | 7 +- block/blk-merge.c | 2 +- block/blk-mq-sched.c | 434 +++++++++++++++++++++++++++++++++++++++++++++++ block/blk-mq-sched.h | 209 +++++++++++++++++++++++ block/blk-mq.c | 197 +++++++++------------ block/blk-mq.h | 6 +- block/elevator.c | 186 +++++++++++++++----- include/linux/blk-mq.h | 3 +- include/linux/elevator.h | 30 ++++ 12 files changed, 914 insertions(+), 168 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 +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);
@@ -2127,7 +2128,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 {
@@ -453,9 +454,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 +1 -1
@@ -763,7 +763,7 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq, {struct elevator_queue *e = q->elevator; -if (e->type->ops.sq.elevator_allow_rq_merge_fn) +if (!e->uses_mq && e->type->ops.sq.elevator_allow_rq_merge_fn)if (!e->type->ops.sq.elevator_allow_rq_merge_fn (q, rq, next))return 0 ;
block/blk-mq-sched.c new file +434 -0
434 lines not on this page · raw message
block/blk-mq-sched.h new file +209 -0
209 lines not on this page · raw message
block/blk-mq.c +82 -115
389 lines not on this page · raw message
block/blk-mq.h +4 -2
@@ -47,7 +47,8 @@ struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,*/ void __blk_mq_insert_request (struct blk_mq_hw_ctx *hctx,struct request *rq,bool at_head); - +void blk_mq_insert_requests (struct blk_mq_hw_ctx *hctx,struct blk_mq_ctx *ctx, +struct list_head *list);/* * CPU hotplug helpers */
@@ -123,8 +124,9 @@ static inline void blk_mq_set_alloc_data(struct blk_mq_alloc_data *data,*/ 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, +void __blk_mq_finish_request (struct blk_mq_hw_ctx *hctx,struct blk_mq_ctx *ctx,struct request *rq); +void blk_mq_finish_request (struct request *rq);struct request *__blk_mq_alloc_request (struct blk_mq_alloc_data *data,unsigned int op);
block/elevator.c +143 -43
377 lines not on this page · raw message
include/linux/blk-mq.h +2 -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;
@@ -156,6 +157,7 @@ enum {BLK_MQ_S_STOPPED =0 ,BLK_MQ_S_TAG_ACTIVE =1 , +BLK_MQ_S_SCHED_RESTART =2 , BLK_MQ_MAX_DEPTH = 10240,
@@ -179,7 +181,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);bool blk_mq_can_queue (struct blk_mq_hw_ctx *);
include/linux/elevator.h +30 -0
@@ -77,6 +77,32 @@ 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 *); +int (*request_merge)(struct request_queue *q,struct request **,struct bio *); +void (*request_merged)(struct request_queue *,struct request *,int ); +void (*requests_merged)(struct request_queue *,struct request *,struct request *); +struct request *(*get_request)(struct request_queue *,unsigned int ,struct blk_mq_alloc_data *); +bool (*put_request)(struct request *); +void (*insert_requests)(struct blk_mq_hw_ctx *,struct list_head *,bool ); +void (*dispatch_requests)(struct blk_mq_hw_ctx *,struct list_head *); +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 *); +int (*get_rq_priv)(struct request_queue *,struct request *); +void (*put_rq_priv)(struct request_queue *,struct request *); +}; +#define ELV_NAME_MAX (16)struct elv_fs_entry {
@@ -96,12 +122,14 @@ struct elevator_type/* fields provided by elevator implementation */ union {struct elevator_ops sq; +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" */
@@ -125,6 +153,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 ); };
@@ -141,6 +170,7 @@ extern void elv_merge_requests(struct request_queue *, struct request *,extern void elv_merged_request (struct request_queue *,struct request *,int );extern void elv_bio_merged (struct request_queue *q,struct request *,struct bio *); +extern bool elv_attempt_insert_merge (struct request_queue *,struct request *);extern void elv_requeue_request (struct request_queue *,struct request *);extern struct request *elv_former_request (struct request_queue *,struct request *);extern struct request *elv_latter_request (struct request_queue *,struct request *);
Signature · 1 line
2.7.4
PATCH 7/8 mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeThis is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design.
--- block/Kconfig.iosched | 6 + block/Makefile | 1 + block/mq-deadline.c | 649 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 656 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 +649 -0
649 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 8/8 blk-mq-sched: allow setting of default IO scheduler
In reply to Jens AxboeAdd Kconfig entries to manage what devices get assigned an MQ scheduler, and add a blk-mq flag for drivers to opt out of scheduling. The latter is useful for admin type queues that still allocate a blk-mq queue and tag set, but aren't use for normal IO.
--- block/Kconfig.iosched | 43 +++++++++++++++++++++++++++++++++++++------ block/blk-mq-sched.c | 19 +++++++++++++++++++ block/blk-mq-sched.h | 2 ++ block/blk-mq.c | 3 +++ block/elevator.c | 5 ++++- drivers/nvme/host/pci.c | 1 + include/linux/blk-mq.h | 1 + 7 files changed, 67 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 + +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. + endmenu endif
block/blk-mq-sched.c +19 -0
@@ -432,3 +432,22 @@ void blk_mq_sched_request_inserted(struct request *rq)trace_block_rq_insert (rq->q, rq); }EXPORT_SYMBOL_GPL (blk_mq_sched_request_inserted); + +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 +2 -0
@@ -37,6 +37,8 @@ bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq);void blk_mq_sched_dispatch_requests (struct blk_mq_hw_ctx *hctx); +int blk_mq_sched_init (struct request_queue *q); +static inline bool blk_mq_sched_bio_merge (struct request_queue *q,struct bio *bio) {
block/blk-mq.c +3 -0
@@ -2105,6 +2105,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
@@ -1188,6 +1188,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
Quoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 6 lines
=20
This is version 4 of this patchset, version 3 was posted here:
=20
https://marc.info/?l=3Dlinux-block&m=3D148178513407631&w=3D2
=20
=46rom the discussion last time, I looked into the feasibility of =
having
Quoted 2 lines
two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do =
that,
Quoted 7 lines
we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it.
Quoted 8 lines
Unless someone can convince me otherwise, I think the current approach is cleaner.
=20
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
=20
I'm to modifying bfq. You mentioned other missing pieces to come. Do you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
Thanks,
Paolo
Quoted 4 lines
Changes since v3:
=20
- Keep the blk_mq_free_request/__blk_mq_free_request() as the interface, and have those functions call the scheduler API
Quoted 8 lines
instead.
=20
- Add insertion merging from unplugging.
=20
- Ensure thatRQF_STARTEDis cleared when we get a new shadow request, or merging will fail if it is already set.
=20
- Improve theblk_mq_sched_init_hctx_data()implementation. =46rom =
Omar.
Quoted 7 lines
=20
- Make the shadow alloc/free interface more usable by schedulers that use the software queues. =46rom Omar.
=20
- Fix a bug in the io context code.
=20
- Put theis_shadow()helper in generic code, instead of in =
mq-deadline.
Quoted 9 lines
=20
- Add prep patch that unexportsblk_mq_free_hctx_request(), it's not used by anyone.
=20
- Remove the magic '256' queue depth from mq-deadline, replace with a module parameter, 'queue_depth', that defaults to 256.
=20
- Various cleanups.
=20
Quoted 26 lines · Paolo Valente
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is version 4 of this patchset, version 3 was posted here:
https://marc.info/?l=linux-block&m=148178513407631&w=2
From the discussion last time, I looked into the feasibility of having two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
Quoted 5 lines
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
Quoted 3 lines
I'm to modifying bfq. You mentioned other missing pieces to come. Do you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
I'm mostly talking about elevator ops hooks that aren't there in the new framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in the dispatch_request hook for activate, and put/requeue for deactivate.
Outside of that, some of them have been renamed, and some have been collapsed (like activate/deactivate), and yet others again work a little differently (like merging). See the mq-deadline conversion, and just work through them one at the time.
Signature · 1 line
Jens Axboe
Quoted 35 lines · Jens Axboe
Quoted 26 lines · Paolo Valente
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is version 4 of this patchset, version 3 was posted here:
https://marc.info/?l=linux-block&m=148178513407631&w=2
From the discussion last time, I looked into the feasibility of having two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
Quoted 5 lines
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
Quoted 3 lines
I'm to modifying bfq. You mentioned other missing pieces to come. Do you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
I'm mostly talking about elevator ops hooks that aren't there in the new framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
Quoted 8 lines
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in the
dispatch_requesthook for activate, and put/requeue for deactivate.Outside of that, some of them have been renamed, and some have been collapsed (like activate/deactivate), and yet others again work a little differently (like merging). See the mq-deadline conversion, and just work through them one at the time.
Some more details...
Outside of the differences outlined above, a major one is that the old scheduler interfaces invoked almost all of the hooks with the device queue lock held. That's no longer the case on the new framework, you have to setup your own lock(s) for what you need. That's a lot saner. One example is the attempt to merge a bio to an existing request, that would be the ->bio_merge() hook. If you look at mq-deadline, the hook merely grabs its per-queue lock (dd->lock) and calls a blk-mq-sched helper to do the merging. That, in turn, will call ->request_merge(), so that is called with the lock that ->bio_merge() grabs.
Signature · 5 lines
Jens Axboe -- Jens Axboe
Quoted 2 lines
Il giorno 19 dic 2016, alle ore 16:20, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
=20
This is version 4 of this patchset, version 3 was posted here:
=20
https://marc.info/?l=3Dlinux-block&m=3D148178513407631&w=3D2
=20
=46rom the discussion last time, I looked into the feasibility of =
having
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do =
that,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue =
depth.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current =
approach
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
is cleaner.
=20
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
=20=20
I'm to modifying bfq. You mentioned other missing pieces to come. =
Do
Quoted 4 lines
Quoted 2 lines
you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
=20
I'm mostly talking about elevator ops hooks that aren't there in the =
new
Quoted 7 lines
framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
=20
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in thedispatch_requesthook for activate, and put/requeue for deactivate.
=20
You mean that there is no conceptual problem in moving the code of the activate interface function into the dispatch function, and the code of the deactivate into the put_request? (for a requeue it is a little less clear to me, so one step at a time) Or am I missing something more complex?
Quoted 2 lines
Outside of that, some of them have been renamed, and some have been collapsed (like activate/deactivate), and yet others again work a =
little
Quoted 3 lines
differently (like merging). See the mq-deadline conversion, and just work through them one at the time.
=20
That's how I'm proceeding, thanks.
Thank you,
Paolo
Quoted 5 lines
--=20
Jens Axboe
=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 43 lines · Paolo Valente
Quoted 34 lines
Il giorno 19 dic 2016, alle ore 16:20, Jens Axboe <[email protected]> ha scritto:
Quoted 26 lines · Paolo Valente
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is version 4 of this patchset, version 3 was posted here:
https://marc.info/?l=linux-block&m=148178513407631&w=2
From the discussion last time, I looked into the feasibility of having two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
Quoted 5 lines
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
Quoted 3 lines
I'm to modifying bfq. You mentioned other missing pieces to come. Do you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
Quoted 8 lines
I'm mostly talking about elevator ops hooks that aren't there in the new framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in the
dispatch_requesthook for activate, and put/requeue for deactivate.
Quoted 5 lines
You mean that there is no conceptual problem in moving the code of the activate interface function into the dispatch function, and the code of the deactivate into the
put_request? (for a requeue it is a little less clear to me, so one step at a time) Or am I missing something more complex?
Yes, what I mean is that there isn't a 1:1 mapping between the old ops and the new ops. So you'll have to consider the cases.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
block/mq-deadline.c
Quoted 10 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20Signed-off-by Jens Axboe <[email protected]>...
block/mq-deadline.c new file +4
-0+ +static bool dd_has_work (struct blk_mq_hw_ctx *hctx) +{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c line 533
Quoted 4 lines
block/mq-deadline.c new file +4
-0+ +return !list_empty_careful (&dd->dispatch) || + !list_empty_careful (&dd->fifo_list[0 ]) || + !list_empty_careful (&dd->fifo_list[1 ]);
Just a request for clarification: if I'm not mistaken, list_empty_careful can be used safely only if the only possible other concurrent access is a delete. Or am I missing something?
If the above constraint does hold, then how are we guaranteed that it is met? My doubt arises from, e.g., the possible concurrent list_add from dd_insert_request.
Thanks,
Paolo
Quoted 11 lines
block/mq-deadline.c new file +11
-0+} + +/* +* sysfs parts below +*/ +static ssize_t +deadline_var_show (int var,char *page) +{ +return sprintf (page,"%d\n" , var); +} +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+static ssize_t +deadline_var_store (int *var,const char *page,size_t count) +{ + char *p =3D (char *) page; + + *var =3D simple_strtol(p, &p, 10); +return count; +} + +#define SHOW_FUNCTION (__FUNC, __VAR, __CONV) =
\
Quoted 1 line
+static
ssize_t__FUNC(struct elevator_queue *e, char *page)=
\
Quoted 1 line
+{ =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ int __data =3D __VAR; =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__CONV) =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ __data =3D jiffies_to_msecs(__data); =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ return deadline_var_show(__data, (page)); =
\
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+} +SHOW_FUNCTION (deadline_read_expire_show, dd->fifo_expire[READ ],1 ); +SHOW_FUNCTION (deadline_write_expire_show, dd->fifo_expire[WRITE ],1 ); +SHOW_FUNCTION (deadline_writes_starved_show, dd->writes_starved,0 ); +SHOW_FUNCTION (deadline_front_merges_show, dd->front_merges,0 ); +SHOW_FUNCTION (deadline_fifo_batch_show, dd->fifo_batch,0 ); +#undef SHOW_FUNCTION + +#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) =
\
Quoted 1 line
+static
ssize_t__FUNC(structelevator_queue*e, const char *page, =
size_t count) \
Quoted 1 line
+{ =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ int __data; =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ int ret =3D deadline_var_store(&__data, (page), count); =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__data < (MIN)) =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ __data =3D (MIN); =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ else if (__data > (MAX)) =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ __data =3D (MAX); =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ if (__CONV) =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ *(__PTR) =3D msecs_to_jiffies(__data); =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ else =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ *(__PTR) =3D __data; =
\
Review
Quoted 1 line
(quoted diff) +1
-0+ return ret; =
\
Review
Quoted 2 lines
(quoted diff) +2
-0+} +STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, =
INT_MAX, 1);
Quoted 1 line
+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], =
0, INT_MAX, 1);
Quoted 1 line
+STORE_FUNCTION(deadline_writes_starved_store,
&dd->writes_starved, =
INT_MIN, INT_MAX, 0);
Quoted 1 line
+STORE_FUNCTION(deadline_front_merges_store,
&dd->front_merges, 0, 1, =
0);
Quoted 1 line
+STORE_FUNCTION(deadline_fifo_batch_store,
&dd->fifo_batch, 0, =
INT_MAX, 0);
Quoted 62 lines
block/mq-deadline.c new file +59
-1+#undef STORE_FUNCTION + +#define DD_ATTR (name) \ + __ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \ + deadline_##name##_store) + +static struct elv_fs_entry deadline_attrs[] =3D { +DD_ATTR (read_expire), +DD_ATTR (write_expire), +DD_ATTR (writes_starved), +DD_ATTR (front_merges), +DD_ATTR (fifo_batch), + __ATTR_NULL +}; + +static struct elevator_type mq_deadline =3D { + .ops.mq =3D { + .get_request =3D dd_get_request, + .put_request =3D dd_put_request, + .insert_requests =3D dd_insert_requests, + .dispatch_requests =3D dd_dispatch_requests, + .completed_request =3D dd_completed_request, + .next_request =3D elv_rb_latter_request, + .former_request =3D elv_rb_former_request, + .bio_merge =3D dd_bio_merge, + .request_merge =3D dd_request_merge, + .requests_merged =3D dd_merged_requests, + .request_merged =3D dd_request_merged, + .has_work =3D dd_has_work, + .init_sched =3D dd_init_queue, + .exit_sched =3D dd_exit_queue, + }, + + .uses_mq =3D true, + .elevator_attrs =3D deadline_attrs, + .elevator_name =3D "mq-deadline", + .elevator_owner =3D THIS_MODULE, +}; + +static int __init deadline_init (void ) +{ +if (!queue_depth) { +pr_err ("mq-deadline: queue depth must be > 0\n" ); +return -EINVAL ; + } +return elv_register (&mq_deadline); +} + +static void __exit deadline_exit(void) +{ +elv_unregister (&mq_deadline); +} + +module_init (deadline_init); +module_exit (deadline_exit); + +MODULE_AUTHOR ("Jens Axboe" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("MQ deadline IO scheduler" ); --=202.7.4
=20
Re: [PATCH 3/8] block: move rq_ioc() to blk.h
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 3 lines
=20
We want to use it outside ofblk-core.c.
=20
Hi Jens,
no hooks equivalent to elevator_init_icq_fn and elevator_exit_icq_fn are invoked. In particular, the second hook let bfq (as with cfq) know when it could finally exit the queue associated with the icq. I'm trying to figure out how to make it without these hooks/signals, but at no avail so far ...
Thanks,
Paolo
block/blk-core.c static bool blk_rq_should_init_elevator(struct =
Quoted 11 lines
Signed-off-by Jens Axboe <[email protected]>---
block/blk-core.c| 16 ----------------block/blk.h| 16 ++++++++++++++++2 files changed, 16 insertions(+), 16 deletions(-)=20
block/blk-core.c +0
-0@@ -1040,22 +1040,6 @@ static bool blk_rq_should_init_elevator(struct =
bio *bio)
Quoted 7 lines
block/blk-core.c +0
-0}=20
/**
- *rq_ioc- determineio_contextfor request allocation
- * @bio: request being allocated is for this bio (can be %NULL)
- *
- * Determineio_contextto use for request allocation for @bio. May =
return
Quoted 20 lines
- * %NULL if %current->io_context doesn't exist.
- */block/blk-core.c +0
-10-static struct io_context *rq_ioc (struct bio *bio) -{ -#ifdef CONFIG_BLK_CGROUP -if (bio && bio->bi_ioc) -return bio->bi_ioc; -#endif -return current->io_context; -} - -/** * __get_request - get a free request * @rl: request list to allocate from * @op: operation and flags block/blk.h +0
-0@@ -264,6 +264,22 @@ void ioc_clear_queue(struct request_queue *q);
Quoted 1 line
int create_task_io_context(struct
task_struct*task,gfp_tgfp_mask, =
int node);
Quoted 6 lines
=20
/**
+ *rq_ioc- determineio_contextfor request allocation
+ * @bio: request being allocated is for this bio (can be %NULL)
+ *
+ * Determineio_contextto use for request allocation for @bio. May =
return
Quoted 16 lines
+ * %NULL if %current->io_context doesn't exist.
+ */block/blk.h +10
-1+static inline struct io_context *rq_ioc (struct bio *bio) +{ +#ifdef CONFIG_BLK_CGROUP +if (bio && bio->bi_ioc) +return bio->bi_ioc; +#endif +return current->io_context; +} + +/** * create_io_context - try to create task->io_context * @gfp_mask: allocation mask * @node: allocation node --=20
Quoted 4 lines
2.7.4
=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
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 28 lines
=20
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
=20
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
=20
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with. =20Signed-off-by Jens Axboe <[email protected]>...
=20block/blk-mq-sched.c new file +8
-0+struct request *blk_mq_sched_get_request (struct request_queue *q, +struct bio *bio, +unsigned int op, +struct blk_mq_alloc_data *data) +{ + struct elevator_queue *e =3D q->elevator; +struct blk_mq_hw_ctx *hctx; +struct blk_mq_ctx *ctx;
block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+struct request *rq; + +blk_queue_enter_live (q); + ctx =3D blk_mq_get_ctx(q); + hctx =3D blk_mq_map_queue(q, ctx->cpu); + +blk_mq_set_alloc_data (data, q,0 , ctx, hctx); + +if (e && e->type->ops.mq.get_request) + rq =3D e->type->ops.mq.get_request(q, op, data);
bio is not passed to the scheduler here. Yet bfq uses bio to get the blkcg (invoking bio_blkcg). I'm not finding any workaround.
block/blk-mq-sched.c line 335
Quoted 7 lines
block/blk-mq-sched.c new file +7
-0+else + rq =3D __blk_mq_alloc_request(data, op); + +if (rq) { + rq->elv.icq =3D NULL; +if (e && e->type->icq_cache) +blk_mq_sched_assign_ioc (q, rq, bio);
bfq needs rq->elv.icq to be consistent in bfq_get_request, but the needed initialization seems to occur only after mq.get_request is invoked.
Note: to minimize latency, I'm reporting immediately each problem that apparently cannot be solved by just modifying bfq. But, if the resulting higher number of micro-emails is annoying for you, I can buffer my questions, and send you cumulative emails less frequently.
Thanks,
Paolo
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ data->hctx->queued++; +return rq; + } + +blk_queue_exit (q); +return NULL ; +} + +void blk_mq_sched_dispatch_requests (struct blk_mq_hw_ctx *hctx) +{
block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ struct elevator_queue *e =3D hctx->queue->elevator; +LIST_HEAD (rq_list); + +if (unlikely (blk_mq_hctx_stopped (hctx))) +return ; + + hctx->run++; + +/* +* If we have previous entries on our dispatch list, grab them =
first for
block/blk-mq-sched.c
Quoted 11 lines
block/blk-mq-sched.c new file +11
-0+* 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); + } + +/* +* Only ask the scheduler for requests, if we didn't have =
residual
Review
Quoted 1 line
(quoted diff) +1
-0+ * requests from the dispatch list. This is to avoid the case =
where
Review
Quoted 1 line
(quoted diff) +1
-0+ * we only ever dispatch a fraction of the requests available =
because
Review
Quoted 1 line
(quoted diff) +1
-0+ * of low device queue depth. Once we pull requests out of the =
IO
Review
Quoted 1 line
(quoted diff) +1
-0+ * scheduler, we can no longer merge or sort them. So it's best =
to
block/blk-mq-sched.c
Quoted 6 lines
block/blk-mq-sched.c new file +6
-0+* leave them there for as long as we can. Mark the hw queue as +* needing a restart in that case. +*/ +if (list_empty (&rq_list)) { +if (e && e->type->ops.mq.dispatch_requests) + e->type->ops.mq.dispatch_requests(hctx, =
&rq_list);
Quoted 23 lines
block/blk-mq-sched.c new file +23
-0+else +blk_mq_flush_busy_ctxs (hctx, &rq_list); + }else if (!test_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state)) +set_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state); + +blk_mq_dispatch_rq_list (hctx, &rq_list); +} + +bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio) +{ +struct request *rq; +int ret; + + ret =3D elv_merge(q, &rq, bio); + if (ret =3D=3D ELEVATOR_BACK_MERGE) { +if (bio_attempt_back_merge (q, rq, bio)) { +if (!attempt_back_merge (q, rq)) +elv_merged_request (q, rq, ret); +return true; + } + } else if (ret =3D=3D ELEVATOR_FRONT_MERGE) { +if (bio_attempt_front_merge (q, rq, bio)) { +if (!attempt_front_merge (q, rq))
block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+elv_merged_request (q, rq, ret); +return true; + } + } + +return false; +} +EXPORT_SYMBOL_GPL (blk_mq_sched_try_merge); + +bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio =
*bio)
block/blk-mq-sched.c
Quoted 6 lines
block/blk-mq-sched.c new file +6
-0+{ + struct elevator_queue *e =3D q->elevator; + +if (e->type->ops.mq.bio_merge) { + struct blk_mq_ctx *ctx =3D blk_mq_get_ctx(q); + struct blk_mq_hw_ctx *hctx =3D blk_mq_map_queue(q, =
ctx->cpu);
block/blk-mq-sched.c
Quoted 9 lines
block/blk-mq-sched.c new file +9
-0+ +blk_mq_put_ctx (ctx); +return e->type->ops.mq.bio_merge (hctx, bio); + } + +return false; +} + +bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct =
request *rq)
Quoted 16 lines
block/blk-mq-sched.c new file +10
-0+{ +return rq_mergeable (rq) &&elv_attempt_insert_merge (q, rq); +} +EXPORT_SYMBOL_GPL (blk_mq_sched_try_insert_merge); + +void blk_mq_sched_request_inserted (struct request *rq) +{ +trace_block_rq_insert (rq->q, rq); +} +EXPORT_SYMBOL_GPL (blk_mq_sched_request_inserted);block/blk-mq-sched.h new file +0
-0
block/blk-mq-sched.h line 7
Quoted 7 lines
block/blk-mq-sched.h new file +7
-0@@ -0,0 +1,209 @@ +#ifndef BLK_MQ_SCHED_H +#define BLK_MQ_SCHED_H + +#include "blk-mq.h" +#include "blk-wbt.h" + +struct blk_mq_tags *blk_mq_sched_alloc_requests(unsigned int depth, =
unsigned int numa_node);
block/blk-mq-sched.h
Quoted 12 lines
block/blk-mq-sched.h new file +12
-0+void blk_mq_sched_free_requests (struct blk_mq_tags *tags); + +int blk_mq_sched_init_hctx_data (struct request_queue *q,size_t size, +int (*init)(struct blk_mq_hw_ctx *), +void (*exit)(struct blk_mq_hw_ctx *)); + +void blk_mq_sched_free_hctx_data (struct request_queue *q, +void (*exit)(struct blk_mq_hw_ctx *)); + +void blk_mq_sched_free_shadow_request (struct blk_mq_tags *tags, +struct request *rq); +struct request *blk_mq_sched_alloc_shadow_request(struct =
request_queue *q,
block/blk-mq-sched.h line 20
Quoted 1 line
block/blk-mq-sched.h new file +1
-0+ struct =
blk_mq_alloc_data *data,
block/blk-mq-sched.h line 21
Quoted 1 line
block/blk-mq-sched.h new file +1
-0+ struct blk_mq_tags =
*tags,
block/blk-mq-sched.h
Quoted 4 lines
block/blk-mq-sched.h new file +4
-0+ atomic_t *wait_index); +struct request * +blk_mq_sched_request_from_shadow(struct blk_mq_hw_ctx *hctx, + struct request *(*get_sched_rq)(struct =
blk_mq_hw_ctx *));
block/blk-mq-sched.h
Quoted 5 lines
block/blk-mq-sched.h new file +5
-0+struct request * +__blk_mq_sched_request_from_shadow (struct blk_mq_hw_ctx *hctx, +struct request *sched_rq); + +struct request *blk_mq_sched_get_request(struct request_queue *q, =
struct bio *bio, unsigned int op, struct blk_mq_alloc_data *data);
block/blk-mq-sched.h
Quoted 4 lines
block/blk-mq-sched.h new file +4
-0+ +void __blk_mq_sched_dispatch_requests (struct blk_mq_hw_ctx *hctx); +void blk_mq_sched_request_inserted (struct request *rq); +bool blk_mq_sched_try_merge(struct request_queue *q, struct bio =
*bio);
block/blk-mq-sched.h line 35
Quoted 1 line
block/blk-mq-sched.h new file +1
-0+bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio =
*bio);
block/blk-mq-sched.h line 36
Quoted 1 line
block/blk-mq-sched.h new file +1
-0+bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct =
request *rq);
Quoted 48 lines
block/blk-mq-sched.h new file +48
-0+ +void blk_mq_sched_dispatch_requests (struct blk_mq_hw_ctx *hctx); + +static inline bool +blk_mq_sched_bio_merge (struct request_queue *q,struct bio *bio) +{ + struct elevator_queue *e =3D q->elevator; + +if (!e ||blk_queue_nomerges (q) || !bio_mergeable (bio)) +return false; + +return __blk_mq_sched_bio_merge (q, bio); +} + +static inline int blk_mq_sched_get_rq_priv (struct request_queue *q, +struct request *rq) +{ + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.get_rq_priv) +return e->type->ops.mq.get_rq_priv (q, rq); + +return 0 ; +} + +static inline void blk_mq_sched_put_rq_priv (struct request_queue *q, +struct request *rq) +{ + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.put_rq_priv) + e->type->ops.mq.put_rq_priv (q, rq); +} + +static inline void blk_mq_sched_put_request (struct request *rq) +{ + struct request_queue *q =3D rq->q; + struct elevator_queue *e =3D q->elevator; + bool do_free =3D true; + +wbt_done (q->rq_wb, &rq->issue_stat); + +if (rq->rq_flags &RQF_ELVPRIV ) { +blk_mq_sched_put_rq_priv (rq->q, rq); +if (rq->elv.icq) { +put_io_context (rq->elv.icq->ioc); + rq->elv.icq =3D NULL; + }
block/blk-mq-sched.h
Quoted 10 lines
block/blk-mq-sched.h new file +10
-0+ } + +if (e && e->type->ops.mq.put_request) + do_free =3D !e->type->ops.mq.put_request(rq); +if (do_free) +blk_mq_finish_request (rq); +} + +static inline void +blk_mq_sched_insert_request(struct request *rq, bool at_head, bool =
run_queue,
Quoted 14 lines
block/blk-mq-sched.h new file +14
-0+ bool async) +{ + struct request_queue *q =3D rq->q; + struct elevator_queue *e =3D q->elevator; + struct blk_mq_ctx *ctx =3D rq->mq_ctx; + struct blk_mq_hw_ctx *hctx =3D blk_mq_map_queue(q, ctx->cpu); + +if (e && e->type->ops.mq.insert_requests) { +LIST_HEAD (list); + +list_add (&rq->queuelist, &list); + e->type->ops.mq.insert_requests (hctx, &list, at_head); + }else { +spin_lock (&ctx->lock);
block/blk-mq-sched.h
Quoted 10 lines
block/blk-mq-sched.h new file +10
-0+__blk_mq_insert_request (hctx, rq, at_head); +spin_unlock (&ctx->lock); + } + +if (run_queue) +blk_mq_run_hw_queue (hctx, async); +} + +static inline void +blk_mq_sched_insert_requests(struct request_queue *q, struct =
blk_mq_ctx *ctx,
block/blk-mq-sched.h line 119
Quoted 1 line
block/blk-mq-sched.h new file +1
-0+ struct list_head *list, bool =
run_queue_async)
Quoted 6 lines
block/blk-mq-sched.h new file +6
-0+{ + struct blk_mq_hw_ctx *hctx =3D blk_mq_map_queue(q, ctx->cpu); + struct elevator_queue *e =3D hctx->queue->elevator; + +if (e && e->type->ops.mq.insert_requests) + e->type->ops.mq.insert_requests (hctx, list, false);
block/blk-mq-sched.h
Quoted 10 lines
block/blk-mq-sched.h new file +10
-0+else +blk_mq_insert_requests (hctx, ctx, list); + +blk_mq_run_hw_queue (hctx, run_queue_async); +} + +static inline void +blk_mq_sched_dispatch_shadow_requests(struct blk_mq_hw_ctx *hctx, + struct list_head *rq_list, + struct request =
*(*get_sched_rq)(struct blk_mq_hw_ctx *))
block/blk-mq-sched.h
Quoted 5 lines
block/blk-mq-sched.h new file +5
-0+{ + do { + struct request *rq; + + rq =3D blk_mq_sched_request_from_shadow(hctx, =
get_sched_rq);
Quoted 11 lines
block/blk-mq-sched.h new file +11
-0+if (!rq) +break ; + +list_add_tail (&rq->queuelist, rq_list); + }while (1 ); +} + +static inline bool +blk_mq_sched_allow_merge (struct request_queue *q,struct request *rq, +struct bio *bio) +{
block/blk-mq-sched.h
Quoted 10 lines
block/blk-mq-sched.h new file +10
-0+ struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true; +} + +static inline void +blk_mq_sched_completed_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq)
block/blk-mq.c struct request *blk_mq_alloc_request_hctx(struct =
Quoted 104 lines
block/blk-mq-sched.h new file +48
-0+{ + struct elevator_queue *e =3D hctx->queue->elevator; + +if (e && e->type->ops.mq.completed_request) + e->type->ops.mq.completed_request (hctx, rq); + +if (test_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state)) { +clear_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state); +blk_mq_run_hw_queue (hctx, true); + } +} + +static inline void blk_mq_sched_started_request (struct request *rq) +{ + struct request_queue *q =3D rq->q; + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.started_request) + e->type->ops.mq.started_request (rq); +} + +static inline void blk_mq_sched_requeue_request (struct request *rq) +{ + struct request_queue *q =3D rq->q; + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.requeue_request) + e->type->ops.mq.requeue_request (rq); +} + +static inline bool blk_mq_sched_has_work (struct blk_mq_hw_ctx *hctx) +{ + struct elevator_queue *e =3D hctx->queue->elevator; + +if (e && e->type->ops.mq.has_work) +return e->type->ops.mq.has_work (hctx); + +return false; +} + +/* +* Returns true if this is an internal shadow request +*/ +static inline bool blk_mq_sched_rq_is_shadow (struct request *rq) +{ + return (rq->rq_flags & RQF_ALLOCED) !=3D 0; +} +#endif block/blk-mq.c +1
-0@@ -32,6 +32,7 @@#include "blk-mq-tag.h" #include "blk-stat.h" #include "blk-wbt.h" +#include "blk-mq-sched.h" =20
staticDEFINE_MUTEX(all_q_mutex);
staticLIST_HEAD(all_q_list);block/blk-mq.c +2
-1@@ -41,7 +42,8 @@ static LIST_HEAD(all_q_list);*/ static bool blk_mq_hctx_has_pending (struct blk_mq_hw_ctx *hctx) { -return sbitmap_any_bit_set (&hctx->ctx_map); +return sbitmap_any_bit_set (&hctx->ctx_map) || +blk_mq_sched_has_work (hctx); }=20
/*block/blk-mq.c +1
-3@@ -242,26 +244,21 @@ EXPORT_SYMBOL_GPL(__blk_mq_alloc_request);struct request *blk_mq_alloc_request (struct request_queue *q,int rw,unsigned int flags) { -struct blk_mq_ctx *ctx; -struct blk_mq_hw_ctx *hctx; -struct request *rq;struct blk_mq_alloc_data alloc_data; +struct request *rq;int ret;=20
ret =3D blk_queue_enter(q, flags & BLK_MQ_REQ_NOWAIT); if (ret) return ERR_PTR(ret);=20
block/blk-mq.c +1
-5- ctx =3D blk_mq_get_ctx(q); - hctx =3D blk_mq_map_queue(q, ctx->cpu); -blk_mq_set_alloc_data (&alloc_data, q, flags, ctx, hctx); - rq =3D __blk_mq_alloc_request(&alloc_data, rw); -blk_mq_put_ctx (ctx); + rq =3D blk_mq_sched_get_request(q, NULL, rw, &alloc_data);=20
block/blk-mq.c +4
-2-if (!rq) { -blk_queue_exit (q); +blk_mq_put_ctx (alloc_data.ctx); +blk_queue_exit (q); + +if (!rq)return ERR_PTR(-EWOULDBLOCK);block/blk-mq.c +0
-1- }=20
rq->__data_len =3D 0; rq->__sector =3D (sector_t) -1;block/blk-mq.c +0
-0@@ -321,12 +318,14 @@ struct request *blk_mq_alloc_request_hctx(struct =
request_queue *q, int rw,
Quoted 4 lines
block/blk-mq.c +0
-0}EXPORT_SYMBOL_GPL (blk_mq_alloc_request_hctx);=20
-void __blk_mq_free_request(structblk_mq_hw_ctx*hctx, struct =
blk_mq_ctx *ctx,
block/blk-mq.c
Quoted 2 lines
block/blk-mq.c +1
-1- struct request *rq) +void __blk_mq_finish_request(struct blk_mq_hw_ctx *hctx, struct =
blk_mq_ctx *ctx,
block/blk-mq.c void __blk_mq_free_request(struct blk_mq_hw_ctx =
Quoted 11 lines
block/blk-mq.c +1
-0+ struct request *rq){ const int tag =3D rq->tag; struct request_queue *q =3D rq->q;=20
block/blk-mq.c +2
-0+blk_mq_sched_completed_request (hctx, rq); +if (rq->rq_flags & RQF_MQ_INFLIGHT) atomic_dec(&hctx->nr_active);=20
block/blk-mq.c +0
-0@@ -339,18 +338,23 @@ void __blk_mq_free_request(struct blk_mq_hw_ctx =
*hctx, struct blk_mq_ctx *ctx,
Quoted 10 lines
block/blk-mq.c +0
-0blk_queue_exit (q); }=20
block/blk-mq.c +1
-1-static void blk_mq_free_hctx_request(struct blk_mq_hw_ctx *hctx, +static void blk_mq_finish_hctx_request(struct blk_mq_hw_ctx *hctx,struct request *rq)
{ struct blk_mq_ctx *ctx =3D rq->mq_ctx; =20 ctx->rq_completed[rq_is_sync(rq)]++;
block/blk-mq.c void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
Quoted 7 lines
block/blk-mq.c +6
-1-__blk_mq_free_request (hctx, ctx, rq); +__blk_mq_finish_request (hctx, ctx, rq); +} + +void blk_mq_finish_request (struct request *rq) +{ + blk_mq_finish_hctx_request(blk_mq_map_queue(rq->q, =
rq->mq_ctx->cpu), rq);
block/blk-mq.c
Quoted 5 lines
}
=20
voidblk_mq_free_request(struct request *rq)
{block/blk-mq.c +0
-1- blk_mq_free_hctx_request(blk_mq_map_queue(rq->q, =
rq->mq_ctx->cpu), rq);
block/blk-mq.c static void __blk_mq_requeue_request(struct =
Quoted 14 lines
block/blk-mq.c +1
-0+blk_mq_sched_put_request (rq);}
EXPORT_SYMBOL_GPL(blk_mq_free_request);
=20block/blk-mq.c +0
-0@@ -468,6 +472,8 @@ void blk_mq_start_request(struct request *rq) { struct request_queue *q =3D rq->q;=20
block/blk-mq.c +2
-0+blk_mq_sched_started_request (rq); +trace_block_rq_issue(q, rq); =20 rq->resid_len =3D blk_rq_bytes(rq);block/blk-mq.c +0
-0@@ -516,6 +522,7 @@ static void __blk_mq_requeue_request(struct =
request *rq)
block/blk-mq.c static void blk_mq_requeue_work(struct =
Quoted 8 lines
=20
trace_block_rq_requeue(q, rq); wbt_requeue(q->rq_wb, &rq->issue_stat);block/blk-mq.c +1
-0+blk_mq_sched_requeue_request (rq);=20
if (test_and_clear_bit(REQ_ATOM_STARTED, &rq->atomic_flags)) { if (q->dma_drain_size && blk_rq_bytes(rq))block/blk-mq.c +0
-0@@ -550,13 +557,13 @@ static void blk_mq_requeue_work(struct =
work_struct *work)
Quoted 9 lines
=20
rq->rq_flags &=3D ~RQF_SOFTBARRIER; list_del_init(&rq->queuelist);block/blk-mq.c +1
-1-blk_mq_insert_request (rq, true, false, false); +blk_mq_sched_insert_request (rq, true, false, false);} =20 while (!list_empty(&rq_list)) { rq =3D list_entry(rq_list.next, struct request, =
queuelist);
block/blk-mq.c static bool blk_mq_attempt_merge(struct =
Quoted 7 lines
list_del_init(&rq->queuelist);block/blk-mq.c +1
-1-blk_mq_insert_request (rq, false, false, false); +blk_mq_sched_insert_request (rq, false, false, false);} =20 blk_mq_run_hw_queues(q, false);block/blk-mq.c +0
-0@@ -762,8 +769,16 @@ static bool blk_mq_attempt_merge(struct =
request_queue *q,
block/blk-mq.c bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx =
Quoted 17 lines
=20
if (!blk_rq_merge_ok(rq, bio)) continue;block/blk-mq.c +2
-0+if (!blk_mq_sched_allow_merge (q, rq, bio)) +break ;=20
el_ret =3D blk_try_merge(rq, bio);block/blk-mq.c +6
-0+ if (el_ret =3D=3D ELEVATOR_NO_MERGE) +continue ; + +if (!blk_mq_sched_allow_merge (q, rq, bio)) +break ; +if (el_ret =3D=3D ELEVATOR_BACK_MERGE) { if (bio_attempt_back_merge(q, rq, bio)) { ctx->rq_merged++;block/blk-mq.c +0
-0@@ -905,41 +920,6 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx =
*hctx, struct list_head *list)
Quoted 5 lines
block/blk-mq.c +0
-0return ret !=3D BLK_MQ_RQ_QUEUE_BUSY; }=20
-/*
- * Run this hardware queue, pulling any software queues mapped to it =
in.
Quoted 1 line
- * Note that this function currently has various problems around =
ordering
Quoted 1 line
- * of IO. In particular, we'd like FIFO behaviour on handling =
existing
block/blk-mq.c static void __blk_mq_run_hw_queue(struct =
Quoted 35 lines
- * items on the
hctx->dispatchlist. Ignore that for now.
- */block/blk-mq.c +0
-29-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. -*/ -blk_mq_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){ int srcu_idx;block/blk-mq.c +0
-0@@ -949,11 +929,11 @@ static void __blk_mq_run_hw_queue(struct =
blk_mq_hw_ctx *hctx)
block/blk-mq.c void __blk_mq_insert_request(struct =
Quoted 14 lines
=20
if (!(hctx->flags & BLK_MQ_F_BLOCKING)) { rcu_read_lock();block/blk-mq.c +1
-1-blk_mq_process_rq_list (hctx); +blk_mq_sched_dispatch_requests (hctx);rcu_read_unlock(); } else { srcu_idx =3D srcu_read_lock(&hctx->queue_rq_srcu);block/blk-mq.c +1
-1-blk_mq_process_rq_list (hctx); +blk_mq_sched_dispatch_requests (hctx);srcu_read_unlock(&hctx->queue_rq_srcu, srcu_idx); } }block/blk-mq.c +0
-0@@ -1147,32 +1127,10 @@ void __blk_mq_insert_request(struct =
blk_mq_hw_ctx *hctx, struct request *rq,
Quoted 4 lines
block/blk-mq.c +0
-0blk_mq_hctx_mark_pending (hctx, ctx); }=20
-void blk_mq_insert_request(struct request *rq, boolat_head, bool =
run_queue,
Quoted 10 lines
block/blk-mq.c +0
-10- bool async) -{ - struct blk_mq_ctx *ctx =3D rq->mq_ctx; - struct request_queue *q =3D rq->q; - struct blk_mq_hw_ctx *hctx =3D blk_mq_map_queue(q, ctx->cpu); - -spin_lock (&ctx->lock); -__blk_mq_insert_request (hctx, rq, at_head); -spin_unlock (&ctx->lock); -
block/blk-mq.c void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
Quoted 10 lines
block/blk-mq.c +1
-9-if (run_queue) -blk_mq_run_hw_queue (hctx, async); -} - -static void blk_mq_insert_requests (struct request_queue *q, -struct blk_mq_ctx *ctx, -struct list_head *list, -int depth, -bool from_schedule) +void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct =
blk_mq_ctx *ctx,
Quoted 9 lines
block/blk-mq.c +1
-0+ struct list_head *list)=20
{block/blk-mq.c +0
-4- struct blk_mq_hw_ctx *hctx =3D blk_mq_map_queue(q, ctx->cpu); - -trace_block_unplug (q, depth, !from_schedule); -/* * preemption doesn't flush plug list, so it's possible ctx->cpu =
is
block/blk-mq.c static void blk_mq_insert_requests(struct =
Quoted 2 lines
* offline now
block/blk-mq.c +0
-0@@ -1188,8 +1146,6 @@ static void blk_mq_insert_requests(struct =
request_queue *q,
Quoted 8 lines
block/blk-mq.c +0
-2}blk_mq_hctx_mark_pending (hctx, ctx);spin_unlock (&ctx->lock); - -blk_mq_run_hw_queue (hctx, from_schedule); }=20
static int plug_ctx_cmp(void *priv, structlist_head*a, struct =
list_head *b)
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug =
Quoted 1 line
block/blk-mq.c +0
-0@@ -1225,9 +1181,10 @@ void blk_mq_flush_plug_list(struct blk_plug =
*plug, bool from_schedule)
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
Quoted 5 lines
block/blk-mq.c +0
-2BUG_ON (!rq->q); if (rq->mq_ctx !=3D this_ctx) {if (this_ctx) { - blk_mq_insert_requests(this_q, this_ctx, - &ctx_list, =
depth,
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug = · line 1184
Quoted 2 lines
block/blk-mq.c +1
-1- from_schedule); + trace_block_unplug(this_q, depth, =
from_schedule);
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug = · line 1185
Quoted 1 line
block/blk-mq.c +1
-0+ blk_mq_sched_insert_requests(this_q, =
this_ctx,
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug = · line 1186
Quoted 1 line
block/blk-mq.c +1
-0+ =
&ctx_list,
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug = · line 1187
Quoted 1 line
block/blk-mq.c +1
-0+ =
from_schedule);
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug =
Quoted 4 lines
block/blk-mq.c +0
-0}=20
this_ctx =3D rq->mq_ctx;block/blk-mq.c +0
-0@@ -1244,8 +1201,9 @@ void blk_mq_flush_plug_list(struct blk_plug =
*plug, bool from_schedule)
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
Quoted 4 lines
block/blk-mq.c +0
-1* on 'ctx_list'. Do those. */ if (this_ctx) { - blk_mq_insert_requests(this_q, this_ctx, &ctx_list, =
depth,
block/blk-mq.c void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
Quoted 3 lines
block/blk-mq.c +2
-1- from_schedule); +trace_block_unplug (this_q, depth, from_schedule); + blk_mq_sched_insert_requests(this_q, this_ctx, =
&ctx_list,
block/blk-mq.c static inline bool =
Quoted 5 lines
block/blk-mq.c +1
-0+ from_schedule); } }=20
block/blk-mq.c +0
-0@@ -1283,46 +1241,32 @@ static inline bool =
blk_mq_merge_queue_io(struct blk_mq_hw_ctx *hctx,
block/blk-mq.c static inline bool blk_mq_merge_queue_io(struct blk_mq_hw_ctx *hctx,
Quoted 12 lines
block/blk-mq.c +0
-0}=20
spin_unlock(&ctx->lock);block/blk-mq.c +1
-1-__blk_mq_free_request (hctx, ctx, rq); +__blk_mq_finish_request (hctx, ctx, rq);return true; } }=20
block/blk-mq.c +0
-3-static struct request *blk_mq_map_request(struct request_queue *q, - struct bio *bio, - struct blk_mq_alloc_data =
*data)
Quoted 17 lines
block/blk-mq.c +0
-17-{ -struct blk_mq_hw_ctx *hctx; -struct blk_mq_ctx *ctx; -struct request *rq; - -blk_queue_enter_live (q); - ctx =3D blk_mq_get_ctx(q); - hctx =3D blk_mq_map_queue(q, ctx->cpu); - -trace_block_getrq (q, bio, bio->bi_opf); -blk_mq_set_alloc_data (data, q,0 , ctx, hctx); - rq =3D __blk_mq_alloc_request(data, bio->bi_opf); - - data->hctx->queued++; -return rq; -} -
Quoted 1 line
static void blk_mq_try_issue_directly(struct request *rq,
blk_qc_t=
*cookie)
block/blk-mq.c
Quoted 4 lines
{
block/blk-mq.c +0
-1-int ret;struct request_queue *q =3D rq->q;block/blk-mq.c +0
-1- struct blk_mq_hw_ctx *hctx =3D blk_mq_map_queue(q, =
rq->mq_ctx->cpu);
block/blk-mq.c
Quoted 6 lines
struct blk_mq_queue_data bd =3D { .rq =3D rq, .list =3D NULL, .last =3D 1 };block/blk-mq.c +0
-1- blk_qc_t new_cookie =3D blk_tag_to_qc_t(rq->tag, =
hctx->queue_num);
block/blk-mq.c static void blk_mq_try_issue_directly(struct =
Quoted 17 lines
block/blk-mq.c +6
-0+struct blk_mq_hw_ctx *hctx; +blk_qc_t new_cookie; +int ret; + +if (q->elevator) + goto insert;=20
block/blk-mq.c +1
-0+ hctx =3D blk_mq_map_queue(q, rq->mq_ctx->cpu);if (blk_mq_hctx_stopped(hctx)) goto insert;=20
block/blk-mq.c +2
-0+ new_cookie =3D blk_tag_to_qc_t(rq->tag, hctx->queue_num); +/*
* For OK queue, we are done. For error, kill it. Any other
* error (busy), just add it to our list as we previouslyblock/blk-mq.c +0
-0@@ -1344,7 +1288,7 @@ static void blk_mq_try_issue_directly(struct =
request *rq, blk_qc_t *cookie)
block/blk-mq.c static blk_qc_t blk_mq_make_request(struct =
Quoted 9 lines
block/blk-mq.c +0
-0}=20
insert:block/blk-mq.c +1
-1-blk_mq_insert_request (rq, false, true, true); +blk_mq_sched_insert_request (rq, false, true, true);}
=20
/*block/blk-mq.c +0
-0@@ -1377,9 +1321,14 @@ static blk_qc_t blk_mq_make_request(struct =
request_queue *q, struct bio *bio)
block/blk-mq.c static blk_qc_t blk_mq_make_request(struct = · line 1321
Quoted 1 line
block/blk-mq.c +0
-0blk_attempt_plug_merge(q, bio, &request_count, =
&same_queue_rq))
block/blk-mq.c static blk_qc_t blk_mq_make_request(struct =
Quoted 15 lines
block/blk-mq.c +0
-0return BLK_QC_T_NONE ;=20
block/blk-mq.c +3
-0+if (blk_mq_sched_bio_merge (q, bio)) +return BLK_QC_T_NONE ; +wb_acct =3D wbt_wait(q->rq_wb, bio, NULL);=20
block/blk-mq.c +3
-1- rq =3D blk_mq_map_request(q, bio, &data); +trace_block_getrq (q, bio, bio->bi_opf); + + rq =3D blk_mq_sched_get_request(q, bio, bio->bi_opf, &data);if (unlikely(!rq)) { __wbt_done(q->rq_wb, wb_acct); return BLK_QC_T_NONE;block/blk-mq.c +0
-0@@ -1441,6 +1390,12 @@ static blk_qc_t blk_mq_make_request(struct =
request_queue *q, struct bio *bio)
Quoted 9 lines
block/blk-mq.c +0
-0goto done; }=20
block/blk-mq.c +6
-0+if (q->elevator) { +blk_mq_put_ctx (data.ctx); +blk_mq_bio_to_request (rq, bio); +blk_mq_sched_insert_request (rq, false, true, true); + goto done; + }
Quoted 3 lines
if (!blk_mq_merge_queue_io(data.hctx, data.ctx, rq, bio)) {
/*
* For a SYNC request, send it to the hardware =immediately. For
block/blk-mq.c static blk_qc_t blk_sq_make_request(struct =
Quoted 1 line
block/blk-mq.c +0
-0@@ -1486,9 +1441,14 @@ static blk_qc_t blk_sq_make_request(struct =
request_queue *q, struct bio *bio)
block/blk-mq.c static blk_qc_t blk_sq_make_request(struct =
Quoted 16 lines
block/blk-mq.c +0
-0}else request_count =3D blk_plug_queued_count(q);=20
block/blk-mq.c +3
-0+if (blk_mq_sched_bio_merge (q, bio)) +return BLK_QC_T_NONE ; +wb_acct =3D wbt_wait(q->rq_wb, bio, NULL);=20
block/blk-mq.c +3
-1- rq =3D blk_mq_map_request(q, bio, &data); +trace_block_getrq (q, bio, bio->bi_opf); + + rq =3D blk_mq_sched_get_request(q, bio, bio->bi_opf, &data);if (unlikely(!rq)) { __wbt_done(q->rq_wb, wb_acct); return BLK_QC_T_NONE;block/blk-mq.c +0
-0@@ -1538,6 +1498,12 @@ static blk_qc_t blk_sq_make_request(struct =
request_queue *q, struct bio *bio)
Quoted 9 lines
block/blk-mq.c +0
-0return cookie; }=20
block/blk-mq.c +6
-0+if (q->elevator) { +blk_mq_put_ctx (data.ctx); +blk_mq_bio_to_request (rq, bio); +blk_mq_sched_insert_request (rq, false, true, true); + goto done; + }
Quoted 3 lines
if (!blk_mq_merge_queue_io(data.hctx, data.ctx, rq, bio)) {
/*
* For a SYNC request, send it to the hardware =immediately. For
block/blk-mq.c static blk_qc_t blk_sq_make_request(struct =
Quoted 1 line
block/blk-mq.c +0
-0@@ -1550,6 +1516,7 @@ static blk_qc_t blk_sq_make_request(struct =
request_queue *q, struct bio *bio)
block/blk-mq.c void blk_mq_free_rq_map(struct blk_mq_tag_set =
Quoted 8 lines
block/blk-mq.c +0
-0}=20
blk_mq_put_ctx(data.ctx); +done: return cookie; }=20
block/blk-mq.c +0
-0@@ -1558,7 +1525,7 @@ void blk_mq_free_rq_map(struct blk_mq_tag_set =
*set, struct blk_mq_tags *tags,
block/blk-mq.h struct blk_mq_tags *blk_mq_init_rq_map(struct =
Quoted 13 lines
block/blk-mq.c +0
-0{struct page *page;=20
block/blk-mq.c +1
-1-if (tags->rqs && set->ops->exit_request) { +if (tags->rqs && set && set->ops->exit_request) {int i; =20 for (i =3D 0; i < tags->nr_tags; i++) {block/blk-mq.h +0
-0@@ -47,7 +47,8 @@ struct blk_mq_tags *blk_mq_init_rq_map(struct =
blk_mq_tag_set *set,
Quoted 2 lines
block/blk-mq.h +0
-0*/ void __blk_mq_insert_request(struct
blk_mq_hw_ctx*hctx, struct =
request *rq,
block/blk-mq.h
Quoted 3 lines
bool at_head);block/blk-mq.h +1
-1- +void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct =
blk_mq_ctx *ctx,
block/blk-mq.h static inline void blk_mq_set_alloc_data(struct =
Quoted 5 lines
block/blk-mq.h +1
-0+ struct list_head *list);/*
* CPU hotplug helpers
*/block/blk-mq.h +0
-0@@ -123,8 +124,9 @@ static inline void blk_mq_set_alloc_data(struct =
blk_mq_alloc_data *data,
Quoted 2 lines
block/blk-mq.h +0
-0*/ void blk_mq_rq_ctx_init(struct
request_queue*q, structblk_mq_ctx=
*ctx,
Quoted 2 lines
struct request *rq, unsigned int op);-void __blk_mq_free_request(struct
blk_mq_hw_ctx*hctx, struct =
blk_mq_ctx *ctx,
Quoted 1 line
+void __blk_mq_finish_request(struct
blk_mq_hw_ctx*hctx, struct =
blk_mq_ctx *ctx,
block/elevator.c static int elv_iosched_allow_bio_merge(struct =
Quoted 18 lines
struct request *rq); +void blk_mq_finish_request(struct request *rq); struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data, unsigned int op);=20
block/elevator.c +0
-0@@ -40,6 +40,7 @@#include <trace/events/block.h> =20
#include "blk.h"
+#include "blk-mq-sched.h"
=20
staticDEFINE_SPINLOCK(elv_list_lock);
staticLIST_HEAD(elv_list);block/elevator.c +0
-0@@ -58,7 +59,9 @@ static int elv_iosched_allow_bio_merge(struct =
request *rq, struct bio *bio)
block/elevator.c static int elv_iosched_allow_bio_merge(struct request *rq, struct bio *bio)
Quoted 7 lines
block/elevator.c +0
-0struct request_queue *q =3D rq->q; struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-1-if (e->type->ops.sq.elevator_allow_bio_merge_fn) +if (e->uses_mq && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + else if (!e->uses_mq && =
e->type->ops.sq.elevator_allow_bio_merge_fn)
Quoted 1 line
return e->type->ops.sq.elevator_allow_bio_merge_fn(q, =
rq, bio);
block/elevator.c struct elevator_queue *elevator_alloc(struct =
Quoted 3 lines
=20
return 1;block/elevator.c +0
-0@@ -163,6 +166,7 @@ struct elevator_queue *elevator_alloc(struct =
request_queue *q,
block/elevator.c int elevator_init(struct request_queue *q, char =
Quoted 8 lines
block/elevator.c +1
-0kobject_init (&eq->kobj, &elv_ktype);mutex_init (&eq->sysfs_lock);hash_init (eq->hash); + eq->uses_mq =3D e->uses_mq;=20
return eq; }block/elevator.c +0
-0@@ -219,12 +223,19 @@ int elevator_init(struct request_queue *q, char =
*name)
block/elevator.c void elv_rqhash_del(struct request_queue *q, =
Quoted 33 lines
block/elevator.c +5
-1if (!e) {printk (KERN_ERR "Default I/O scheduler not found. " \ -"Using noop.\n" ); +"Using noop/none.\n" ); +if (q->mq_ops) { +elevator_put (e); +return 0 ; + } e =3D elevator_get("noop", false); } }=20
block/elevator.c +4
-1- err =3D e->ops.sq.elevator_init_fn(q, e); +if (e->uses_mq) + err =3D e->ops.mq.init_sched(q, e); +else + err =3D e->ops.sq.elevator_init_fn(q, e);if (err) elevator_put(e); return err;block/elevator.c +3
-1@@ -234,7 +245,9 @@ EXPORT_SYMBOL(elevator_init);void elevator_exit (struct elevator_queue *e) {mutex_lock (&e->sysfs_lock); -if (e->type->ops.sq.elevator_exit_fn) +if (e->uses_mq && e->type->ops.mq.exit_sched) + e->type->ops.mq.exit_sched (e); +else if (!e->uses_mq && e->type->ops.sq.elevator_exit_fn) e->type->ops.sq.elevator_exit_fn (e);mutex_unlock (&e->sysfs_lock);=20
block/elevator.c +0
-0@@ -253,6 +266,7 @@ void elv_rqhash_del(struct request_queue *q, =
struct request *rq)
block/elevator.c void elv_rqhash_add(struct request_queue *q, =
Quoted 8 lines
block/elevator.c +1
-0if (ELV_ON_HASH (rq))__elv_rqhash_del (rq); } +EXPORT_SYMBOL_GPL (elv_rqhash_del);=20
voidelv_rqhash_add(struct request_queue *q, struct request *rq){block/elevator.c +0
-0@@ -262,6 +276,7 @@ void elv_rqhash_add(struct request_queue *q, =
struct request *rq)
Quoted 6 lines
block/elevator.c +1
-0hash_add (e->hash, &rq->hash,rq_hash_key (rq)); rq->rq_flags |=3D RQF_HASHED; } +EXPORT_SYMBOL_GPL (elv_rqhash_add);=20
void elv_rqhash_reposition(structrequest_queue*q, struct request =
*rq)
block/elevator.c int elv_merge(struct request_queue *q, struct =
Quoted 2 lines
{
block/elevator.c +0
-0@@ -443,7 +458,9 @@ int elv_merge(struct request_queue *q, struct =
request **req, struct bio *bio)
block/elevator.c int elv_merge(struct request_queue *q, struct =
Quoted 11 lines
block/elevator.c +0
-0return ELEVATOR_BACK_MERGE ; }=20
block/elevator.c +3
-1-if (e->type->ops.sq.elevator_merge_fn) +if (e->uses_mq && e->type->ops.mq.request_merge) +return e->type->ops.mq.request_merge (q, req, bio); +else if (!e->uses_mq && e->type->ops.sq.elevator_merge_fn)return e->type->ops.sq.elevator_merge_fn(q, req, bio); =20 return ELEVATOR_NO_MERGE;block/elevator.c +0
-0@@ -456,8 +473,7 @@ int elv_merge(struct request_queue *q, struct =
request **req, struct bio *bio)
block/elevator.c int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
Quoted 6 lines
block/elevator.c +1
-2* * Returns true if we merged, false otherwise */ -static bool elv_attempt_insert_merge (struct request_queue *q, -struct request *rq) +bool elv_attempt_insert_merge(struct request_queue *q, struct request =
*rq)
block/elevator.c void elv_merged_request(struct request_queue *q, =
Quoted 4 lines
block/elevator.c +0
-0{struct request *__rq;bool ret;@@ -495,7 +511,9 @@ void elv_merged_request(struct request_queue *q, =
struct request *rq, int type)
block/elevator.c void elv_merge_requests(struct request_queue *q, =
Quoted 11 lines
block/elevator.c +0
-0{ struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-1-if (e->type->ops.sq.elevator_merged_fn) +if (e->uses_mq && e->type->ops.mq.request_merged) + e->type->ops.mq.request_merged (q, rq, type); +else if (!e->uses_mq && e->type->ops.sq.elevator_merged_fn)e->type->ops.sq.elevator_merged_fn(q, rq, type);=20
if (type =3D=3DELEVATOR_BACK_MERGE)block/elevator.c +0
-0@@ -508,10 +526,15 @@ void elv_merge_requests(struct request_queue *q, =
struct request *rq,
Quoted 5 lines
block/elevator.c +0
-2struct request *next) { struct elevator_queue *e =3D q->elevator; - const int next_sorted =3D next->rq_flags & RQF_SORTED; -
block/elevator.c void elv_merge_requests(struct request_queue *q, struct request *rq,
Quoted 10 lines
block/elevator.c +8
-2-if (next_sorted && e->type->ops.sq.elevator_merge_req_fn) - e->type->ops.sq.elevator_merge_req_fn (q, rq, next); + bool next_sorted =3D false; + +if (e->uses_mq && e->type->ops.mq.requests_merged) + e->type->ops.mq.requests_merged (q, rq, next); +else if (e->type->ops.sq.elevator_merge_req_fn) { + next_sorted =3D next->rq_flags & RQF_SORTED; +if (next_sorted) + e->type->ops.sq.elevator_merge_req_fn(q, rq, =
next);
block/elevator.c void elv_bio_merged(struct request_queue *q, =
Quoted 5 lines
block/elevator.c +1
-0+ }=20
elv_rqhash_reposition(q, rq);=20
block/elevator.c +0
-0@@ -528,6 +551,9 @@ void elv_bio_merged(struct request_queue *q, =
struct request *rq,
block/elevator.c struct request *elv_latter_request(struct =
Quoted 10 lines
block/elevator.c +0
-0{ struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-0+if (WARN_ON_ONCE (e->uses_mq)) +return ; +if (e->type->ops.sq.elevator_bio_merged_fn) e->type->ops.sq.elevator_bio_merged_fn(q, rq, bio); }block/elevator.c +0
-0@@ -682,8 +708,11 @@ struct request *elv_latter_request(struct =
request_queue *q, struct request *rq)
block/elevator.c struct request *elv_former_request(struct =
Quoted 13 lines
block/elevator.c +0
-0{ struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-1-if (e->type->ops.sq.elevator_latter_req_fn) +if (e->uses_mq && e->type->ops.mq.next_request) +return e->type->ops.mq.next_request (q, rq); +else if (!e->uses_mq && e->type->ops.sq.elevator_latter_req_fn)return e->type->ops.sq.elevator_latter_req_fn(q, rq); + return NULL; }=20
block/elevator.c +0
-0@@ -691,7 +720,9 @@ struct request *elv_former_request(struct =
request_queue *q, struct request *rq)
block/elevator.c int elv_set_request(struct request_queue *q, =
Quoted 11 lines
block/elevator.c +0
-0{ struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-1-if (e->type->ops.sq.elevator_former_req_fn) +if (e->uses_mq && e->type->ops.mq.former_request) +return e->type->ops.mq.former_request (q, rq); +if (!e->uses_mq && e->type->ops.sq.elevator_former_req_fn)return e->type->ops.sq.elevator_former_req_fn(q, rq); return NULL; }block/elevator.c +0
-0@@ -701,6 +732,9 @@ int elv_set_request(struct request_queue *q, =
struct request *rq,
Quoted 8 lines
block/elevator.c +0
-0{ struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-0+if (WARN_ON_ONCE (e->uses_mq)) +return 0 ; +if (e->type->ops.sq.elevator_set_req_fn) return e->type->ops.sq.elevator_set_req_fn(q, rq, bio, =
gfp_mask);
block/elevator.c void elv_put_request(struct request_queue *q, =
Quoted 2 lines
return 0;block/elevator.c +0
-0@@ -710,6 +744,9 @@ void elv_put_request(struct request_queue *q, =
struct request *rq)
block/elevator.c int elv_may_queue(struct request_queue *q, =
Quoted 10 lines
block/elevator.c +0
-0{ struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-0+if (WARN_ON_ONCE (e->uses_mq)) +return ; +if (e->type->ops.sq.elevator_put_req_fn) e->type->ops.sq.elevator_put_req_fn(rq); }block/elevator.c +0
-0@@ -718,6 +755,9 @@ int elv_may_queue(struct request_queue *q, =
unsigned int op)
block/elevator.c void elv_completed_request(struct request_queue =
Quoted 10 lines
block/elevator.c +0
-0{ struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-0+if (WARN_ON_ONCE (e->uses_mq)) +return 0 ; +if (e->type->ops.sq.elevator_may_queue_fn) return e->type->ops.sq.elevator_may_queue_fn(q, op);=20
block/elevator.c +0
-0@@ -728,6 +768,9 @@ void elv_completed_request(struct request_queue =
*q, struct request *rq)
Quoted 10 lines
block/elevator.c +0
-0{ struct elevator_queue *e =3D q->elevator;=20
block/elevator.c +3
-0+if (WARN_ON_ONCE (e->uses_mq)) +return ; +/* * request is released from the driver, io must be done */
block/elevator.c int elv_register_queue(struct request_queue *q) · line 849
Quoted 5 lines
block/elevator.c +1
-1@@ -803,7 +846,7 @@ int elv_register_queue(struct request_queue *q) }kobject_uevent (&e->kobj,KOBJ_ADD ); e->registered =3D 1; -if (e->type->ops.sq.elevator_registered_fn) + if (!e->uses_mq && =
e->type->ops.sq.elevator_registered_fn)
Quoted 5 lines
block/elevator.c +0
-0e->type->ops.sq.elevator_registered_fn (q); }return error;@@ -891,9 +934,14 @@ EXPORT_SYMBOL_GPL(elv_unregister);static int elevator_switch(struct
request_queue*q, struct =
elevator_type *new_e)
Quoted 11 lines
{ struct elevator_queue *old =3D q->elevator;block/elevator.c +1
-1- bool registered =3D old->registered; + bool old_registered =3D false;int err;=20
block/elevator.c +5
-0+if (q->mq_ops) { +blk_mq_freeze_queue (q); +blk_mq_quiesce_queue (q); + } +
Quoted 2 lines
/* * Turn on BYPASS and drain all requests w/ elevator private =
data.
Quoted 1 line
* Block layer doesn't call into a quiesced elevator - all =
requests
block/elevator.c static int elevator_switch(struct request_queue =
Quoted 1 line
block/elevator.c +0
-0@@ -901,32 +949,52 @@ static int elevator_switch(struct request_queue =
*q, struct elevator_type *new_e)
block/elevator.c
Quoted 8 lines
block/elevator.c +2
-1* using INSERT_BACK. All requests have SOFTBARRIER set and no * merge happens either. */ -blk_queue_bypass_start (q); +if (old) { + old_registered =3D old->registered;=20
block/elevator.c +0
-1-/* unregister and clear all auxiliary data of the old elevator =
*/
block/elevator.c static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
Quoted 9 lines
block/elevator.c +2
-2-if (registered) -elv_unregister_queue (q); +if (!q->mq_ops) +blk_queue_bypass_start (q);=20
block/elevator.c +1
-3-spin_lock_irq (q->queue_lock); -ioc_clear_queue (q); -spin_unlock_irq (q->queue_lock); +/* unregister and clear all auxiliary data of the old =
elevator */
Quoted 9 lines
block/elevator.c +7
-0+if (old_registered) +elv_unregister_queue (q); + +spin_lock_irq (q->queue_lock); +ioc_clear_queue (q); +spin_unlock_irq (q->queue_lock); + }=20
/* allocate, init and register new elevator */
block/elevator.c static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
Quoted 8 lines
block/elevator.c +5
-3- err =3D new_e->ops.sq.elevator_init_fn(q, new_e); -if (err) - goto fail_init; +if (new_e) { +if (new_e->uses_mq) + err =3D new_e->ops.mq.init_sched(q, new_e); +else + err =3D new_e->ops.sq.elevator_init_fn(q, =
new_e);
Quoted 25 lines
block/elevator.c +2
-0+if (err) + goto fail_init;=20
block/elevator.c +0
-1-if (registered) {err =3D elv_register_queue(q); if (err) goto fail_register;block/elevator.c +2
-1- } + }else + q->elevator =3D NULL;=20
/* done, kill the old one and finish */block/elevator.c +10
-2-elevator_exit (old); -blk_queue_bypass_end (q); +if (old) { +elevator_exit (old); +if (!q->mq_ops) +blk_queue_bypass_end (q); + } + +if (q->mq_ops) { +blk_mq_unfreeze_queue (q); +blk_mq_start_stopped_hw_queues (q, true); + }=20
block/elevator.c static int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
Quoted 3 lines
block/elevator.c +2
-1-blk_add_trace_msg (q,"elv switch: %s" , new_e->elevator_name); +if (new_e) + blk_add_trace_msg(q, "elv switch: %s", =
new_e->elevator_name);
block/elevator.c static int elevator_switch(struct request_queue =
Quoted 6 lines
block/elevator.c +2
-0+else +blk_add_trace_msg (q,"elv switch: none" );=20
return 0;=20
block/elevator.c +0
-0@@ -934,9 +1002,16 @@ static int elevator_switch(struct request_queue =
*q, struct elevator_type *new_e)
block/elevator.c static int __elevator_change(struct =
Quoted 20 lines
block/elevator.c +0
-0elevator_exit (q->elevator);
fail_init:/* switch failed, restore and re-register old elevator */block/elevator.c +10
-3- q->elevator =3D old; -elv_register_queue (q); -blk_queue_bypass_end (q); +if (old) { + q->elevator =3D old; +elv_register_queue (q); +if (!q->mq_ops) +blk_queue_bypass_end (q); + } +if (q->mq_ops) { +blk_mq_unfreeze_queue (q); +blk_mq_start_stopped_hw_queues (q, true); + }=20
return err; }block/elevator.c +0
-0@@ -949,8 +1024,11 @@ static int __elevator_change(struct =
request_queue *q, const char *name)
block/elevator.c static int __elevator_change(struct =
Quoted 14 lines
block/elevator.c +0
-0char elevator_name[ELV_NAME_MAX ];struct elevator_type *e;=20
block/elevator.c +5
-2-if (!q->elevator) -return -ENXIO ; +/* +* Special case for mq, turn off scheduling +*/ +if (q->mq_ops && !strncmp (name,"none" ,4 )) +return elevator_switch (q,NULL );=20
strlcpy(elevator_name, name, sizeof(elevator_name)); e =3D elevator_get(strstrip(elevator_name), true);block/elevator.c +0
-0@@ -959,11 +1037,23 @@ static int __elevator_change(struct =
request_queue *q, const char *name)
block/elevator.c
Quoted 12 lines
block/elevator.c +0
-0return -EINVAL ; }=20
block/elevator.c +2
-1-if (!strcmp (elevator_name, q->elevator->type->elevator_name)) { +if (q->elevator && + !strcmp (elevator_name, q->elevator->type->elevator_name)) {elevator_put(e); return 0; }=20
block/elevator.c +2
-0+ if (!e->uses_mq && q->mq_ops) { + printk(KERN_ERR "blk-mq-sched: elv %s does not support =
mq\n", elevator_name);
block/elevator.c static int __elevator_change(struct request_queue *q, const char *name)
Quoted 5 lines
block/elevator.c +5
-0+elevator_put (e); +return -EINVAL ; + } +if (e->uses_mq && !q->mq_ops) { + printk(KERN_ERR "blk-mq-sched: elv %s is for mq\n", =
elevator_name);
block/elevator.c ssize_t elv_iosched_store(struct request_queue =
Quoted 8 lines
block/elevator.c +4
-0+elevator_put (e); +return -EINVAL ; + } +return elevator_switch(q, e); }=20
block/elevator.c +0
-0@@ -985,7 +1075,7 @@ ssize_t elv_iosched_store(struct request_queue =
*q, const char *name,
block/elevator.c ssize_t elv_iosched_store(struct request_queue =
Quoted 9 lines
block/elevator.c +0
-0{int ret;=20
block/elevator.c +1
-1-if (!q->elevator) +if (!q->mq_ops || q->request_fn)return count; =20 ret =3D __elevator_change(q, name);block/elevator.c +0
-0@@ -999,24 +1089,34 @@ ssize_t elv_iosched_store(struct request_queue =
*q, const char *name,
Quoted 20 lines
block/elevator.c +1
-1ssize_t elv_iosched_show (struct request_queue *q,char *name) { struct elevator_queue *e =3D q->elevator; -struct elevator_type *elv; + struct elevator_type *elv =3D NULL;struct elevator_type *__e; int len =3D 0;=20
block/elevator.c +1
-1-if (!q->elevator || !blk_queue_stackable (q)) +if (!blk_queue_stackable (q))return sprintf(name, "none\n");=20
block/elevator.c +4
-1- elv =3D e->type; +if (!q->elevator) + len +=3D sprintf(name+len, "[none] "); +else + elv =3D e->type;=20
spin_lock(&elv_list_lock); list_for_each_entry(__e, &elv_list, list) {
block/elevator.c
Quoted 2 lines
block/elevator.c +1
-1-if (!strcmp (elv->elevator_name, __e->elevator_name)) + if (elv && !strcmp(elv->elevator_name, =
__e->elevator_name)) {
Quoted 1 line
len +=3D sprintf(name+len, "[%s] ", =
elv->elevator_name);
block/elevator.c ssize_t elv_iosched_store(struct request_queue *q, const char *name,
Quoted 5 lines
block/elevator.c +4
-1-else +continue ; + } +if (__e->uses_mq && q->mq_ops) + len +=3D sprintf(name+len, "%s ", =
__e->elevator_name);
Quoted 2 lines
block/elevator.c +1
-0+else if (!__e->uses_mq && !q->mq_ops)len +=3D sprintf(name+len, "%s ", =
__e->elevator_name);
include/linux/blk-mq.h void blk_mq_free_tag_set(struct blk_mq_tag_set =
Quoted 30 lines
} spin_unlock(&elv_list_lock);=20
block/elevator.c +3
-0+if (q->mq_ops && q->elevator) + len +=3D sprintf(name+len, "none"); +len +=3D sprintf(len+name, "\n"); return len; }include/linux/blk-mq.h +0
-0@@ -22,6 +22,7 @@ struct blk_mq_hw_ctx {=20
unsigned long flags; /* BLK_MQ_F_* flags */=20
include/linux/blk-mq.h +1
-0+void *sched_data;struct request_queue *queue; struct blk_flush_queue *fq;=20
include/linux/blk-mq.h +0
-0@@ -156,6 +157,7 @@ enum {=20
BLK_MQ_S_STOPPED =3D 0, BLK_MQ_S_TAG_ACTIVE =3D 1,include/linux/blk-mq.h +1
-0+ BLK_MQ_S_SCHED_RESTART =3D 2,=20
BLK_MQ_MAX_DEPTH =3D 10240,=20
include/linux/blk-mq.h +0
-0@@ -179,7 +181,6 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set =
*set);
Quoted 2 lines
=20
void blk_mq_flush_plug_list(structblk_plug*plug, bool =
from_schedule);
Quoted 13 lines
=20
-voidblk_mq_insert_request(struct request *, bool, bool, bool); voidblk_mq_free_request(struct request *rq);
boolblk_mq_can_queue(struct blk_mq_hw_ctx *);
=20include/linux/elevator.h +0
-0@@ -77,6 +77,32 @@ struct elevator_opselevator_registered_fn *elevator_registered_fn; };=20
include/linux/elevator.h struct elevator_ops
Quoted 5 lines
include/linux/elevator.h +5
-0+struct blk_mq_alloc_data ; +struct blk_mq_hw_ctx ; + +struct elevator_mq_ops { + int (*init_sched)(struct request_queue *, struct elevator_type =
*);
include/linux/elevator.h struct elevator_ops
Quoted 3 lines
include/linux/elevator.h +3
-0+void (*exit_sched)(struct elevator_queue *); + + bool (*allow_merge)(struct request_queue *, struct request *, =
struct bio *);
include/linux/elevator.h
Quoted 2 lines
include/linux/elevator.h +2
-0+bool (*bio_merge)(struct blk_mq_hw_ctx *,struct bio *); + int (*request_merge)(struct request_queue *q, struct request **, =
struct bio *);
include/linux/elevator.h
Quoted 1 line
include/linux/elevator.h +1
-0+ void (*request_merged)(struct request_queue *, struct request *, =
int);
include/linux/elevator.h
Quoted 1 line
include/linux/elevator.h +1
-0+ void (*requests_merged)(struct request_queue *, struct request =
*, struct request *);
include/linux/elevator.h
Quoted 1 line
include/linux/elevator.h +1
-0+ struct request *(*get_request)(struct request_queue *, unsigned =
int, struct blk_mq_alloc_data *);
include/linux/elevator.h
Quoted 2 lines
include/linux/elevator.h +2
-0+bool (*put_request)(struct request *); + void (*insert_requests)(struct blk_mq_hw_ctx *, struct list_head =
*, bool);
include/linux/elevator.h
Quoted 1 line
include/linux/elevator.h +1
-0+ void (*dispatch_requests)(struct blk_mq_hw_ctx *, struct =
list_head *);
include/linux/elevator.h
Quoted 2 lines
include/linux/elevator.h +2
-0+bool (*has_work)(struct blk_mq_hw_ctx *); + void (*completed_request)(struct blk_mq_hw_ctx *, struct request =
*);
include/linux/elevator.h struct elevator_ops
Quoted 3 lines
include/linux/elevator.h +3
-0+void (*started_request)(struct request *); +void (*requeue_request)(struct request *); + struct request *(*former_request)(struct request_queue *, struct =
request *);
include/linux/elevator.h
Quoted 1 line
include/linux/elevator.h +1
-0+ struct request *(*next_request)(struct request_queue *, struct =
request *);
include/linux/elevator.h extern void elv_merge_requests(struct =
Quoted 31 lines
include/linux/elevator.h +4
-0+int (*get_rq_priv)(struct request_queue *,struct request *); +void (*put_rq_priv)(struct request_queue *,struct request *); +}; +#define
ELV_NAME_MAX(16)
=20
structelv_fs_entry{include/linux/elevator.h +2
-0@@ -96,12 +122,14 @@ struct elevator_type/* fields provided by elevator implementation */ union {struct elevator_ops sq; +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;=20
/* managed by elevator core */ char icq_cache_name[ELV_NAME_MAX + 5]; /* elvname + "_io_cq" */include/linux/elevator.h +1
-0@@ -125,6 +153,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 ); };=20
include/linux/elevator.h +0
-0@@ -141,6 +170,7 @@ extern void elv_merge_requests(struct =
request_queue *, struct request *,
Quoted 1 line
extern void elv_merged_request(struct
request_queue*, struct request =
*, int);
Quoted 3 lines
extern void elv_bio_merged(struct
request_queue*q, struct request *,struct bio *);+extern bool elv_attempt_insert_merge(struct
request_queue*, struct =
request *);
Quoted 1 line
extern void elv_requeue_request(struct
request_queue*, struct request =
*);
Quoted 1 line
extern struct request *elv_former_request(struct
request_queue*, =
struct request *);
Quoted 1 line
extern struct request *elv_latter_request(struct
request_queue*, =
struct request *);
Quoted 3 lines
--=20
2.7.4
=20
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
Quoted 13 lines · Paolo Valente
Quoted 13 lines
block/blk-mq-sched.c new file +13
-0+struct request *blk_mq_sched_get_request (struct request_queue *q, +struct bio *bio, +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);
Quoted 8 lines
block/blk-mq-sched.c line 328
Quoted 5 lines
block/blk-mq-sched.c new file +5
-0+ +blk_mq_set_alloc_data (data, q,0 , ctx, hctx); + +if (e && e->type->ops.mq.get_request) + rq = e->type->ops.mq.get_request (q, op, data);bio is not passed to the scheduler here. Yet bfq uses bio to get the blkcg (invoking
bio_blkcg). I'm not finding any workaround.
One important note here - what I'm posting is a work in progress, it's by no means set in stone. So when you find missing items like this, feel free to fix them up and send a patch. I will then fold in that patch. Or if you don't feel comfortable fixing it up, let me know, and I'll fix it up next time I touch it.
Quoted 12 lines
block/blk-mq-sched.c line 335
Quoted 7 lines
block/blk-mq-sched.c new file +7
-0+else + rq =__blk_mq_alloc_request (data, op); + +if (rq) { + rq->elv.icq =NULL ; +if (e && e->type->icq_cache) +blk_mq_sched_assign_ioc (q, rq, bio);bfq needs
rq->elv.icqto be consistent inbfq_get_request, but the needed initialization seems to occur only after mq.get_request is invoked.
Quoted 4 lines
Note: to minimize latency, I'm reporting immediately each problem that apparently cannot be solved by just modifying bfq. But, if the resulting higher number of micro-emails is annoying for you, I can buffer my questions, and send you cumulative emails less frequently.
That's perfectly fine, I prefer knowing earlier rather than later. But do also remember that it's fine to send a patch to fix those things up, you don't have to wait for me.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Paolo ValenteQuoted 6 lines · Paolo Valente
Quoted 6 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design.
Quoted 14 lines
block/mq-deadline.c line 533
Quoted 10 lines
Signed-off-by Jens Axboe <[email protected]>...
block/mq-deadline.c new file +8
-0+ +static bool dd_has_work (struct blk_mq_hw_ctx *hctx) +{ +struct deadline_data *dd = hctx->queue->elevator->elevator_data; + +return !list_empty_careful (&dd->dispatch) || + !list_empty_careful (&dd->fifo_list[0 ]) || + !list_empty_careful (&dd->fifo_list[1 ]);Just a request for clarification: if I'm not mistaken,
list_empty_carefulcan be used safely only if the only possible other concurrent access is a delete. Or am I missing something?
We can "solve" that with memory barriers. For now, it's safe to ignore on your end.
Signature · 1 line
Jens Axboe
Re: [PATCH 3/8] block: move rq_ioc() to blk.h
In reply to Paolo ValenteQuoted 6 lines · Paolo Valente
Quoted 5 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
We want to use it outside of
blk-core.c.
Quoted 6 lines
Hi Jens,
no hooks equivalent toelevator_init_icq_fnandelevator_exit_icq_fnare invoked. In particular, the second hook let bfq (as with cfq) know when it could finally exit the queue associated with the icq. I'm trying to figure out how to make it without these hooks/signals, but at no avail so far ...
Yep, those need to be added.
Signature · 1 line
Jens Axboe
Re: [PATCH 3/8] block: move rq_ioc() to blk.h
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Paolo Valente
Quoted 5 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
We want to use it outside of
blk-core.c.
Quoted 8 lines
Quoted 6 lines
Hi Jens,
no hooks equivalent toelevator_init_icq_fnandelevator_exit_icq_fnare invoked. In particular, the second hook let bfq (as with cfq) know when it could finally exit the queue associated with the icq. I'm trying to figure out how to make it without these hooks/signals, but at no avail so far ...Yep, those need to be added.
Done, pushed out.
Signature · 1 line
Jens Axboe
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Paolo ValenteQuoted 11 lines · Paolo Valente
block/blk-mq-sched.c line 335
Quoted 7 lines
block/blk-mq-sched.c new file +7
-0+else + rq =__blk_mq_alloc_request (data, op); + +if (rq) { + rq->elv.icq =NULL ; +if (e && e->type->icq_cache) +blk_mq_sched_assign_ioc (q, rq, bio);bfq needs
rq->elv.icqto be consistent inbfq_get_request, but the needed initialization seems to occur only after mq.get_request is invoked.
Can you do it from get/put_rq_priv? The icq is assigned there. If not, we can redo this part, not a big deal.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeT24gMTIvMTcvMjAxNiAwMToxMiBBTSwgSmVucyBBeGJvZSB3cm90ZToNCj4gK3N0YXRpYyBib29s IGRkX3B1dF9yZXF1ZXN0KHN0cnVjdCByZXF1ZXN0ICpycSkNCj4gK3sNCj4gKwkvKg0KPiArCcKg KiBJZiBpdCdzIGEgcmVhbCByZXF1ZXN0LCB3ZSBqdXN0IGhhdmUgdG8NCmZyZWUgaXQuIEZvciBh IHNoYWRvdw0KPiArCcKgKiByZXF1ZXN0LCB3ZSBzaG91bGQgb25seSBmcmVlIGl0IGlmIHdlIGhh dmVuJ3Qgc3RhcnRlZCBpdC4gQQ0KPiArCcKgKiBzdGFydGVkIHJlcXVlc3QgaXMgbWFwcGVkIHRv IGEgcmVhbCBvbmUsIGFuZCB0aGUNCnJlYWwgb25lIHdpbGwNCj4gKwnCoCogZnJlZSBpdC4gV2Ug Y2FuIGdldCBoZXJlIHdpdGggcmVxdWVzdCBtZXJnZXMsIHNpbmNlIHdlIHRoZW4NCj4gKwnCoCog ZnJlZSB0aGUgcmVxdWVzdCBiZWZvcmUgd2Ugc3RhcnQvaXNzdWUgaXQuDQo+ICsJwqAqLw0KPiAr CQ0KaWYgKCFibGtfbXFfc2NoZWRfcnFfaXNfc2hhZG93KHJxKSkNCj4gKwkJcmV0dXJuIGZhbHNl Ow0KPiArDQo+ICsJaWYgKCEocnEtPnJxX2ZsYWdzICYgUlFGX1NUQVJURUQpKSB7DQo+ICsJCXN0 cnVjdCByZXF1ZXN0X3F1ZXVlICpxDQo9IHJxLT5xOw0KPiArCQlzdHJ1Y3QgZGVhZGxpbmVfZGF0 YSAqZGQgPSBxLT5lbGV2YXRvci0+ZWxldmF0b3JfZGF0YTsNCj4gKw0KPiArCQkvKg0KPiArCQnC oCogSU8gY29tcGxldGlvbiB3b3VsZCBub3JtYWxseSBkbw0KdGhpcywgYnV0IGlmIHdlIG1lcmdl DQo+ICsJCcKgKiBhbmQgZnJlZSBiZWZvcmUgd2UgaXNzdWUgdGhlIHJlcXVlc3QsIGRyb3AgYm90 aCB0aGUNCj4gKwkJwqAqIHRhZyBhbmQgcXVldWUgcmVmDQo+ICsJCcKgKi8NCj4gKwkNCglibGtf bXFfc2NoZWRfZnJlZV9zaGFkb3dfcmVxdWVzdChkZC0+dGFncywgcnEpOw0KPiArCQlibGtfcXVl dWVfZXhpdChxKTsNCj4gKwl9DQo+ICsNCj4gKwlyZXR1cm4gdHJ1ZTsNCj4gK30NCg0KSGVsbG8g SmVucywNCg0KU2luY2UgdGhpcyBwYXRjaCBpcyB0aGUgZmlyc3QgcGF0Y2ggdGhhdCBpbnRyb2R1 Y2VzIGEgY2FsbCB0byBibGtfcXVldWVfZXhpdCgpDQpmcm9tIGEgbW9kdWxlIG90aGVyIHRoYW4g dGhlIGJsb2NrIGxheWVyIGNvcmUsIHNob3VsZG4ndCB0aGlzIHBhdGNoIGV4cG9ydCB0aGUNCmJs a19xdWV1ZV9leGl0KCkgZnVuY3Rpb24/IEFuIGF0dGVtcHQgdG8gYnVpbGQgbXEtZGVhZGxpbmUg YXMgYSBtb2R1bGUgcmVzdWx0ZWQNCmluIHRoZSBmb2xsb3dpbmc6DQoNCkVSUk9SOiAiYmxrX3F1 ZXVlX2V4aXQiIFtibG9jay9tcS1kZWFkbGluZS5rb10gdW5kZWZpbmVkIQ0KbWFrZVsxXTogKioq IFtzY3JpcHRzL01ha2VmaWxlLm1vZHBvc3Q6OTE6IF9fbW9kcG9zdF0gRXJyb3IgMQ0KbWFrZTog KioqIFtNYWtlZmlsZToxMTk4OiBtb2R1bGVzXSBFcnJvciAyDQpFeGVjdXRpb24gZmFpbGVkOiBt YWtlIGFsbA0KDQpCYXJ0Lg==
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 9 lines · Bart Van Assche
Since this patch is the first patch that introduces a call to
blk_queue_exit()from a module other than the block layer core, shouldn't this patch export theblk_queue_exit()function? An attempt to build mq-deadline as a module resulted in the following:ERROR: "
blk_queue_exit" [block/mq-deadline.ko] undefined! make[1]: *** [scripts/Makefile.modpost:91:__modpost] Error 1
make: *** [Makefile:1198: modules] Error 2 Execution failed: make all
Yes, it should. I'll make the export for now, I want to move that check and free/drop into the generic code so that the schedulers don't have to worry about it.
Signature · 1 line
Jens Axboe
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 18 lines
=20
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
=20
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
=20
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with. =20Signed-off-by Jens Axboe <[email protected]>=20
...
Quoted 9 lines
block/blk-mq-sched.c new file +2
-0+static inline bool +blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,
block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ struct bio *bio) +{ + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true; +} +
Something does not seem to add up here:e->type->ops.mq.allow_merge may be called only in blk_mq_sched_allow_merge, which, in its turn, may be called only in blk_mq_attempt_merge, which, finally, may be called only in blk_mq_merge_queue_io. Yet the latter may be called only if there is no elevator (line 1399 and 1507 in blk-mq.c).
Therefore, e->type->ops.mq.allow_merge can never be called, both if there is and if there is not an elevator. Be patient if I'm missing something huge, but I thought it was worth reporting this.
Paolo
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
Quoted 2 lines
Il giorno 22 dic 2016, alle ore 10:59, Paolo Valente =
<[email protected]> ha scritto:
Quoted 3 lines
=20
Quoted 2 lines
=20
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 26 lines
Quoted 16 lines
=20
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
=20
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
=20
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with. =20Quoted 2 lines
Signed-off-by Jens Axboe <[email protected]>=20
...
=20block/blk-mq-sched.c
Quoted 5 lines
block/blk-mq-sched.c new file +0
-0=20
Quoted 3 lines
block/blk-mq-sched.c
Quoted 3 lines
...
block/blk-mq-sched.c new file +2
-0+static inline bool +blk_mq_sched_allow_merge(struct request_queue *q, struct request =
*rq,
Quoted 14 lines
block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ struct bio *bio) +{ + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true; +} +=20
Something does not seem to add up here:e->type->ops.mq.allow_mergemay be called only inblk_mq_sched_allow_merge, which, in its turn, may be called only in
Quoted 8 lines
blk_mq_attempt_merge, which, finally, may be called only inblk_mq_merge_queue_io. Yet the latter may be called only if there is no elevator (line 1399 and 1507 inblk-mq.c).
=20
Therefore,e->type->ops.mq.allow_mergecan never be called, both if there is and if there is not an elevator. Be patient if I'm missing something huge, but I thought it was worth reporting this. =20
Just another detail: if e->type->ops.mq.allow_merge does get invoked from the above path, then it is invoked of course without the scheduler lock held. In contrast, if this function gets invoked from dd_bio_merge, then the scheduler lock is held.
To handle this opposite alternatives, I don't know whether checking if the lock is held (and possibly taking it) from inside e->type->ops.mq.allow_merge is a good solution. In any case, before possibly trying it, I will wait for some feedback on the main problem, i.e., on the fact that e->type->ops.mq.allow_merge
seems unreachable in the above path.
Thanks,
Paolo
Quoted 4 lines
Paolo
=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
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens AxboeQuoted 2 lines
Il giorno 21 dic 2016, alle ore 03:22, Jens Axboe <[email protected]> ha =
scritto:
Quoted 13 lines
=20
Quoted 11 lines · Paolo Valente
block/blk-mq-sched.c line 335
Quoted 7 lines
block/blk-mq-sched.c new file +7
-0+else + rq =3D __blk_mq_alloc_request(data, op); + +if (rq) { + rq->elv.icq =3D NULL; +if (e && e->type->icq_cache) +blk_mq_sched_assign_ioc (q, rq, bio);=20
bfq needsrq->elv.icqto be consistent inbfq_get_request, but the needed initialization seems to occur only after mq.get_request is invoked.
Quoted 2 lines
=20
Can you do it from get/put_rq_priv?
Definitely, I just overlooked them, sorry :(
Thanks,
Paolo
Quoted 8 lines
The icq is assigned there. If not,
we can redo this part, not a big deal.
=20
--=20
Jens Axboe
=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 2 lines
Il giorno 19 dic 2016, alle ore 22:05, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 19 dic 2016, alle ore 16:20, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> =
ha scritto:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
=20
This is version 4 of this patchset, version 3 was posted here:
=20
https://marc.info/?l=3Dlinux-block&m=3D148178513407631&w=3D2
=20
=46rom the discussion last time, I looked into the feasibility of =
having
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
two sets of tags for the same request pool, to avoid having to =
copy
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
some of the request fields at dispatch and completion time. To do =
that,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
we'd have to replace the driver tag map(s) with our own, and =
augment
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
that with tag map(s) on the side representing the device queue =
depth.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a =
real
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current =
approach
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
is cleaner.
=20
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
=20=20
I'm to modifying bfq. You mentioned other missing pieces to come. =
Do
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
=20
I'm mostly talking about elevator ops hooks that aren't there in the =
new
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
=20
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in thedispatch_requesthook for activate, and put/requeue for deactivate.
=20=20
You mean that there is no conceptual problem in moving the code of =
the
Quoted 9 lines
Quoted 4 lines
activate interface function into the dispatch function, and the code of the deactivate into the
put_request? (for a requeue it is a little less clear to me, so one step at a time) Or am I missing something more complex?=20
Yes, what I mean is that there isn't a 1:1 mapping between the old ops and the new ops. So you'll have to consider the cases.
=20
=20
Problem: whereas it seems easy and safe to do somewhere else the simple increment that was done in activate_request, I wonder if it may happen that a request is deactivate before being completed. In it may happen, then, without a deactivate_request hook, the increments would remain unbalanced. Or are request completions always guaranteed till no hw/sw components breaks?
Thanks,
Paolo=20
Quoted 5 lines
--=20
Jens Axboe
=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
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 6 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20Signed-off-by Jens Axboe <[email protected]>---
...
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +4
-0+/* +* remove rq from rbtree and fifo. +*/ +static void deadline_remove_request(struct request_queue *q, struct =
request *rq)
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct deadline_data *dd =3D q->elevator->elevator_data; + +list_del_init (&rq->queuelist); + +/* +* We might not be on the rbtree, if we are doing an insert =
merge
block/mq-deadline.c line 123
Quoted 4 lines
block/mq-deadline.c new file +4
-0+*/ +if (!RB_EMPTY_NODE (&rq->rb_node)) +deadline_del_rq_rb (dd, rq); +
I've been scratching my head on the last three instructions, but at no avail. If I understand correctly, the list_del_init(&rq->queue list);
removes rq from the fifo list. But, if so, I don't understand how it could be possible that rq has not been added to the rb_tree too.
Another interpretation that I tried is that the above three lines handle correctly the following case where rq has not been inserted at all into deadline fifo queue and rb tree: when dd_insert_request was executed for rq, blk_mq_sched_try_insert_merge succeeded. Yet, the list_del_init(&rq->queue list);
does not seem to make sense.
Could you please shed some light on this for me?
Thanks,
Paolo
Quoted 4 lines · Jens Axboe
From the discussion last time, I looked into the feasibility of having two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment
Quoted 8 lines
that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
Hello Jens,
Can you have a look at the attached patches? These implement the "two tags per request" approach without a table that maps one tag type to the other or any other ugly construct. __blk_mq_alloc_request() is modified such that it assigns rq->sched_tag and sched_tags->rqs[] instead of rq->tag and tags->rqs[]. rq->tag and tags->rqs[] are assigned just before dispatch by blk_mq_assign_drv_tag(). This approach results in significantly less code than the approach proposed in v4 of your blk-mq-sched patch series. Memory usage is lower because only a single set of requests is allocated. The runtime overhead is lower because request fields no longer have to be copied between the requests owned by the block driver and the requests owned by the I/O scheduler. I can boot a VM from the virtio-blk driver but otherwise the attached patches have not yet been tested.
Thanks,
Bart.
From 0fd04112850a73f5be9fa91a29bd1791179e1e80 Mon Sep 17 00:00:00 2001
From: Bart Van Assche <[email protected]>
Date: Tue, 20 Dec 2016 12:53:54 +0100
Subject: [PATCH 1/3] blk-mq: Revert some of the blk-mq-sched framework changes
Remove the functions that allocate and free shadow requests. Remove the get_request, put_request and completed_request callback functions from struct elevator_type. Remove blk-mq I/O scheduling functions that become superfluous due to these changes.
Note: this patch breaks blk-mq I/O scheduling. Later patches will make blk-mq I/O scheduling work again.
--- block/blk-mq-sched.c | 295 +---------------------------------------------- block/blk-mq-sched.h | 55 +-------- block/blk-mq.c | 50 ++++++-- block/mq-deadline.c | 90 ++------------- include/linux/elevator.h | 3 - 5 files changed, 58 insertions(+), 435 deletions(-)
block/blk-mq-sched.c +3 -292
@@ -15,196 +15,6 @@#include "blk-mq-tag.h" #include "blk-wbt.h" -/* -* Empty set -*/ -static const struct blk_mq_ops mq_sched_tag_ops = { -}; - -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, -int (*init)(struct blk_mq_hw_ctx *), -void (*exit)(struct blk_mq_hw_ctx *)) -{ -struct blk_mq_hw_ctx *hctx; -int ret; -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) { - ret = -ENOMEM ; - goto error; - } - -if (init) { - ret =init (hctx); -if (ret) { -/* -* We don't want to give exit() a partially -* initialized sched_data. init() must clean up -* if it fails. -*/ -kfree (hctx->sched_data); - hctx->sched_data =NULL ; - goto error; - } - } - } - -return 0 ; -error: -blk_mq_sched_free_hctx_data (q, exit); -return ret; -} -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; - rq->rq_flags =RQF_ALLOCED ; -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) -{ -WARN_ON_ONCE (!(rq->rq_flags &RQF_ALLOCED )); -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, issue_stat); - src->issue_stat.time =0 ; -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); - -if (sched_rq->end_io) - sched_rq->end_io (sched_rq, error); - -blk_mq_finish_request (rq); -} -static inline struct request *__blk_mq_sched_alloc_request (struct blk_mq_hw_ctx *hctx) {
@@ -225,55 +35,6 @@ __blk_mq_sched_alloc_request(struct blk_mq_hw_ctx *hctx)return rq; } -static inline void -__blk_mq_sched_init_request_from_shadow (struct request *rq, -struct request *sched_rq) -{ -WARN_ON_ONCE (!(sched_rq->rq_flags &RQF_ALLOCED )); -rq_copy (rq, sched_rq); - rq->end_io = sched_rq_end_io; - rq->end_io_data = sched_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 request *rq, *sched_rq; - - rq =__blk_mq_sched_alloc_request (hctx); -if (!rq) -return NULL ; - - sched_rq =get_sched_rq (hctx); -if (sched_rq) { -__blk_mq_sched_init_request_from_shadow (rq, sched_rq); -return rq; - } - -/* -* __blk_mq_finish_request() drops a queue ref we already hold, -* so grab an extra one. -*/ -blk_queue_enter_live (hctx->queue); -__blk_mq_finish_request (hctx, rq->mq_ctx, rq); -return NULL ; -} -EXPORT_SYMBOL_GPL (blk_mq_sched_request_from_shadow); - -struct request *__blk_mq_sched_request_from_shadow (struct blk_mq_hw_ctx *hctx, -struct request *sched_rq) -{ -struct request *rq; - - rq =__blk_mq_sched_alloc_request (hctx); -if (rq) -__blk_mq_sched_init_request_from_shadow (rq, sched_rq); - -return rq; -} -EXPORT_SYMBOL_GPL (__blk_mq_sched_request_from_shadow); -static void __blk_mq_sched_assign_ioc (struct request_queue *q,struct request *rq,struct io_context *ioc) {
@@ -298,8 +59,8 @@ static void __blk_mq_sched_assign_ioc(struct request_queue *q, rq->elv.icq =NULL ; } -static void blk_mq_sched_assign_ioc (struct request_queue *q, -struct request *rq,struct bio *bio) +void blk_mq_sched_assign_ioc (struct request_queue *q,struct request *rq, +struct bio *bio) {struct io_context *ioc;
@@ -308,44 +69,9 @@ static void blk_mq_sched_assign_ioc(struct request_queue *q,__blk_mq_sched_assign_ioc (q, rq, ioc); } -struct request *blk_mq_sched_get_request (struct request_queue *q, -struct bio *bio, -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->ops.mq.get_request) - rq = e->type->ops.mq.get_request (q, op, data); -else - rq =__blk_mq_alloc_request (data, op); - -if (rq) { - rq->elv.icq =NULL ; -if (e && e->type->icq_cache) -blk_mq_sched_assign_ioc (q, rq, bio); - data->hctx->queued++; -return rq; - } - -blk_queue_exit (q); -return NULL ; -} -void blk_mq_sched_put_request (struct request *rq) {struct request_queue *q = rq->q; -struct elevator_queue *e = q->elevator; -bool has_queue_ref = false, do_free = false;wbt_done (q->rq_wb, &rq->issue_stat);
@@ -357,22 +83,7 @@ void blk_mq_sched_put_request(struct request *rq) } } -/* -* If we are freeing a shadow that hasn't been started, then drop -* our queue ref on it. This normally happens at IO completion -* time, but if we merge request-to-request, then this 'rq' will -* never get started or completed. -*/ -if (blk_mq_sched_rq_is_shadow (rq) && !(rq->rq_flags &RQF_STARTED )) - has_queue_ref = true; - -if (e && e->type->ops.mq.put_request) - do_free = !e->type->ops.mq.put_request (rq); - -if (do_free) -blk_mq_finish_request (rq); -if (has_queue_ref) -blk_queue_exit (q); +blk_mq_finish_request (rq); }void blk_mq_sched_dispatch_requests (struct blk_mq_hw_ctx *hctx)
block/blk-mq-sched.h +3 -52
83 lines not on this page · raw message
block/blk-mq.c +42 -8
94 lines not on this page · raw message
block/mq-deadline.c +10 -80
141 lines not on this page · raw message
include/linux/elevator.h +0 -3
@@ -89,12 +89,9 @@ struct elevator_mq_ops {int (*request_merge)(struct request_queue *q,struct request **,struct bio *);void (*request_merged)(struct request_queue *,struct request *,int );void (*requests_merged)(struct request_queue *,struct request *,struct request *); -struct request *(*get_request)(struct request_queue *,unsigned int ,struct blk_mq_alloc_data *); -bool (*put_request)(struct request *);void (*insert_requests)(struct blk_mq_hw_ctx *,struct list_head *,bool );void (*dispatch_requests)(struct blk_mq_hw_ctx *,struct list_head *);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 *);
Signature · 1 line
2.11.0
From ae72bb9f67d01b3a02cee80c81a712f775d13c32 Mon Sep 17 00:00:00 2001
From: Bart Van Assche <[email protected]>
Date: Tue, 20 Dec 2016 12:00:47 +0100
Subject: [PATCH 2/3] blk-mq: Make the blk_mq_{get,put}_tag() callers specify
the tag set
This patch does not change any functionality.
--- block/blk-mq-tag.c | 29 ++++++++++---------- block/blk-mq-tag.h | 7 +++-- block/blk-mq.c | 80 ++++++++++++++++++++++++++++++++++++------------------ block/blk-mq.h | 9 ++++-- 4 files changed, 77 insertions(+), 48 deletions(-)
block/blk-mq-tag.c +14 -15
@@ -156,47 +156,46 @@ static int bt_get(struct blk_mq_alloc_data *data, struct sbitmap_queue *bt,return tag; } -static unsigned int __blk_mq_get_tag (struct blk_mq_alloc_data *data) +static unsigned int __blk_mq_get_tag (struct blk_mq_alloc_data *data, +struct blk_mq_tags *tags) {int tag; - tag =bt_get (data, &data->hctx->tags->bitmap_tags, data->hctx, - data->hctx->tags); + tag =bt_get (data, &tags->bitmap_tags, data->hctx, tags);if (tag >=0 ) -return tag + data->hctx->tags->nr_reserved_tags; +return tag + tags->nr_reserved_tags;return BLK_MQ_TAG_FAIL ; } -static unsigned int __blk_mq_get_reserved_tag (struct blk_mq_alloc_data *data) +static unsigned int __blk_mq_get_reserved_tag (struct blk_mq_alloc_data *data, +struct blk_mq_tags *tags) {int tag; -if (unlikely (!data->hctx->tags->nr_reserved_tags)) { +if (unlikely (!tags->nr_reserved_tags)) {WARN_ON_ONCE (1 );return BLK_MQ_TAG_FAIL ; } - tag =bt_get (data, &data->hctx->tags->breserved_tags,NULL , - data->hctx->tags); + tag =bt_get (data, &tags->breserved_tags,NULL , tags);if (tag <0 )return BLK_MQ_TAG_FAIL ;return tag; } -unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data) +unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data, +struct blk_mq_tags *tags) {if (data->flags &BLK_MQ_REQ_RESERVED ) -return __blk_mq_get_reserved_tag (data); -return __blk_mq_get_tag (data); +return __blk_mq_get_reserved_tag (data, tags); +return __blk_mq_get_tag (data, tags); } -void blk_mq_put_tag (struct blk_mq_hw_ctx *hctx,struct blk_mq_ctx *ctx, -unsigned int tag) +void blk_mq_put_tag (struct blk_mq_hw_ctx *hctx,struct blk_mq_tags *tags, +struct blk_mq_ctx *ctx,unsigned int tag) { -struct blk_mq_tags *tags = hctx->tags; -if (tag >= tags->nr_reserved_tags) {const int real_tag = tag - tags->nr_reserved_tags;
block/blk-mq-tag.h +4 -3
@@ -23,9 +23,10 @@ struct blk_mq_tags {extern struct blk_mq_tags *blk_mq_init_tags (unsigned int nr_tags,unsigned int reserved_tags,int node,int alloc_policy);extern void blk_mq_free_tags (struct blk_mq_tags *tags); -extern unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data); -extern void blk_mq_put_tag (struct blk_mq_hw_ctx *hctx,struct blk_mq_ctx *ctx, -unsigned int tag); +extern unsigned int blk_mq_get_tag (struct blk_mq_alloc_data *data, +struct blk_mq_tags *tags); +extern void blk_mq_put_tag (struct blk_mq_hw_ctx *hctx,struct blk_mq_tags *tags, +struct blk_mq_ctx *ctx,unsigned int tag);extern bool blk_mq_has_free_tags (struct blk_mq_tags *tags);extern ssize_t blk_mq_tag_sysfs_show (struct blk_mq_tags *tags,char *page);extern int blk_mq_tag_update_depth (struct blk_mq_tags *tags,unsigned int depth);
block/blk-mq.c +53 -27
173 lines not on this page · raw message
block/blk-mq.h +6 -3
@@ -37,10 +37,13 @@ void blk_mq_flush_busy_ctxs(struct blk_mq_hw_ctx *hctx, struct list_head *list);/* * Internal helpers for allocating/freeing the request map */ -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, +void blk_mq_free_rqs (struct blk_mq_tag_set *set,struct blk_mq_tags *tags, +unsigned int hctx_idx); +void blk_mq_free_rq_map (struct blk_mq_tags *tags); +struct blk_mq_tags *blk_mq_alloc_rq_map (struct blk_mq_tag_set *set,unsigned int hctx_idx); +int blk_mq_alloc_rqs (struct blk_mq_tag_set *set,struct blk_mq_tags *tags, +unsigned int hctx_idx);/* * Internal helpers for request insertion into sw queues
Signature · 1 line
2.11.0
From c49ec4e8b0e4135a87c9894597901539f3e3ca08 Mon Sep 17 00:00:00 2001
From: Bart Van Assche <[email protected]>
Date: Wed, 21 Dec 2016 12:39:33 +0100
Subject: [PATCH 3/3] blk-mq: Split driver and scheduler tags
Add 'sched_tags' next to 'tags' in struct blk_mq_hw_ctx and also in struct blk_mq_tag_set. Add 'sched_tag' next to 'tag' in struct request. Modify blk_mq_update_nr_requests() such that it accepts values larger than the queue depth. Make __blk_mq_free_request() free both tags. Make blk_mq_alloc_tag_set() allocate both tag sets. Make blk_mq_free_tag_set() free both tag sets. Make blk_mq_dispatch_rq_list() allocate the driver tag. Modify blk_mq_update_nr_requests() such that it accepts a size that exceeds the queue depth.
--- block/blk-flush.c | 9 ++- block/blk-mq.c | 160 +++++++++++++++++++++++++++++++++++-------------- block/blk-mq.h | 5 +- block/blk-tag.c | 1 + include/linux/blk-mq.h | 2 + include/linux/blkdev.h | 1 + 6 files changed, 129 insertions(+), 49 deletions(-)
block/blk-flush.c +7 -2
@@ -170,6 +170,8 @@ static bool blk_flush_complete_seq(struct request *rq,struct list_head *pending = &fq->flush_queue[fq->flush_pending_idx];bool queued = false, kicked; +BUG_ON (rq->tag <0 ); +BUG_ON (rq->flush.seq & seq); rq->flush.seq |= seq;
@@ -319,6 +321,8 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq)if (q->mq_ops) {struct blk_mq_hw_ctx *hctx; +BUG_ON (first_rq->tag <0 ); + flush_rq->mq_ctx = first_rq->mq_ctx; flush_rq->tag = first_rq->tag; fq->orig_rq = first_rq;
@@ -452,8 +456,9 @@ void blk_insert_flush(struct request *rq)* processed directly without going through flush machinery. Queue * for normal execution. */ -if ((policy &REQ_FSEQ_DATA ) && - !(policy & (REQ_FSEQ_PREFLUSH |REQ_FSEQ_POSTFLUSH ))) { +if (((policy &REQ_FSEQ_DATA ) && + !(policy & (REQ_FSEQ_PREFLUSH |REQ_FSEQ_POSTFLUSH ))) || + (q->mq_ops &&blk_mq_assign_drv_tag (rq) <0 )) {if (q->mq_ops)blk_mq_sched_insert_request (rq, false, true, false);else
block/blk-mq.c +114 -46
323 lines not on this page · raw message
block/blk-mq.h +4 -1
@@ -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); +int blk_mq_assign_drv_tag (struct request *rq);bool blk_mq_dispatch_rq_list (struct blk_mq_hw_ctx *,struct list_head *);void blk_mq_flush_busy_ctxs (struct blk_mq_hw_ctx *hctx,struct list_head *list);
@@ -41,7 +42,9 @@ void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, unsigned int hctx_idx);void blk_mq_free_rq_map (struct blk_mq_tags *tags);struct blk_mq_tags *blk_mq_alloc_rq_map (struct blk_mq_tag_set *set, -unsigned int hctx_idx); +unsigned int hctx_idx, +unsigned int nr_tags, +unsigned int reserved_tags);int blk_mq_alloc_rqs (struct blk_mq_tag_set *set,struct blk_mq_tags *tags,unsigned int hctx_idx);
block/blk-tag.c +1 -0
@@ -272,6 +272,7 @@ void blk_queue_end_tag(struct request_queue *q, struct request *rq)list_del_init (&rq->queuelist); rq->rq_flags &= ~RQF_QUEUED ; rq->tag =-1 ; + rq->sched_tag =-1 ;if (unlikely (bqt->tag_index[tag] ==NULL )) printk(KERN_ERR "%s: tag %d is missing\n",
include/linux/blk-mq.h +2 -0
@@ -36,6 +36,7 @@ struct blk_mq_hw_ctx {atomic_t wait_index;struct blk_mq_tags *tags; +struct blk_mq_tags *sched_tags;struct srcu_struct queue_rq_srcu;
@@ -72,6 +73,7 @@ struct blk_mq_tag_set {void *driver_data;struct blk_mq_tags **tags; +struct blk_mq_tags **sched_tags;struct mutex tag_list_lock;struct list_head tag_list;
include/linux/blkdev.h +1 -0
@@ -223,6 +223,7 @@ struct request {void *special;/* opaque pointer available for LLD use */ int tag; +int sched_tag;int errors;/*
Signature · 1 line
2.11.0
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20
One last question (for today ...):in mq-deadline there are no "schedule dispatch" or "unplug work" functions. In blk, CFQ and BFQ do these schedules/unplugs in a lot of cases. What's the right replacement? Just doing nothing?
Thanks,
Paolo
Quoted 5 lines
Signed-off-by Jens Axboe <[email protected]>---
block/Kconfig.iosched | 6 + block/Makefile | 1 + block/mq-deadline.c | 649 =
++++++++++++++++++++++++++++++++++++++++++++++++++
block/Makefile obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
Quoted 25 lines
3 files changed, 656 insertions(+)create mode 100644
block/mq-deadline.c
=20block/Kconfig.iosched +0
-0@@ -32,6 +32,12 @@ config IOSCHED_CFQ=20
This is the default I/O scheduler.
=20block/Kconfig.iosched +6
-0+config MQ_IOSCHED_DEADLINE + tristate "MQ deadline I/O scheduler" + default y + ---help--- + MQ version of the deadline IO scheduler. +config
CFQ_GROUP_IOSCHEDbool "CFQ Group Scheduling support" depends on IOSCHED_CFQ && BLK_CGROUPblock/Makefile +0
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
blk-throttle.o
Quoted 13 lines
obj-$(CONFIG_IOSCHED_NOOP) +=3D noop-iosched.o
obj-$(CONFIG_IOSCHED_DEADLINE) +=3D deadline-iosched.o
obj-$(CONFIG_IOSCHED_CFQ) +=3D cfq-iosched.o
+obj-$(CONFIG_MQ_IOSCHED_DEADLINE) +=3D mq-deadline.o
=20
obj-$(CONFIG_BLOCK_COMPAT) +=3D compat_ioctl.o
obj-$(CONFIG_BLK_CMDLINE_PARSER) +=3D cmdline-parser.oblock/mq-deadline.c new file +0
-0
block/mq-deadline.c line 2
Quoted 2 lines
block/mq-deadline.c new file +2
-0@@ -0,0 +1,649 @@ +/* +* MQ Deadline i/o scheduler - adaptation of the legacy deadline =
scheduler,
Quoted 15 lines
block/mq-deadline.c new file +15
-0+* for the blk-mq scheduling framework +* +* Copyright (C) 2016 Jens Axboe <[email protected]> +*/ +#include <linux/kernel.h> +#include <linux/fs.h> +#include <linux/blkdev.h> +#include <linux/blk-mq.h> +#include <linux/elevator.h> +#include <linux/bio.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/init.h> +#include <linux/compiler.h> +#include <linux/rbtree.h>
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+#include <linux/sbitmap.h> + +#include "blk.h" +#include "blk-mq.h" +#include "blk-mq-tag.h" +#include "blk-mq-sched.h" + +static unsigned int queue_depth =3D 256; +module_param (queue_depth, uint,0644 ); +MODULE_PARM_DESC(queue_depth, "Use this value as the scheduler queue =
depth");
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+ +/* +* See Documentation/block/deadline-iosched.txt +*/ +static const int read_expire =3D HZ / 2; /* max time before a read =
is submitted. */
block/mq-deadline.c line 33
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int write_expire =3D 5 * HZ; /* ditto for writes, these =
limits are SOFT! */
block/mq-deadline.c line 34
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int writes_starved =3D 2; /* max times reads can =
starve a write */
block/mq-deadline.c line 35
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int fifo_batch =3D 16; /* # of sequential requests =
treated as one
block/mq-deadline.c line 36
Quoted 1 line
block/mq-deadline.c new file +1
-0+ by the above parameters. For =
throughput. */
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ +struct deadline_data { +/* +* run time data +*/ + +/* +* requests (deadline_rq s) are present on both sort_list and =
fifo_list
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+*/ +struct rb_root sort_list[2 ]; +struct list_head fifo_list[2 ]; + +/* +* next in sort order. read, write or both are NULL +*/ +struct request *next_rq[2 ]; +unsigned int batching;/* number of sequential requests =
made */
block/mq-deadline.c line 54
Quoted 1 line
block/mq-deadline.c new file +1
-0+unsigned int starved;/* times reads have starved =
writes */
Quoted 48 lines
block/mq-deadline.c new file +48
-0+ +/* +* settings that change how the i/o scheduler behaves +*/ +int fifo_expire[2 ]; +int fifo_batch; +int writes_starved; +int front_merges; + +spinlock_t lock; +struct list_head dispatch; +struct blk_mq_tags *tags; +atomic_t wait_index; +}; + +static inline struct rb_root * +deadline_rb_root (struct deadline_data *dd,struct request *rq) +{ +return &dd->sort_list[rq_data_dir (rq)]; +} + +/* +* get the request after `rq' in sector-sorted order +*/ +static inline struct request * +deadline_latter_request (struct request *rq) +{ + struct rb_node *node =3D rb_next(&rq->rb_node); + +if (node) +return rb_entry_rq (node); + +return NULL ; +} + +static void +deadline_add_rq_rb (struct deadline_data *dd,struct request *rq) +{ + struct rb_root *root =3D deadline_rb_root(dd, rq); + +elv_rb_add (root, rq); +} + +static inline void +deadline_del_rq_rb (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ if (dd->next_rq[data_dir] =3D=3D rq) + dd->next_rq[data_dir] =3D deadline_latter_request(rq); + +elv_rb_del (deadline_rb_root (dd, rq), rq); +} + +/* +* remove rq from rbtree and fifo. +*/ +static void deadline_remove_request(struct request_queue *q, struct =
request *rq)
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct deadline_data *dd =3D q->elevator->elevator_data; + +list_del_init (&rq->queuelist); + +/* +* We might not be on the rbtree, if we are doing an insert =
merge
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+*/ +if (!RB_EMPTY_NODE (&rq->rb_node)) +deadline_del_rq_rb (dd, rq); + +elv_rqhash_del (q, rq); + if (q->last_merge =3D=3D rq) + q->last_merge =3D NULL; +} + +static void dd_request_merged(struct request_queue *q, struct request =
*req,
Quoted 4 lines
block/mq-deadline.c new file +4
-0+ int type) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+/* +* if the merge was a front merge, we need to reposition request +*/ + if (type =3D=3D ELEVATOR_FRONT_MERGE) { +elv_rb_del (deadline_rb_root (dd, req), req); +deadline_add_rq_rb (dd, req); + } +} + +static void dd_merged_requests(struct request_queue *q, struct =
request *req,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct request *next) +{ +/* +* if next expires before rq, assign its expire time to rq +* and move into next position (next will be deleted) in fifo +*/ + if (!list_empty(&req->queuelist) && =
!list_empty(&next->queuelist)) {
Quoted 23 lines
block/mq-deadline.c new file +23
-0+if (time_before ((unsigned long )next->fifo_time, + (unsigned long )req->fifo_time)) { +list_move (&req->queuelist, &next->queuelist); + req->fifo_time =3D next->fifo_time; + } + } + +/* +* kill knowledge of next, this one is a goner +*/ +deadline_remove_request (q, next); +} + +/* +* move an entry to dispatch queue +*/ +static void +deadline_move_request (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); + + dd->next_rq[READ] =3D NULL; + dd->next_rq[WRITE] =3D NULL;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ dd->next_rq[data_dir] =3D deadline_latter_request(rq); + +/* +* take it off the sort and fifo list +*/ +deadline_remove_request (rq->q, rq); +} + +/* +* deadline_check_fifo returns 0 if there are no expired requests on =
the fifo,
block/mq-deadline.c
Quoted 3 lines
block/mq-deadline.c new file +3
-0+* 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir]) +*/ +static inline int deadline_check_fifo(struct deadline_data *dd, int =
ddir)
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct request *rq =3D rq_entry_fifo(dd->fifo_list[ddir].next); + +/* +* rq is expired! +*/ +if (time_after_eq (jiffies, (unsigned long )rq->fifo_time))
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+return 1 ; + +return 0 ; +} + +/* +* deadline_dispatch_requests selects the best request according to +* read/write expire, fifo_batch, etc +*/ +static struct request *__dd_dispatch_request(struct blk_mq_hw_ctx =
*hctx)
block/mq-deadline.c line 205
Quoted 2 lines
block/mq-deadline.c new file +2
-0+{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+struct request *rq; +bool reads, writes; +int data_dir; + +spin_lock (&dd->lock); + +if (!list_empty (&dd->dispatch)) { + rq =3D list_first_entry(&dd->dispatch, struct request, =
queuelist);
Quoted 11 lines
block/mq-deadline.c new file +11
-0+list_del_init (&rq->queuelist); + goto done; + } + + reads =3D !list_empty(&dd->fifo_list[READ]); + writes =3D !list_empty(&dd->fifo_list[WRITE]); + +/* +* batches are currently reads XOR writes +*/ +if (dd->next_rq[WRITE ])
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ rq =3D dd->next_rq[WRITE]; + else + rq =3D dd->next_rq[READ]; + +if (rq && dd->batching < dd->fifo_batch) +/* we have a next request are still entitled to batch */ + goto dispatch_request; + +/* +* at this point we are not running a batch. select the =
appropriate
Quoted 25 lines
block/mq-deadline.c new file +25
-0+* data direction (read / write) +*/ + +if (reads) { +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[READ ])); + + if (writes && (dd->starved++ >=3D dd->writes_starved)) + goto dispatch_writes; + + data_dir =3D READ; + + goto dispatch_find_request; + } + +/* +* there are either no reads or writes have been starved +*/ + +if (writes) { +dispatch_writes: +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[WRITE ])); + + dd->starved =3D 0; + + data_dir =3D WRITE;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ + goto dispatch_find_request; + } + +spin_unlock (&dd->lock); +return NULL ; + +dispatch_find_request: +/* +* we are not running a batch, find best request for selected =
data_dir
block/mq-deadline.c line 271
Quoted 2 lines
block/mq-deadline.c new file +2
-0+*/ + if (deadline_check_fifo(dd, data_dir) || !dd->next_rq[data_dir]) =
{
block/mq-deadline.c line 273
Quoted 2 lines
block/mq-deadline.c new file +2
-0+/* +* A deadline has expired, the last request was in the =
other
block/mq-deadline.c line 274
Quoted 1 line
block/mq-deadline.c new file +1
-0+* direction, or we have run out of higher-sectored =
requests.
block/mq-deadline.c line 275
Quoted 1 line
block/mq-deadline.c new file +1
-0+* Start again from the request with the earliest expiry =
time.
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+*/ + rq =3D rq_entry_fifo(dd->fifo_list[data_dir].next); + }else { +/* +* The last req was the same dir and we have a next =
request in
block/mq-deadline.c line 281
Quoted 1 line
block/mq-deadline.c new file +1
-0+* sort order. No expired requests so continue on from =
here.
Quoted 12 lines
block/mq-deadline.c new file +12
-0+*/ + rq =3D dd->next_rq[data_dir]; + } + + dd->batching =3D 0; + +dispatch_request: +/* +* rq is the selected appropriate request. +*/ + dd->batching++; +deadline_move_request (dd, rq);
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+done: + rq->rq_flags |=3D RQF_STARTED; +spin_unlock (&dd->lock); +return rq; +} + +static void dd_dispatch_requests (struct blk_mq_hw_ctx *hctx, +struct list_head *rq_list) +{ + blk_mq_sched_dispatch_shadow_requests(hctx, rq_list, =
__dd_dispatch_request);
Quoted 7 lines
block/mq-deadline.c new file +7
-0+} + +static void dd_exit_queue (struct elevator_queue *e) +{ + struct deadline_data *dd =3D e->elevator_data; + +BUG_ON (!list_empty (&dd->fifo_list[READ ]));
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+BUG_ON (!list_empty (&dd->fifo_list[WRITE ])); + +blk_mq_sched_free_requests (dd->tags); +kfree (dd); +} + +/* +* initialize elevator private data (deadline_data). +*/ +static int dd_init_queue(struct request_queue *q, struct =
elevator_type *e)
Quoted 30 lines
block/mq-deadline.c new file +30
-0+{ +struct deadline_data *dd; +struct elevator_queue *eq; + + eq =3D elevator_alloc(q, e); +if (!eq) +return -ENOMEM ; + + dd =3D kzalloc_node(sizeof(*dd), GFP_KERNEL, q->node); +if (!dd) { +kobject_put (&eq->kobj); +return -ENOMEM ; + } + eq->elevator_data =3D dd; + + dd->tags =3D blk_mq_sched_alloc_requests(queue_depth, q->node); +if (!dd->tags) { +kfree (dd); +kobject_put (&eq->kobj); +return -ENOMEM ; + } + +INIT_LIST_HEAD (&dd->fifo_list[READ ]); +INIT_LIST_HEAD (&dd->fifo_list[WRITE ]); + dd->sort_list[READ] =3D RB_ROOT; + dd->sort_list[WRITE] =3D RB_ROOT; + dd->fifo_expire[READ] =3D read_expire; + dd->fifo_expire[WRITE] =3D write_expire; + dd->writes_starved =3D writes_starved; + dd->front_merges =3D 1;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ dd->fifo_batch =3D fifo_batch; +spin_lock_init (&dd->lock); +INIT_LIST_HEAD (&dd->dispatch); +atomic_set (&dd->wait_index,0 ); + + q->elevator =3D eq; +return 0 ; +} + +static int dd_request_merge(struct request_queue *q, struct request =
**rq,
Quoted 29 lines
block/mq-deadline.c new file +29
-0+ struct bio *bio) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; + sector_t sector =3D bio_end_sector(bio); +struct request *__rq; + +if (!dd->front_merges) +return ELEVATOR_NO_MERGE ; + + __rq =3D elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector); +if (__rq) { + BUG_ON(sector !=3D blk_rq_pos(__rq)); + +if (elv_bio_merge_ok (__rq, bio)) { + *rq =3D __rq; +return ELEVATOR_FRONT_MERGE ; + } + } + +return ELEVATOR_NO_MERGE ; +} + +static bool dd_bio_merge (struct blk_mq_hw_ctx *hctx,struct bio *bio) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; +int ret; + +spin_lock (&dd->lock);
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ ret =3D blk_mq_sched_try_merge(q, bio); +spin_unlock (&dd->lock); + +return ret; +} + +/* +* add rq to rbtree and fifo +*/ +static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq,
block/mq-deadline.c
Quoted 13 lines
block/mq-deadline.c new file +13
-0+ bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + const int data_dir =3D rq_data_dir(rq); + +if (blk_mq_sched_try_insert_merge (q, rq)) +return ; + +blk_mq_sched_request_inserted (rq); + +/* +* If we're trying to insert a real request, just send it =
directly
block/mq-deadline.c line 413
Quoted 1 line
block/mq-deadline.c new file +1
-0+* to the hardware dispatch list. This only happens for a =
requeue,
Quoted 32 lines
block/mq-deadline.c new file +32
-0+* or FUA/FLUSH requests. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) { +spin_lock (&hctx->lock); +list_add_tail (&rq->queuelist, &hctx->dispatch); +spin_unlock (&hctx->lock); +return ; + } + + if (at_head || rq->cmd_type !=3D REQ_TYPE_FS) { +if (at_head) +list_add (&rq->queuelist, &dd->dispatch); +else +list_add_tail (&rq->queuelist, &dd->dispatch); + }else { +deadline_add_rq_rb (dd, rq); + +if (rq_mergeable (rq)) { +elv_rqhash_add (q, rq); +if (!q->last_merge) + q->last_merge =3D rq; + } + +/* +* set expire time and add to fifo list +*/ + rq->fifo_time =3D jiffies + dd->fifo_expire[data_dir]; +list_add_tail (&rq->queuelist, &dd->fifo_list[data_dir]); + } +} + +static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ struct list_head *list, bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + +spin_lock (&dd->lock); +while (!list_empty (list)) { +struct request *rq; + + rq =3D list_first_entry(list, struct request, =
queuelist);
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+list_del_init (&rq->queuelist); +dd_insert_request (hctx, rq, at_head); + } +spin_unlock (&dd->lock); +} + +static struct request *dd_get_request(struct request_queue *q, =
unsigned int op,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct blk_mq_alloc_data *data) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +struct request *rq; + +/* +* The flush machinery intercepts before we insert the request. =
As
block/mq-deadline.c
Quoted 6 lines
block/mq-deadline.c new file +6
-0+* a work-around, just hand it back a real request. +*/ +if (unlikely (op & (REQ_PREFLUSH |REQ_FUA ))) + rq =3D __blk_mq_alloc_request(data, op); +else { + rq =3D blk_mq_sched_alloc_shadow_request(q, data, =
dd->tags, &dd->wait_index);
block/mq-deadline.c
Quoted 13 lines
block/mq-deadline.c new file +13
-0+if (rq) +blk_mq_rq_ctx_init (q, data->ctx, rq, op); + } + +return rq; +} + +static bool dd_put_request (struct request *rq) +{ +/* +* If it's a real request, we just have to free it. For a shadow +* request, we should only free it if we haven't started it. A +* started request is mapped to a real one, and the real one =
will
Quoted 13 lines
block/mq-deadline.c new file +13
-0+* free it. We can get here with request merges, since we then +* free the request before we start/issue it. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) +return false; + +if (!(rq->rq_flags &RQF_STARTED )) { + struct request_queue *q =3D rq->q; + struct deadline_data *dd =3D q->elevator->elevator_data; + +/* +* IO completion would normally do this, but if we merge +* and free before we issue the request, drop both the
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+* tag and queue ref +*/ +blk_mq_sched_free_shadow_request (dd->tags, rq); +blk_queue_exit (q); + } + +return true; +} + +static void dd_completed_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq)
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+{ + struct request *sched_rq =3D rq->end_io_data; + +/* +* sched_rq can be NULL, if we haven't setup the shadow yet +* because we failed getting one. +*/ +if (sched_rq) { + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+ +blk_mq_sched_free_shadow_request (dd->tags, sched_rq); +blk_mq_start_stopped_hw_queue (hctx, true); + } +} + +static bool dd_has_work (struct blk_mq_hw_ctx *hctx) +{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
Quoted 15 lines
block/mq-deadline.c new file +15
-0+ +return !list_empty_careful (&dd->dispatch) || + !list_empty_careful (&dd->fifo_list[0 ]) || + !list_empty_careful (&dd->fifo_list[1 ]); +} + +/* +* sysfs parts below +*/ +static ssize_t +deadline_var_show (int var,char *page) +{ +return sprintf (page,"%d\n" , var); +} +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+static ssize_t +deadline_var_store (int *var,const char *page,size_t count) +{ + char *p =3D (char *) page; + + *var =3D simple_strtol(p, &p, 10); +return count; +} + +#define SHOW_FUNCTION (__FUNC, __VAR, __CONV) =
\
block/mq-deadline.c line 555
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, char *page) =
\
block/mq-deadline.c line 556
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
block/mq-deadline.c line 557
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
block/mq-deadline.c line 558
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data =3D __VAR; =
\
block/mq-deadline.c line 559
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
block/mq-deadline.c line 560
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D jiffies_to_msecs(__data); =
\
block/mq-deadline.c line 561
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return deadline_var_show(__data, (page)); =
\
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+} +SHOW_FUNCTION (deadline_read_expire_show, dd->fifo_expire[READ ],1 ); +SHOW_FUNCTION (deadline_write_expire_show, dd->fifo_expire[WRITE ],1 ); +SHOW_FUNCTION (deadline_writes_starved_show, dd->writes_starved,0 ); +SHOW_FUNCTION (deadline_front_merges_show, dd->front_merges,0 ); +SHOW_FUNCTION (deadline_fifo_batch_show, dd->fifo_batch,0 ); +#undef SHOW_FUNCTION + +#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) =
\
block/mq-deadline.c line 571
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, const char *page, =
size_t count) \
block/mq-deadline.c line 572
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
block/mq-deadline.c line 573
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
block/mq-deadline.c line 574
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data; =
\
block/mq-deadline.c line 575
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int ret =3D deadline_var_store(&__data, (page), count); =
\
block/mq-deadline.c line 576
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__data < (MIN)) =
\
block/mq-deadline.c line 577
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MIN); =
\
block/mq-deadline.c line 578
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else if (__data > (MAX)) =
\
block/mq-deadline.c line 579
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MAX); =
\
block/mq-deadline.c line 580
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
block/mq-deadline.c line 581
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D msecs_to_jiffies(__data); =
\
block/mq-deadline.c line 582
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else =
\
block/mq-deadline.c line 583
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D __data; =
\
block/mq-deadline.c line 584
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return ret; =
\
block/mq-deadline.c line 586
Quoted 2 lines
block/mq-deadline.c new file +2
-0+} +STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, =
INT_MAX, 1);
block/mq-deadline.c line 587
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], =
0, INT_MAX, 1);
block/mq-deadline.c line 588
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, =
INT_MIN, INT_MAX, 0);
block/mq-deadline.c line 589
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, =
0);
block/mq-deadline.c line 590
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, =
INT_MAX, 0);
Quoted 62 lines
block/mq-deadline.c new file +59
-1+#undef STORE_FUNCTION + +#define DD_ATTR (name) \ + __ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \ + deadline_##name##_store) + +static struct elv_fs_entry deadline_attrs[] =3D { +DD_ATTR (read_expire), +DD_ATTR (write_expire), +DD_ATTR (writes_starved), +DD_ATTR (front_merges), +DD_ATTR (fifo_batch), + __ATTR_NULL +}; + +static struct elevator_type mq_deadline =3D { + .ops.mq =3D { + .get_request =3D dd_get_request, + .put_request =3D dd_put_request, + .insert_requests =3D dd_insert_requests, + .dispatch_requests =3D dd_dispatch_requests, + .completed_request =3D dd_completed_request, + .next_request =3D elv_rb_latter_request, + .former_request =3D elv_rb_former_request, + .bio_merge =3D dd_bio_merge, + .request_merge =3D dd_request_merge, + .requests_merged =3D dd_merged_requests, + .request_merged =3D dd_request_merged, + .has_work =3D dd_has_work, + .init_sched =3D dd_init_queue, + .exit_sched =3D dd_exit_queue, + }, + + .uses_mq =3D true, + .elevator_attrs =3D deadline_attrs, + .elevator_name =3D "mq-deadline", + .elevator_owner =3D THIS_MODULE, +}; + +static int __init deadline_init (void ) +{ +if (!queue_depth) { +pr_err ("mq-deadline: queue depth must be > 0\n" ); +return -EINVAL ; + } +return elv_register (&mq_deadline); +} + +static void __exit deadline_exit(void) +{ +elv_unregister (&mq_deadline); +} + +module_init (deadline_init); +module_exit (deadline_exit); + +MODULE_AUTHOR ("Jens Axboe" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("MQ deadline IO scheduler" ); --=202.7.4
=20
Quoted 29 lines · Bart Van Assche
Quoted 4 lines · Jens Axboe
From the discussion last time, I looked into the feasibility of having two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment
Quoted 8 lines
that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
Hello Jens,
Can you have a look at the attached patches? These implement the "two tags per request" approach without a table that maps one tag type to the other or any other ugly construct.�__blk_mq_alloc_request() is modified such that it assigns
rq->sched_tagand sched_tags->rqs[] instead ofrq->tagand tags->rqs[].rq->tagand tags->rqs[] are assigned just before dispatch byblk_mq_assign_drv_tag(). This approach results in significantly less code than the approach proposed in v4 of your blk-mq-sched patch series. Memory usage is lower because only a single set of requests is allocated. The runtime overhead is lower because request fields no longer have to be copied between the requests owned by the block driver and the requests owned by the I/O scheduler. I can boot a VM from the virtio-blk driver but otherwise the attached patches have not yet been tested.
Quoted 3 lines
Thanks,
Bart.
Hey, Bart,
This approach occurred to us, but we couldn't figure out a way to make blk_mq_tag_to_rq() work with it. From skimming over the patches, I didn't see a solution to that problem.
T24gVGh1LCAyMDE2LTEyLTIyIGF0IDA4OjUyIC0wODAwLCBPbWFyIFNhbmRvdmFsIHdyb3RlOg0K PiBUaGlzIGFwcHJvYWNoIG9jY3VycmVkIHRvIHVzLCBidXQgd2UgY291bGRuJ3QgZmlndXJlIG91 dCBhIHdheSB0byBtYWtlDQo+IGJsa19tcV90YWdfdG9fcnEoKSB3b3JrIHdpdGggaXQuIEZyb20g c2tpbW1pbmcgb3ZlciB0aGUgcGF0Y2hlcywgSQ0KPiBkaWRuJ3Qgc2VlIGEgc29sdXRpb24gdG8g dGhhdCBwcm9ibGVtLg0KDQpIZWxsbyBPbWFyLA0KDQpDYW4geW91IGNsYXJpZnkgeW91ciBjb21t ZW50PyBTaW5jZSBteSBwYXRjaGVzIGluaXRpYWxpemUgYm90aCB0YWdzLT5ycXNbXQ0KYW5kIHNj aGVkX3RhZ3MtPnJxc1tdIHRoZSBmdW5jdGlvbiBibGtfbXFfdGFnX3RvX3JxKCkgc2hvdWxkIHN0 aWxsIHdvcmsuDQoNCkJhcnQu
Quoted 11 lines · Bart Van Assche
Quoted 3 lines · Omar Sandoval
This approach occurred to us, but we couldn't figure out a way to make
blk_mq_tag_to_rq()work with it. From skimming over the patches, I didn't see a solution to that problem.Hello Omar,
Can you clarify your comment? Since my patches initialize both tags->rqs[] and sched_tags->rqs[] the function
blk_mq_tag_to_rq()should still work.Bart.
Sorry, you're right, it does work, but tags->rqs[] ends up being the extra lookup table. I suspect that the runtime overhead of keeping that up to date could be worse than copying the rq fields if you have lots of CPUs but only one hardware queue.
T24gVGh1LCAyMDE2LTEyLTIyIGF0IDA5OjEyIC0wODAwLCBPbWFyIFNhbmRvdmFsIHdyb3RlOg0K PiBPbiBUaHUsIERlYyAyMiwgMjAxNiBhdCAwNDo1NzozNlBNICswMDAwLCBCYXJ0IFZhbiBBc3Nj aGUgd3JvdGU6DQo+ID4gT24gVGh1LCAyMDE2LTEyLTIyIGF0IDA4OjUyIC0wODAwLCBPbWFyIFNh bmRvdmFsIHdyb3RlOg0KPiA+ID4gVGhpcyBhcHByb2FjaCBvY2N1cnJlZCB0byB1cywgYnV0IHdl IGNvdWxkbid0IGZpZ3VyZSBvdXQgYSB3YXkgdG8gbWFrZQ0KPiA+ID4gYmxrX21xX3RhZ190b19y cSgpIHdvcmsgd2l0aCBpdC4gRnJvbSBza2ltbWluZyBvdmVyIHRoZSBwYXRjaGVzLCBJDQo+ID4g PiBkaWRuJ3Qgc2VlIGEgc29sdXRpb24gdG8gdGhhdCBwcm9ibGVtLg0KPiA+IA0KPiA+IENhbiB5 b3UgY2xhcmlmeSB5b3VyIGNvbW1lbnQ/IFNpbmNlIG15IHBhdGNoZXMgaW5pdGlhbGl6ZSBib3Ro IHRhZ3MtPnJxc1tdDQo+ID4gYW5kIHNjaGVkX3RhZ3MtPnJxc1tdIHRoZSBmdW5jdGlvbiBibGtf bXFfdGFnX3RvX3JxKCkgc2hvdWxkIHN0aWxsIHdvcmsuDQo+IA0KPiBTb3JyeSwgeW91J3JlIHJp Z2h0LCBpdCBkb2VzIHdvcmssIGJ1dCB0YWdzLT5ycXNbXSBlbmRzIHVwIGJlaW5nIHRoZQ0KPiBl eHRyYSBsb29rdXAgdGFibGUuIEkgc3VzcGVjdCB0aGF0IHRoZSBydW50aW1lIG92ZXJoZWFkIG9m IGtlZXBpbmcgdGhhdA0KPiB1cCB0byBkYXRlIGNvdWxkIGJlIHdvcnNlIHRoYW4gY29weWluZyB0 aGUgcnEgZmllbGRzIGlmIHlvdSBoYXZlIGxvdHMgb2YNCj4gQ1BVcyBidXQgb25seSBvbmUgaGFy ZHdhcmUgcXVldWUuDQoNCkhlbGxvIE9tYXIsDQoNCkknbSBub3Qgc3VyZSB0aGF0IGFueXRoaW5n IGNhbiBiZSBkb25lIGlmIHRoZSBudW1iZXIgb2YgQ1BVcyB0aGF0IGlzIHN1Ym1pdHRpbmcNCkkv TyBpcyBsYXJnZSBjb21wYXJlZCB0byB0aGUgcXVldWUgZGVwdGggc28gSSBkb24ndCB0aGluayB3 ZSBzaG91bGQgc3BlbmQgb3VyDQp0aW1lIG9uIHRoYXQgY2FzZS4gSWYgdGhlIHF1ZXVlIGRlcHRo IGlzIGxhcmdlIGVub3VnaCB0aGVuIHRoZSBzYml0bWFwIGNvZGUgd2lsbA0KYWxsb2NhdGUgdGFn cyBzdWNoIHRoYXQgZGlmZmVyZW50IENQVXMgdXNlIGRpZmZlcmVudCBycXNbXSBlbGVtZW50cy4N Cg0KVGhlIGFkdmFudGFnZXMgb2YgdGhlIGFwcHJvYWNoIEkgcHJvcG9zZWQgYXJlIHN1Y2ggdGhh dCBJIGFtIGNvbnZpbmNlZCB0aGF0IGlzDQp3aGF0IHdlIHNob3VsZCBzdGFydCBmcm9tIGFuZCBh ZGRyZXNzIGNvbnRlbnRpb24gb24gdGhlIHRhZ3MtPnJxc1tdIGFycmF5IGlmIGl0DQptZWFzdXJl bWVudHMgc2hvdyB0aGF0IGl0IGlzIG5lY2Vzc2FyeSB0byBhZGRyZXNzIGl0Lg0KDQpCYXJ0Lg==
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Paolo ValenteQuoted 2 lines
Il giorno 22 dic 2016, alle ore 10:59, Paolo Valente =
<[email protected]> ha scritto:
Quoted 3 lines
=20
Quoted 2 lines
=20
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 26 lines
Quoted 16 lines
=20
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
=20
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
=20
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with. =20Quoted 2 lines
Signed-off-by Jens Axboe <[email protected]>=20
...
=20block/blk-mq-sched.c
Quoted 5 lines
block/blk-mq-sched.c new file +0
-0=20
Quoted 3 lines
block/blk-mq-sched.c
Quoted 3 lines
...
block/blk-mq-sched.c new file +2
-0+static inline bool +blk_mq_sched_allow_merge(struct request_queue *q, struct request =
*rq,
Quoted 14 lines
block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ struct bio *bio) +{ + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true; +} +=20
Something does not seem to add up here:e->type->ops.mq.allow_mergemay be called only inblk_mq_sched_allow_merge, which, in its turn, may be called only in
Quoted 8 lines
blk_mq_attempt_merge, which, finally, may be called only inblk_mq_merge_queue_io. Yet the latter may be called only if there is no elevator (line 1399 and 1507 inblk-mq.c).
=20
Therefore,e->type->ops.mq.allow_mergecan never be called, both if there is and if there is not an elevator. Be patient if I'm missing something huge, but I thought it was worth reporting this. =20
Jens,
I forgot to add that I'm willing (and would be happy) to propose a fix to this, and possibly the other problems too, on my own. Just, I'm not yet expert enough to do it with having first received some feedback or instructions from you. In this specific case, I don't even know yet whether this is really a bug.
Thanks, and merry Christmas if we don't get in touch before, Paolo
Quoted 4 lines
Paolo
=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
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Paolo ValenteQuoted 57 lines · Paolo Valente
Quoted 52 lines
Il giorno 22 dic 2016, alle ore 10:59, Paolo Valente <[email protected]> ha scritto:
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with.
Signed-off-by Jens Axboe <[email protected]>...
Quoted 9 lines
block/blk-mq-sched.c new file +2
-0+static inline bool +blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ struct bio *bio) +{ +struct elevator_queue *e = q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true; +} +Something does not seem to add up here:
e->type->ops.mq.allow_mergemay be called only inblk_mq_sched_allow_merge, which, in its turn, may be called only inblk_mq_attempt_merge, which, finally, may be called only inblk_mq_merge_queue_io. Yet the latter may be called only if there is no elevator (line 1399 and 1507 inblk-mq.c).Quoted 4 lines
Therefore,
e->type->ops.mq.allow_mergecan never be called, both if there is and if there is not an elevator. Be patient if I'm missing something huge, but I thought it was worth reporting this.
Quoted 4 lines
Just another detail: if
e->type->ops.mq.allow_mergedoes get invoked from the above path, then it is invoked of course without the scheduler lock held. In contrast, if this function gets invoked fromdd_bio_merge, then the scheduler lock is held.
But the scheduler controls that itself. So it'd be perfectly fine to have a locked and unlocked variant. The way that's typically done is to have function() grabbing the lock, and __function() is invoked with the lock held.
Quoted 6 lines
To handle this opposite alternatives, I don't know whether checking if the lock is held (and possibly taking it) from inside
e->type->ops.mq.allow_mergeis a good solution. In any case, before possibly trying it, I will wait for some feedback on the main problem, i.e., on the fact thate->type->ops.mq.allow_merge
seems unreachable in the above path.
Checking if a lock is held is NEVER a good idea, as it leads to both bad and incorrect code. If you just check if a lock is held when being called, you don't necessarily know if it was the caller that grabbed it or it just happens to be held by someone else for unrelated reasons.
Signature · 1 line
Jens Axboe
Quoted 58 lines · Paolo Valente
Quoted 47 lines
Il giorno 19 dic 2016, alle ore 22:05, Jens Axboe <[email protected]> ha scritto:
Quoted 43 lines · Paolo Valente
Quoted 42 lines
Il giorno 19 dic 2016, alle ore 16:20, Jens Axboe <[email protected]> ha scritto:
Quoted 26 lines · Paolo Valente
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is version 4 of this patchset, version 3 was posted here:
https://marc.info/?l=linux-block&m=148178513407631&w=2
From the discussion last time, I looked into the feasibility of having two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
Quoted 5 lines
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
Quoted 3 lines
I'm to modifying bfq. You mentioned other missing pieces to come. Do you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
I'm mostly talking about elevator ops hooks that aren't there in the new framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in the
dispatch_requesthook for activate, and put/requeue for deactivate.Quoted 10 lines
Quoted 5 lines
You mean that there is no conceptual problem in moving the code of the activate interface function into the dispatch function, and the code of the deactivate into the
put_request? (for a requeue it is a little less clear to me, so one step at a time) Or am I missing something more complex?Yes, what I mean is that there isn't a 1:1 mapping between the old ops and the new ops. So you'll have to consider the cases.
Quoted 6 lines
Problem: whereas it seems easy and safe to do somewhere else the simple increment that was done in
activate_request, I wonder if it may happen that a request is deactivate before being completed. In it may happen, then, without adeactivate_requesthook, the increments would remain unbalanced. Or are request completions always guaranteed till no hw/sw components breaks?
You should be able to do it in get/put_request. But you might need some extra tracking, I'd need to double check. I'm trying to avoid adding hooks that we don't truly need, the old interface had a lot of that. If you find that you need a hook and it isn't there, feel free to add it. activate/deactivate might be a good change.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Paolo ValenteQuoted 39 lines · Paolo Valente
Quoted 8 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design.
Signed-off-by Jens Axboe <[email protected]>---
...
Quoted 11 lines
block/mq-deadline.c new file +5
-0+/* +* remove rq from rbtree and fifo. +*/ +static void deadline_remove_request (struct request_queue *q,struct request *rq) +{block/mq-deadline.c line 123
Quoted 10 lines
block/mq-deadline.c new file +10
-0+struct deadline_data *dd = q->elevator->elevator_data; + +list_del_init (&rq->queuelist); + +/* +* We might not be on the rbtree, if we are doing an insert merge +*/ +if (!RB_EMPTY_NODE (&rq->rb_node)) +deadline_del_rq_rb (dd, rq); +I've been scratching my head on the last three instructions, but at no avail. If I understand correctly, the
list_del_init(&rq->queue list);
removes rq from the fifo list. But, if so, I don't understand how it could be possible that rq has not been added to therb_treetoo.
Quoted 8 lines
Another interpretation that I tried is that the above three lines handle correctly the following case where rq has not been inserted at all into deadline fifo queue and rb tree: when
dd_insert_requestwas executed for rq,blk_mq_sched_try_insert_mergesucceeded. Yet, thelist_del_init(&rq->queue list);
does not seem to make sense.Could you please shed some light on this for me?
I think you are correct, we don't need to touch ->queuelist for the case where RB_EMPTY_NODE() is true. Minor detail, the list is already empty, so it does no harm.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Paolo ValenteQuoted 11 lines · Paolo Valente
Quoted 6 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design.
One last question (for today ...):in mq-deadline there are no "schedule dispatch" or "unplug work" functions. In blk, CFQ and BFQ do these schedules/unplugs in a lot of cases. What's the right replacement? Just doing nothing?
You just use blk_mq_run_hw_queue() or variants thereof to kick off queue runs.
Signature · 1 line
Jens Axboe
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Paolo ValenteQuoted 49 lines · Paolo Valente
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with.
Signed-off-by Jens Axboe <[email protected]>...
Quoted 9 lines
block/blk-mq-sched.c new file +2
-0+static inline bool +blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ struct bio *bio) +{ +struct elevator_queue *e = q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true; +} +Something does not seem to add up here:
e->type->ops.mq.allow_mergemay be called only inblk_mq_sched_allow_merge, which, in its turn, may be called only inblk_mq_attempt_merge, which, finally, may be called only inblk_mq_merge_queue_io. Yet the latter may be called only if there is no elevator (line 1399 and 1507 inblk-mq.c).
Quoted 3 lines
Therefore,
e->type->ops.mq.allow_mergecan never be called, both if there is and if there is not an elevator. Be patient if I'm missing something huge, but I thought it was worth reporting this.
I went through the current branch, and it seems mostly fine. There was a double call to allow_merge() that I killed in the plug path, and one set missing in blk_mq_sched_try_merge(). The rest looks OK.
Signature · 1 line
Jens Axboe
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
Quoted 2 lines
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 26 lines
Quoted 26 lines
Quoted 16 lines
=20
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
=20
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
=20
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with. =20Quoted 2 lines
Signed-off-by Jens Axboe <[email protected]>=20
...
=20block/blk-mq-sched.c
Quoted 5 lines
block/blk-mq-sched.c new file +0
-0=20
Quoted 3 lines
Quoted 3 lines
block/blk-mq-sched.c
Quoted 3 lines
...
block/blk-mq-sched.c new file +2
-0+static inline bool +blk_mq_sched_allow_merge(struct request_queue *q, struct request =
*rq,
Quoted 21 lines
Quoted 13 lines
block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ struct bio *bio) +{ + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true; +} +=20
Something does not seem to add up here:e->type->ops.mq.allow_mergemay be called only inQuoted 8 lines
blk_mq_sched_allow_merge, which, in its turn, may be called only inblk_mq_attempt_merge, which, finally, may be called only inblk_mq_merge_queue_io. Yet the latter may be called only if there is no elevator (line 1399 and 1507 inblk-mq.c).
=20
Therefore,e->type->ops.mq.allow_mergecan never be called, both if there is and if there is not an elevator. Be patient if I'm missing something huge, but I thought it was worth reporting this.
Quoted 5 lines
=20
I went through the current branch, and it seems mostly fine. There was a double call toallow_merge()that I killed in the plug path, and one set missing inblk_mq_sched_try_merge(). The rest looks OK. =20
Yes, I missed a path, sorry. I'm happy that at least your check has not been a waste of time for other reasons.
Thanks,
Paolo
Quoted 3 lines
--=20
Jens Axboe
=20
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 22 dic 2016, alle ore 10:59, Paolo Valente =
<[email protected]> ha scritto:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
=20
Quoted 2 lines
=20
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 16 lines
=20
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
=20
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
=20
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with. =20Quoted 2 lines
Signed-off-by Jens Axboe <[email protected]>=20
...
=20block/blk-mq-sched.c
Quoted 5 lines
block/blk-mq-sched.c new file +0
-0=20
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
block/blk-mq-sched.c
Quoted 3 lines
...
block/blk-mq-sched.c new file +2
-0+static inline bool +blk_mq_sched_allow_merge(struct request_queue *q, struct request =
*rq,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
block/blk-mq-sched.c new file +8
-0+ struct bio *bio) +{ + struct elevator_queue *e =3D q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
block/blk-mq-sched.c
Quoted 2 lines
block/blk-mq-sched.c new file +2
-0+} +=20
Something does not seem to add up here:e->type->ops.mq.allow_mergemay be called only inblk_mq_sched_allow_merge, which, in its turn, may be called only inblk_mq_attempt_merge, which, finally, may be called only inblk_mq_merge_queue_io. Yet the latter may be called only if there =
is
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
no elevator (line 1399 and 1507 in
blk-mq.c).
=20
Therefore,e->type->ops.mq.allow_mergecan never be called, both if there is and if there is not an elevator. Be patient if I'm missing something huge, but I thought it was worth reporting this. =20
Quoted 8 lines
Quoted 5 lines
=20
Just another detail: ife->type->ops.mq.allow_mergedoes get invoked from the above path, then it is invoked of course without the scheduler lock held. In contrast, if this function gets invoked fromdd_bio_merge, then the scheduler lock is held.=20
But the scheduler controls that itself. So it'd be perfectly fine to have a locked and unlocked variant. The way that's typically done is =
to
Quoted 1 line
have
function()grabbing the lock, and__function()is invoked with =
the
Quoted 3 lines
lock held.
=20Quoted 1 line
To handle this opposite alternatives, I don't know whether checking =
if
Quoted 3 lines
Quoted 3 lines
the lock is held (and possibly taking it) from inside
e->type->ops.mq.allow_mergeis a good solution. In any case, before possibly trying it, I will wait for some feedback on the main =
problem,
Quoted 4 lines
Quoted 2 lines
i.e., on the fact that
e->type->ops.mq.allow_mergeseems unreachable in the above path.=20
Checking if a lock is held is NEVER a good idea, as it leads to both =
bad
Quoted 2 lines
and incorrect code. If you just check if a lock is held when being called, you don't necessarily know if it was the caller that grabbed =
it
Quoted 3 lines
or it just happens to be held by someone else for unrelated reasons. =20
=20
Thanks a lot for this and the above explanations. Unfortunately, I still see the problem. To hopefully make you waste less time, I have reported the problematic paths explicitly, so that you can quickly point me to my mistake.
The problem is caused by the existence of at least the following two alternative paths to e->type->ops.mq.allow_merge.
1. In mq-deadline.c (line 374): spin_lock(&dd->lock); blk_mq_sched_try_merge -> elv_merge -> elv_bio_merge_ok -> elv_iosched_allow_bio_merge -> e->type->ops.mq.allow_merge
2. In blk-core.c (line 1660): spin_lock_irq(q->queue_lock); elv_merge -> elv_bio_merge_ok -> elv_iosched_allow_bio_merge -> e->type->ops.mq.allow_merge
In the first path, the scheduler lock is held, while in the second path, it is not. This does not cause problems with mq-deadline, because the latter just has no allow_merge function. Yet it does cause problems with the allow_merge implementation of bfq. There was no issue in blk, as only the global queue lock was used.
Where am I wrong?
Thanks,
Paolo
Quoted 3 lines
--=20
Jens Axboe
=20
Quoted 69 lines
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected]> ha scritto:
Quoted 58 lines · Paolo Valente
Quoted 47 lines
Il giorno 19 dic 2016, alle ore 22:05, Jens Axboe <[email protected]> ha scritto:
Quoted 43 lines · Paolo Valente
Quoted 42 lines
Il giorno 19 dic 2016, alle ore 16:20, Jens Axboe <[email protected]> ha scritto:
Quoted 26 lines · Paolo Valente
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is version 4 of this patchset, version 3 was posted here:
https://marc.info/?l=linux-block&m=148178513407631&w=2
From the discussion last time, I looked into the feasibility of having two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
Quoted 5 lines
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
Quoted 3 lines
I'm to modifying bfq. You mentioned other missing pieces to come. Do you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
I'm mostly talking about elevator ops hooks that aren't there in the new framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in the
dispatch_requesthook for activate, and put/requeue for deactivate.Quoted 10 lines
Quoted 5 lines
You mean that there is no conceptual problem in moving the code of the activate interface function into the dispatch function, and the code of the deactivate into the
put_request? (for a requeue it is a little less clear to me, so one step at a time) Or am I missing something more complex?Yes, what I mean is that there isn't a 1:1 mapping between the old ops and the new ops. So you'll have to consider the cases.
Quoted 6 lines
Problem: whereas it seems easy and safe to do somewhere else the simple increment that was done in
activate_request, I wonder if it may happen that a request is deactivate before being completed. In it may happen, then, without adeactivate_requesthook, the increments would remain unbalanced. Or are request completions always guaranteed till no hw/sw components breaks?
Quoted 2 lines
You should be able to do it in get/put_request. But you might need some extra tracking, I'd need to double check.
Exactly, AFAICT something extra is apparently needed. In particular, get is not ok, because dispatch is a different event (but dispatch is however an already controlled event), while put could be used, provided that it is guaranteed to be executed only after dispatch. If it is not, then I think that an extra flag or something should be added to the request. I don't know whether adding this extra piece would be worst than adding an extra hook.
Quoted 5 lines
I'm trying to avoid adding
hooks that we don't truly need, the old interface had a lot of that. If you find that you need a hook and it isn't there, feel free to add it. activate/deactivate might be a good change.
If my comments above do not trigger any proposal of a better solution, then I will try by adding only one extra 'deactivate' hook. Unless unbalanced hooks are a bad idea too.
Thanks,
Paolo
Quoted 2 lines
Signature · 1 line
Jens Axboe
Quoted 69 lines
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected] <mailto:[email protected]>> ha scritto:
Quoted 58 lines · Paolo Valente
Quoted 47 lines
Il giorno 19 dic 2016, alle ore 22:05, Jens Axboe <[email protected] <mailto:[email protected]>> ha scritto:
Quoted 43 lines · Paolo Valente
Quoted 42 lines
Il giorno 19 dic 2016, alle ore 16:20, Jens Axboe <[email protected] <mailto:[email protected]>> ha scritto:
Quoted 26 lines · Paolo Valente
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected] <mailto:[email protected]>> ha scritto:
This is version 4 of this patchset, version 3 was posted here:
https://marc.info/?l=linux-block&m=148178513407631&w=2 <https://marc.info/?l=linux-block&m=148178513407631&w=2>
From the discussion last time, I looked into the feasibility of having two sets of tags for the same request pool, to avoid having to copy some of the request fields at dispatch and completion time. To do that, we'd have to replace the driver tag map(s) with our own, and augment that with tag map(s) on the side representing the device queue depth. Queuing IO with the scheduler would allocate from the new map, and dispatching would acquire the "real" tag. We would need to change drivers to do this, or add an extra indirection table to map a real tag to the scheduler tag. We would also need a 1:1 mapping between scheduler and hardware tag pools, or additional info to track it. Unless someone can convince me otherwise, I think the current approach is cleaner.
Quoted 5 lines
I wasn't going to post v4 so soon, but I discovered a bug that led to drastically decreased merging. Especially on rotating storage, this release should be fast, and on par with the merging that we get through the legacy schedulers.
Quoted 3 lines
I'm to modifying bfq. You mentioned other missing pieces to come. Do you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
I'm mostly talking about elevator ops hooks that aren't there in the new framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in the
dispatch_requesthook for activate, and put/requeue for deactivate.Quoted 10 lines
Quoted 5 lines
You mean that there is no conceptual problem in moving the code of the activate interface function into the dispatch function, and the code of the deactivate into the
put_request? (for a requeue it is a little less clear to me, so one step at a time) Or am I missing something more complex?Yes, what I mean is that there isn't a 1:1 mapping between the old ops and the new ops. So you'll have to consider the cases.
Quoted 6 lines
Problem: whereas it seems easy and safe to do somewhere else the simple increment that was done in
activate_request, I wonder if it may happen that a request is deactivate before being completed. In it may happen, then, without adeactivate_requesthook, the increments would remain unbalanced. Or are request completions always guaranteed till no hw/sw components breaks?
Quoted 2 lines
You should be able to do it in get/put_request. But you might need some extra tracking, I'd need to double check.
Exactly, AFAICT something extra is apparently needed. In particular, get is not ok, because dispatch is a different event (but dispatch is however an already controlled event), while put could be used, provided that it is guaranteed to be executed only after dispatch. If it is not, then I think that an extra flag or something should be added to the request. I don't know whether adding this extra piece would be worst than adding an extra hook.
Quoted 5 lines
I'm trying to avoid adding
hooks that we don't truly need, the old interface had a lot of that. If you find that you need a hook and it isn't there, feel free to add it. activate/deactivate might be a good change.
If my comments above do not trigger any proposal of a better solution, then I will try by adding only one extra 'deactivate' hook. Unless unbalanced hooks are a bad idea too.
Thanks,
Paolo
Quoted 2 lines
Signature · 1 line
Jens Axboe
[RESENDING, BECAUSE OF REJECT FROM SERVERS]
Quoted 14 lines
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected] <mailto:[email protected]>> ha scritto:
Quoted 10 lines · Paolo Valente
Quoted 3 lines
...
Problem: whereas it seems easy and safe to do somewhere else the simple increment that was done in
activate_request, I wonder if it may happen that a request is deactivate before being completed. In it may happen, then, without adeactivate_requesthook, the increments would remain unbalanced. Or are request completions always guaranteed till no hw/sw components breaks?
Quoted 2 lines
You should be able to do it in get/put_request. But you might need some extra tracking, I'd need to double check.
Exactly, AFAICT something extra is apparently needed. In particular, get is not ok, because dispatch is a different event (but dispatch is however an already controlled event), while put could be used, provided that it is guaranteed to be executed only after dispatch. If it is not, then I think that an extra flag or something should be added to the request. I don't know whether adding this extra piece would be worst than adding an extra hook.
Quoted 5 lines
I'm trying to avoid adding
hooks that we don't truly need, the old interface had a lot of that. If you find that you need a hook and it isn't there, feel free to add it. activate/deactivate might be a good change.
If my comments above do not trigger any proposal of a better solution, then I will try by adding only one extra 'deactivate' hook. Unless unbalanced hooks are a bad idea too.
Thanks,
Paolo
Quoted 2 lines
Signature · 1 line
Jens Axboe
[NEW RESEND ATTEMPT]
Quoted 1 line
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 19 dic 2016, alle ore 22:05, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 19 dic 2016, alle ore 16:20, Jens Axboe <[email protected]> =
ha scritto:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> =
ha scritto:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
=20
This is version 4 of this patchset, version 3 was posted here:
=20
https://marc.info/?l=3Dlinux-block&m=3D148178513407631&w=3D2
=20
=46rom the discussion last time, I looked into the feasibility =
of having
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
two sets of tags for the same request pool, to avoid having to =
copy
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
some of the request fields at dispatch and completion time. To =
do that,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
we'd have to replace the driver tag map(s) with our own, and =
augment
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
that with tag map(s) on the side representing the device queue =
depth.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Queuing IO with the scheduler would allocate from the new map, =
and
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
dispatching would acquire the "real" tag. We would need to =
change
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers to do this, or add an extra indirection table to map a =
real
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
tag to the scheduler tag. We would also need a 1:1 mapping =
between
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
scheduler and hardware tag pools, or additional info to track =
it.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Unless someone can convince me otherwise, I think the current =
approach
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
is cleaner.
=20
I wasn't going to post v4 so soon, but I discovered a bug that =
led
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
to drastically decreased merging. Especially on rotating =
storage,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
this release should be fast, and on par with the merging that we get through the legacy schedulers.
=20=20
I'm to modifying bfq. You mentioned other missing pieces to =
come. Do
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
=20
I'm mostly talking about elevator ops hooks that aren't there in =
the new
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
=20
On the ops side, the only ones I can think of are the activate and deactivate, and those can be done in thedispatch_requesthook for activate, and put/requeue for deactivate.
=20=20
You mean that there is no conceptual problem in moving the code of =
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
activate interface function into the dispatch function, and the =
code
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
of the deactivate into the
put_request? (for a requeue it is a =
little
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
less clear to me, so one step at a time) Or am I missing something more complex?
=20
Yes, what I mean is that there isn't a 1:1 mapping between the old =
ops
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
and the new ops. So you'll have to consider the cases. =20
=20=20
Problem: whereas it seems easy and safe to do somewhere else the simple increment that was done inactivate_request, I wonder if it =
may
Quoted 1 line
Quoted 1 line
happen that a request is deactivate before being completed. In it =
may
Quoted 5 lines
Quoted 3 lines
happen, then, without a
deactivate_requesthook, the increments would remain unbalanced. Or are request completions always guaranteed till no hw/sw components breaks?=20
You should be able to do it in get/put_request. But you might need =
some
Quoted 1 line
extra tracking, I'd need to double check.
Exactly, AFAICT something extra is apparently needed. In particular, get is not ok, because dispatch is a different event (but dispatch is however an already controlled event), while put could be used, provided that it is guaranteed to be executed only after dispatch. If it is not, then I think that an extra flag or something should be added to the request. I don't know whether adding this extra piece would be worst than adding an extra hook.
Quoted 3 lines
=20
I'm trying to avoid adding
hooks that we don't truly need, the old interface had a lot of that. =
If
Quoted 3 lines
you find that you need a hook and it isn't there, feel free to add it. activate/deactivate might be a good change.
=20
If my comments above do not trigger any proposal of a better solution, then I will try by adding only one extra 'deactivate' hook. Unless unbalanced hooks are a bad idea too.
Thanks,
Paolo
Quoted 2 lines
--=20
Jens Axboe
Re: [PATCH 6/8] blk-mq-sched: add framework for MQ capable IO schedulers
In reply to Paolo ValenteQuoted 101 lines · Paolo Valente
Quoted 78 lines
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected]> ha scritto:
Quoted 57 lines · Paolo Valente
Quoted 52 lines
Il giorno 22 dic 2016, alle ore 10:59, Paolo Valente <[email protected]> ha scritto:
Quoted 20 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This adds a set of hooks that intercepts the blk-mq path of allocating/inserting/issuing/completing requests, allowing us to develop a scheduler within that framework.
We reuse the existing elevator scheduler API on the registration side, but augment that with the scheduler flagging support for the blk-mq interfce, and with a separate set of ops hooks for MQ devices.
Schedulers can opt in to using shadow requests. Shadow requests are internal requests that the scheduler uses for for the allocate and insert part, which are then mapped to a real driver request at dispatch time. This is needed to separate the device queue depth from the pool of requests that the scheduler has to work with.
Signed-off-by Jens Axboe <[email protected]>...
Quoted 9 lines
block/blk-mq-sched.c new file +2
-0+static inline bool +blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,block/blk-mq-sched.c
Quoted 10 lines
block/blk-mq-sched.c new file +10
-0+ struct bio *bio) +{ +struct elevator_queue *e = q->elevator; + +if (e && e->type->ops.mq.allow_merge) +return e->type->ops.mq.allow_merge (q, rq, bio); + +return true; +} +Something does not seem to add up here:
e->type->ops.mq.allow_mergemay be called only inblk_mq_sched_allow_merge, which, in its turn, may be called only inblk_mq_attempt_merge, which, finally, may be called only inblk_mq_merge_queue_io. Yet the latter may be called only if there is no elevator (line 1399 and 1507 inblk-mq.c).Quoted 4 lines
Therefore,
e->type->ops.mq.allow_mergecan never be called, both if there is and if there is not an elevator. Be patient if I'm missing something huge, but I thought it was worth reporting this.Quoted 4 lines
Just another detail: if
e->type->ops.mq.allow_mergedoes get invoked from the above path, then it is invoked of course without the scheduler lock held. In contrast, if this function gets invoked fromdd_bio_merge, then the scheduler lock is held.But the scheduler controls that itself. So it'd be perfectly fine to have a locked and unlocked variant. The way that's typically done is to have
function()grabbing the lock, and__function()is invoked with the lock held.Quoted 6 lines
To handle this opposite alternatives, I don't know whether checking if the lock is held (and possibly taking it) from inside
e->type->ops.mq.allow_mergeis a good solution. In any case, before possibly trying it, I will wait for some feedback on the main problem, i.e., on the fact thate->type->ops.mq.allow_merge
seems unreachable in the above path.Quoted 6 lines
Checking if a lock is held is NEVER a good idea, as it leads to both bad and incorrect code. If you just check if a lock is held when being called, you don't necessarily know if it was the caller that grabbed it or it just happens to be held by someone else for unrelated reasons.
Thanks a lot for this and the above explanations. Unfortunately, I still see the problem. To hopefully make you waste less time, I have reported the problematic paths explicitly, so that you can quickly point me to my mistake.
The problem is caused by the existence of at least the following two alternative paths to
e->type->ops.mq.allow_merge.1. In
mq-deadline.c(line 374):spin_lock(&dd->lock);blk_mq_sched_try_merge->elv_merge->elv_bio_merge_ok->elv_iosched_allow_bio_merge->e->type->ops.mq.allow_merge2. In
blk-core.c(line 1660):spin_lock_irq(q->queue_lock);elv_merge->elv_bio_merge_ok->elv_iosched_allow_bio_merge->e->type->ops.mq.allow_merge
Quoted 7 lines
In the first path, the scheduler lock is held, while in the second path, it is not. This does not cause problems with mq-deadline, because the latter just has no
allow_mergefunction. Yet it does cause problems with theallow_mergeimplementation of bfq. There was no issue in blk, as only the global queue lock was used.Where am I wrong?
#2 can never happen for blk-mq, it's the old IO path. blk-mq is never invoked with ->queue_lock held.
Signature · 1 line
Jens Axboe
Quoted 2 lines
Il giorno 17 gen 2017, alle ore 11:49, Paolo Valente =
<[email protected]> ha scritto:
Quoted 4 lines
=20
[NEW RESEND ATTEMPT]
=20Quoted 1 line
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 19 dic 2016, alle ore 22:05, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 19 dic 2016, alle ore 16:20, Jens Axboe <[email protected]> =
ha scritto:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe =
<[email protected]> ha scritto:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
=20
This is version 4 of this patchset, version 3 was posted here:
=20
https://marc.info/?l=3Dlinux-block&m=3D148178513407631&w=3D2
=20
=46rom the discussion last time, I looked into the feasibility =
of having
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
two sets of tags for the same request pool, to avoid having to =
copy
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
some of the request fields at dispatch and completion time. To =
do that,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
we'd have to replace the driver tag map(s) with our own, and =
augment
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
that with tag map(s) on the side representing the device queue =
depth.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Queuing IO with the scheduler would allocate from the new map, =
and
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
dispatching would acquire the "real" tag. We would need to =
change
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers to do this, or add an extra indirection table to map a =
real
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
tag to the scheduler tag. We would also need a 1:1 mapping =
between
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
scheduler and hardware tag pools, or additional info to track =
it.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Unless someone can convince me otherwise, I think the current =
approach
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
is cleaner.
=20
I wasn't going to post v4 so soon, but I discovered a bug that =
led
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
to drastically decreased merging. Especially on rotating =
storage,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
this release should be fast, and on par with the merging that =
we
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
get through the legacy schedulers.
=20=20
I'm to modifying bfq. You mentioned other missing pieces to =
come. Do
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
you already have an idea of what they are, so that I am somehow prepared to what won't work even if my changes are right?
=20
I'm mostly talking about elevator ops hooks that aren't there in =
the new
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
framework, but exist in the old one. There should be no hidden surprises, if that's what you are worried about.
=20
On the ops side, the only ones I can think of are the activate =
and
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
deactivate, and those can be done in the
dispatch_requesthook =
for
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
activate, and put/requeue for deactivate.
=20=20
You mean that there is no conceptual problem in moving the code of =
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
activate interface function into the dispatch function, and the =
code
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
of the deactivate into the
put_request? (for a requeue it is a =
little
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
less clear to me, so one step at a time) Or am I missing something more complex?
=20
Yes, what I mean is that there isn't a 1:1 mapping between the old =
ops
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
and the new ops. So you'll have to consider the cases. =20
=20=20
Problem: whereas it seems easy and safe to do somewhere else the simple increment that was done inactivate_request, I wonder if it =
may
Quoted 1 line
Quoted 1 line
Quoted 1 line
happen that a request is deactivate before being completed. In it =
may
Quoted 1 line
Quoted 1 line
Quoted 1 line
happen, then, without a
deactivate_requesthook, the increments =
would
Quoted 1 line
Quoted 1 line
Quoted 1 line
remain unbalanced. Or are request completions always guaranteed =
till
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
no hw/sw components breaks?
=20
You should be able to do it in get/put_request. But you might need =
some
Quoted 13 lines
Quoted 1 line
extra tracking, I'd need to double check.
=20
Exactly, AFAICT something extra is apparently needed. In particular, get is not ok, because dispatch is a different event (but dispatch is however an already controlled event), while put could be used, provided that it is guaranteed to be executed only after dispatch. If it is not, then I think that an extra flag or something should be added to the request. I don't know whether adding this extra piece would be worst than adding an extra hook.
=20Quoted 3 lines
=20
I'm trying to avoid adding
hooks that we don't truly need, the old interface had a lot of that. =
If
Quoted 1 line
Quoted 1 line
you find that you need a hook and it isn't there, feel free to add =
it.
Quoted 7 lines
Quoted 2 lines
activate/deactivate might be a good change.
=20=20
If my comments above do not trigger any proposal of a better solution, then I will try by adding only one extra 'deactivate' hook. Unless unbalanced hooks are a bad idea too.
=20
Jens,
according to the function blk_mq_sched_put_request, the mq.completed_request hook seems to always be invoked (if set) for a request for which the mq.put_rq_priv is invoked (if set).
If you don't warn me that I'm wrong, I will base on the above assumption, and complete bfq without any additional hook or flag.
Thanks,
Paolo
Quoted 8 lines
Thanks,
Paolo
=20Quoted 2 lines
--=20
Jens Axboe=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 3 lines · Paolo Valente
according to the function
blk_mq_sched_put_request, the mq.completed_request hook seems to always be invoked (if set) for a request for which the mq.put_rq_priv is invoked (if set).
Correct, any request that came out of blk_mq_sched_get_request() will always have completed called on it, regardless of whether it had IO started on it or not.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20=20
One last question (for today ...):in mq-deadline there are no "schedule dispatch" or "unplug work" functions. In blk, CFQ and BFQ do these schedules/unplugs in a lot of cases. What's the right replacement? Just doing nothing?=20
You just useblk_mq_run_hw_queue()or variants thereof to kick off =
queue
Quoted 2 lines
runs.
=20
Hi Jens,
I'm working on this right now. I have a pair of quick questions about performance.
In the blk version of bfq, if the in-service bfq_queue happen to have no more budget when the bfq dispatch function is invoked, then bfq:
returns no request (NULL), immediately expires the in-service bfq_queue, and schedules a new dispatch. The third step is taken so that, if other bfq_queues have requests, then a new in-service bfq_queue will be selected on the upcoming new dispatch, and a new request will be provided right away.
My questions are: is this dispatch-schedule step still needed with blk-mq, to avoid a stall? If it is not needed to avoid a stall, would it still be needed to boost throughput, because it would force an immediate, next dispatch?
BTW, bfq-mq survived its first request completion. I will provide you with a link to a github branch as soon as bfq-mq seems able to stand up with a minimal workload.
Thanks,
Paolo
Quoted 3 lines
--=20
Jens Axboe
=20
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20
Jens,
no spin_lock_irq* in the code. So, also request dispatches are guaranteed to never be executed in IRQ context? I'm asking this question to understand whether I'm missing something that, even in BFQ, would somehow allow me to not disable irqs in critical sections, even if there is the slice_idle-expiration handler. Be patient with my ignorance.
Thanks,
Paolo
Quoted 5 lines
Signed-off-by Jens Axboe <[email protected]>---
block/Kconfig.iosched | 6 + block/Makefile | 1 + block/mq-deadline.c | 649 =
++++++++++++++++++++++++++++++++++++++++++++++++++
block/Makefile obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
Quoted 25 lines
3 files changed, 656 insertions(+)create mode 100644
block/mq-deadline.c
=20block/Kconfig.iosched +0
-0@@ -32,6 +32,12 @@ config IOSCHED_CFQ=20
This is the default I/O scheduler.
=20block/Kconfig.iosched +6
-0+config MQ_IOSCHED_DEADLINE + tristate "MQ deadline I/O scheduler" + default y + ---help--- + MQ version of the deadline IO scheduler. +config
CFQ_GROUP_IOSCHEDbool "CFQ Group Scheduling support" depends on IOSCHED_CFQ && BLK_CGROUPblock/Makefile +0
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
blk-throttle.o
Quoted 13 lines
obj-$(CONFIG_IOSCHED_NOOP) +=3D noop-iosched.o
obj-$(CONFIG_IOSCHED_DEADLINE) +=3D deadline-iosched.o
obj-$(CONFIG_IOSCHED_CFQ) +=3D cfq-iosched.o
+obj-$(CONFIG_MQ_IOSCHED_DEADLINE) +=3D mq-deadline.o
=20
obj-$(CONFIG_BLOCK_COMPAT) +=3D compat_ioctl.o
obj-$(CONFIG_BLK_CMDLINE_PARSER) +=3D cmdline-parser.oblock/mq-deadline.c new file +0
-0
block/mq-deadline.c line 2
Quoted 2 lines
block/mq-deadline.c new file +2
-0@@ -0,0 +1,649 @@ +/* +* MQ Deadline i/o scheduler - adaptation of the legacy deadline =
scheduler,
Quoted 15 lines
block/mq-deadline.c new file +15
-0+* for the blk-mq scheduling framework +* +* Copyright (C) 2016 Jens Axboe <[email protected]> +*/ +#include <linux/kernel.h> +#include <linux/fs.h> +#include <linux/blkdev.h> +#include <linux/blk-mq.h> +#include <linux/elevator.h> +#include <linux/bio.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/init.h> +#include <linux/compiler.h> +#include <linux/rbtree.h>
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+#include <linux/sbitmap.h> + +#include "blk.h" +#include "blk-mq.h" +#include "blk-mq-tag.h" +#include "blk-mq-sched.h" + +static unsigned int queue_depth =3D 256; +module_param (queue_depth, uint,0644 ); +MODULE_PARM_DESC(queue_depth, "Use this value as the scheduler queue =
depth");
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+ +/* +* See Documentation/block/deadline-iosched.txt +*/ +static const int read_expire =3D HZ / 2; /* max time before a read =
is submitted. */
block/mq-deadline.c line 33
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int write_expire =3D 5 * HZ; /* ditto for writes, these =
limits are SOFT! */
block/mq-deadline.c line 34
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int writes_starved =3D 2; /* max times reads can =
starve a write */
block/mq-deadline.c line 35
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int fifo_batch =3D 16; /* # of sequential requests =
treated as one
block/mq-deadline.c line 36
Quoted 1 line
block/mq-deadline.c new file +1
-0+ by the above parameters. For =
throughput. */
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ +struct deadline_data { +/* +* run time data +*/ + +/* +* requests (deadline_rq s) are present on both sort_list and =
fifo_list
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+*/ +struct rb_root sort_list[2 ]; +struct list_head fifo_list[2 ]; + +/* +* next in sort order. read, write or both are NULL +*/ +struct request *next_rq[2 ]; +unsigned int batching;/* number of sequential requests =
made */
block/mq-deadline.c line 54
Quoted 1 line
block/mq-deadline.c new file +1
-0+unsigned int starved;/* times reads have starved =
writes */
Quoted 48 lines
block/mq-deadline.c new file +48
-0+ +/* +* settings that change how the i/o scheduler behaves +*/ +int fifo_expire[2 ]; +int fifo_batch; +int writes_starved; +int front_merges; + +spinlock_t lock; +struct list_head dispatch; +struct blk_mq_tags *tags; +atomic_t wait_index; +}; + +static inline struct rb_root * +deadline_rb_root (struct deadline_data *dd,struct request *rq) +{ +return &dd->sort_list[rq_data_dir (rq)]; +} + +/* +* get the request after `rq' in sector-sorted order +*/ +static inline struct request * +deadline_latter_request (struct request *rq) +{ + struct rb_node *node =3D rb_next(&rq->rb_node); + +if (node) +return rb_entry_rq (node); + +return NULL ; +} + +static void +deadline_add_rq_rb (struct deadline_data *dd,struct request *rq) +{ + struct rb_root *root =3D deadline_rb_root(dd, rq); + +elv_rb_add (root, rq); +} + +static inline void +deadline_del_rq_rb (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ if (dd->next_rq[data_dir] =3D=3D rq) + dd->next_rq[data_dir] =3D deadline_latter_request(rq); + +elv_rb_del (deadline_rb_root (dd, rq), rq); +} + +/* +* remove rq from rbtree and fifo. +*/ +static void deadline_remove_request(struct request_queue *q, struct =
request *rq)
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct deadline_data *dd =3D q->elevator->elevator_data; + +list_del_init (&rq->queuelist); + +/* +* We might not be on the rbtree, if we are doing an insert =
merge
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+*/ +if (!RB_EMPTY_NODE (&rq->rb_node)) +deadline_del_rq_rb (dd, rq); + +elv_rqhash_del (q, rq); + if (q->last_merge =3D=3D rq) + q->last_merge =3D NULL; +} + +static void dd_request_merged(struct request_queue *q, struct request =
*req,
Quoted 4 lines
block/mq-deadline.c new file +4
-0+ int type) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+/* +* if the merge was a front merge, we need to reposition request +*/ + if (type =3D=3D ELEVATOR_FRONT_MERGE) { +elv_rb_del (deadline_rb_root (dd, req), req); +deadline_add_rq_rb (dd, req); + } +} + +static void dd_merged_requests(struct request_queue *q, struct =
request *req,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct request *next) +{ +/* +* if next expires before rq, assign its expire time to rq +* and move into next position (next will be deleted) in fifo +*/ + if (!list_empty(&req->queuelist) && =
!list_empty(&next->queuelist)) {
Quoted 23 lines
block/mq-deadline.c new file +23
-0+if (time_before ((unsigned long )next->fifo_time, + (unsigned long )req->fifo_time)) { +list_move (&req->queuelist, &next->queuelist); + req->fifo_time =3D next->fifo_time; + } + } + +/* +* kill knowledge of next, this one is a goner +*/ +deadline_remove_request (q, next); +} + +/* +* move an entry to dispatch queue +*/ +static void +deadline_move_request (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); + + dd->next_rq[READ] =3D NULL; + dd->next_rq[WRITE] =3D NULL;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ dd->next_rq[data_dir] =3D deadline_latter_request(rq); + +/* +* take it off the sort and fifo list +*/ +deadline_remove_request (rq->q, rq); +} + +/* +* deadline_check_fifo returns 0 if there are no expired requests on =
the fifo,
block/mq-deadline.c
Quoted 3 lines
block/mq-deadline.c new file +3
-0+* 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir]) +*/ +static inline int deadline_check_fifo(struct deadline_data *dd, int =
ddir)
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct request *rq =3D rq_entry_fifo(dd->fifo_list[ddir].next); + +/* +* rq is expired! +*/ +if (time_after_eq (jiffies, (unsigned long )rq->fifo_time))
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+return 1 ; + +return 0 ; +} + +/* +* deadline_dispatch_requests selects the best request according to +* read/write expire, fifo_batch, etc +*/ +static struct request *__dd_dispatch_request(struct blk_mq_hw_ctx =
*hctx)
block/mq-deadline.c line 205
Quoted 2 lines
block/mq-deadline.c new file +2
-0+{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+struct request *rq; +bool reads, writes; +int data_dir; + +spin_lock (&dd->lock); + +if (!list_empty (&dd->dispatch)) { + rq =3D list_first_entry(&dd->dispatch, struct request, =
queuelist);
Quoted 11 lines
block/mq-deadline.c new file +11
-0+list_del_init (&rq->queuelist); + goto done; + } + + reads =3D !list_empty(&dd->fifo_list[READ]); + writes =3D !list_empty(&dd->fifo_list[WRITE]); + +/* +* batches are currently reads XOR writes +*/ +if (dd->next_rq[WRITE ])
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ rq =3D dd->next_rq[WRITE]; + else + rq =3D dd->next_rq[READ]; + +if (rq && dd->batching < dd->fifo_batch) +/* we have a next request are still entitled to batch */ + goto dispatch_request; + +/* +* at this point we are not running a batch. select the =
appropriate
Quoted 25 lines
block/mq-deadline.c new file +25
-0+* data direction (read / write) +*/ + +if (reads) { +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[READ ])); + + if (writes && (dd->starved++ >=3D dd->writes_starved)) + goto dispatch_writes; + + data_dir =3D READ; + + goto dispatch_find_request; + } + +/* +* there are either no reads or writes have been starved +*/ + +if (writes) { +dispatch_writes: +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[WRITE ])); + + dd->starved =3D 0; + + data_dir =3D WRITE;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ + goto dispatch_find_request; + } + +spin_unlock (&dd->lock); +return NULL ; + +dispatch_find_request: +/* +* we are not running a batch, find best request for selected =
data_dir
block/mq-deadline.c line 271
Quoted 2 lines
block/mq-deadline.c new file +2
-0+*/ + if (deadline_check_fifo(dd, data_dir) || !dd->next_rq[data_dir]) =
{
block/mq-deadline.c line 273
Quoted 2 lines
block/mq-deadline.c new file +2
-0+/* +* A deadline has expired, the last request was in the =
other
block/mq-deadline.c line 274
Quoted 1 line
block/mq-deadline.c new file +1
-0+* direction, or we have run out of higher-sectored =
requests.
block/mq-deadline.c line 275
Quoted 1 line
block/mq-deadline.c new file +1
-0+* Start again from the request with the earliest expiry =
time.
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+*/ + rq =3D rq_entry_fifo(dd->fifo_list[data_dir].next); + }else { +/* +* The last req was the same dir and we have a next =
request in
block/mq-deadline.c line 281
Quoted 1 line
block/mq-deadline.c new file +1
-0+* sort order. No expired requests so continue on from =
here.
Quoted 12 lines
block/mq-deadline.c new file +12
-0+*/ + rq =3D dd->next_rq[data_dir]; + } + + dd->batching =3D 0; + +dispatch_request: +/* +* rq is the selected appropriate request. +*/ + dd->batching++; +deadline_move_request (dd, rq);
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+done: + rq->rq_flags |=3D RQF_STARTED; +spin_unlock (&dd->lock); +return rq; +} + +static void dd_dispatch_requests (struct blk_mq_hw_ctx *hctx, +struct list_head *rq_list) +{ + blk_mq_sched_dispatch_shadow_requests(hctx, rq_list, =
__dd_dispatch_request);
Quoted 7 lines
block/mq-deadline.c new file +7
-0+} + +static void dd_exit_queue (struct elevator_queue *e) +{ + struct deadline_data *dd =3D e->elevator_data; + +BUG_ON (!list_empty (&dd->fifo_list[READ ]));
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+BUG_ON (!list_empty (&dd->fifo_list[WRITE ])); + +blk_mq_sched_free_requests (dd->tags); +kfree (dd); +} + +/* +* initialize elevator private data (deadline_data). +*/ +static int dd_init_queue(struct request_queue *q, struct =
elevator_type *e)
Quoted 30 lines
block/mq-deadline.c new file +30
-0+{ +struct deadline_data *dd; +struct elevator_queue *eq; + + eq =3D elevator_alloc(q, e); +if (!eq) +return -ENOMEM ; + + dd =3D kzalloc_node(sizeof(*dd), GFP_KERNEL, q->node); +if (!dd) { +kobject_put (&eq->kobj); +return -ENOMEM ; + } + eq->elevator_data =3D dd; + + dd->tags =3D blk_mq_sched_alloc_requests(queue_depth, q->node); +if (!dd->tags) { +kfree (dd); +kobject_put (&eq->kobj); +return -ENOMEM ; + } + +INIT_LIST_HEAD (&dd->fifo_list[READ ]); +INIT_LIST_HEAD (&dd->fifo_list[WRITE ]); + dd->sort_list[READ] =3D RB_ROOT; + dd->sort_list[WRITE] =3D RB_ROOT; + dd->fifo_expire[READ] =3D read_expire; + dd->fifo_expire[WRITE] =3D write_expire; + dd->writes_starved =3D writes_starved; + dd->front_merges =3D 1;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ dd->fifo_batch =3D fifo_batch; +spin_lock_init (&dd->lock); +INIT_LIST_HEAD (&dd->dispatch); +atomic_set (&dd->wait_index,0 ); + + q->elevator =3D eq; +return 0 ; +} + +static int dd_request_merge(struct request_queue *q, struct request =
**rq,
Quoted 29 lines
block/mq-deadline.c new file +29
-0+ struct bio *bio) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; + sector_t sector =3D bio_end_sector(bio); +struct request *__rq; + +if (!dd->front_merges) +return ELEVATOR_NO_MERGE ; + + __rq =3D elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector); +if (__rq) { + BUG_ON(sector !=3D blk_rq_pos(__rq)); + +if (elv_bio_merge_ok (__rq, bio)) { + *rq =3D __rq; +return ELEVATOR_FRONT_MERGE ; + } + } + +return ELEVATOR_NO_MERGE ; +} + +static bool dd_bio_merge (struct blk_mq_hw_ctx *hctx,struct bio *bio) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; +int ret; + +spin_lock (&dd->lock);
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ ret =3D blk_mq_sched_try_merge(q, bio); +spin_unlock (&dd->lock); + +return ret; +} + +/* +* add rq to rbtree and fifo +*/ +static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq,
block/mq-deadline.c
Quoted 13 lines
block/mq-deadline.c new file +13
-0+ bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + const int data_dir =3D rq_data_dir(rq); + +if (blk_mq_sched_try_insert_merge (q, rq)) +return ; + +blk_mq_sched_request_inserted (rq); + +/* +* If we're trying to insert a real request, just send it =
directly
block/mq-deadline.c line 413
Quoted 1 line
block/mq-deadline.c new file +1
-0+* to the hardware dispatch list. This only happens for a =
requeue,
Quoted 32 lines
block/mq-deadline.c new file +32
-0+* or FUA/FLUSH requests. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) { +spin_lock (&hctx->lock); +list_add_tail (&rq->queuelist, &hctx->dispatch); +spin_unlock (&hctx->lock); +return ; + } + + if (at_head || rq->cmd_type !=3D REQ_TYPE_FS) { +if (at_head) +list_add (&rq->queuelist, &dd->dispatch); +else +list_add_tail (&rq->queuelist, &dd->dispatch); + }else { +deadline_add_rq_rb (dd, rq); + +if (rq_mergeable (rq)) { +elv_rqhash_add (q, rq); +if (!q->last_merge) + q->last_merge =3D rq; + } + +/* +* set expire time and add to fifo list +*/ + rq->fifo_time =3D jiffies + dd->fifo_expire[data_dir]; +list_add_tail (&rq->queuelist, &dd->fifo_list[data_dir]); + } +} + +static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ struct list_head *list, bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + +spin_lock (&dd->lock); +while (!list_empty (list)) { +struct request *rq; + + rq =3D list_first_entry(list, struct request, =
queuelist);
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+list_del_init (&rq->queuelist); +dd_insert_request (hctx, rq, at_head); + } +spin_unlock (&dd->lock); +} + +static struct request *dd_get_request(struct request_queue *q, =
unsigned int op,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct blk_mq_alloc_data *data) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +struct request *rq; + +/* +* The flush machinery intercepts before we insert the request. =
As
block/mq-deadline.c
Quoted 6 lines
block/mq-deadline.c new file +6
-0+* a work-around, just hand it back a real request. +*/ +if (unlikely (op & (REQ_PREFLUSH |REQ_FUA ))) + rq =3D __blk_mq_alloc_request(data, op); +else { + rq =3D blk_mq_sched_alloc_shadow_request(q, data, =
dd->tags, &dd->wait_index);
block/mq-deadline.c
Quoted 13 lines
block/mq-deadline.c new file +13
-0+if (rq) +blk_mq_rq_ctx_init (q, data->ctx, rq, op); + } + +return rq; +} + +static bool dd_put_request (struct request *rq) +{ +/* +* If it's a real request, we just have to free it. For a shadow +* request, we should only free it if we haven't started it. A +* started request is mapped to a real one, and the real one =
will
Quoted 13 lines
block/mq-deadline.c new file +13
-0+* free it. We can get here with request merges, since we then +* free the request before we start/issue it. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) +return false; + +if (!(rq->rq_flags &RQF_STARTED )) { + struct request_queue *q =3D rq->q; + struct deadline_data *dd =3D q->elevator->elevator_data; + +/* +* IO completion would normally do this, but if we merge +* and free before we issue the request, drop both the
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+* tag and queue ref +*/ +blk_mq_sched_free_shadow_request (dd->tags, rq); +blk_queue_exit (q); + } + +return true; +} + +static void dd_completed_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq)
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+{ + struct request *sched_rq =3D rq->end_io_data; + +/* +* sched_rq can be NULL, if we haven't setup the shadow yet +* because we failed getting one. +*/ +if (sched_rq) { + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+ +blk_mq_sched_free_shadow_request (dd->tags, sched_rq); +blk_mq_start_stopped_hw_queue (hctx, true); + } +} + +static bool dd_has_work (struct blk_mq_hw_ctx *hctx) +{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
Quoted 15 lines
block/mq-deadline.c new file +15
-0+ +return !list_empty_careful (&dd->dispatch) || + !list_empty_careful (&dd->fifo_list[0 ]) || + !list_empty_careful (&dd->fifo_list[1 ]); +} + +/* +* sysfs parts below +*/ +static ssize_t +deadline_var_show (int var,char *page) +{ +return sprintf (page,"%d\n" , var); +} +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+static ssize_t +deadline_var_store (int *var,const char *page,size_t count) +{ + char *p =3D (char *) page; + + *var =3D simple_strtol(p, &p, 10); +return count; +} + +#define SHOW_FUNCTION (__FUNC, __VAR, __CONV) =
\
block/mq-deadline.c line 555
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, char *page) =
\
block/mq-deadline.c line 556
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
block/mq-deadline.c line 557
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
block/mq-deadline.c line 558
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data =3D __VAR; =
\
block/mq-deadline.c line 559
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
block/mq-deadline.c line 560
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D jiffies_to_msecs(__data); =
\
block/mq-deadline.c line 561
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return deadline_var_show(__data, (page)); =
\
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+} +SHOW_FUNCTION (deadline_read_expire_show, dd->fifo_expire[READ ],1 ); +SHOW_FUNCTION (deadline_write_expire_show, dd->fifo_expire[WRITE ],1 ); +SHOW_FUNCTION (deadline_writes_starved_show, dd->writes_starved,0 ); +SHOW_FUNCTION (deadline_front_merges_show, dd->front_merges,0 ); +SHOW_FUNCTION (deadline_fifo_batch_show, dd->fifo_batch,0 ); +#undef SHOW_FUNCTION + +#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) =
\
block/mq-deadline.c line 571
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, const char *page, =
size_t count) \
block/mq-deadline.c line 572
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
block/mq-deadline.c line 573
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
block/mq-deadline.c line 574
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data; =
\
block/mq-deadline.c line 575
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int ret =3D deadline_var_store(&__data, (page), count); =
\
block/mq-deadline.c line 576
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__data < (MIN)) =
\
block/mq-deadline.c line 577
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MIN); =
\
block/mq-deadline.c line 578
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else if (__data > (MAX)) =
\
block/mq-deadline.c line 579
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MAX); =
\
block/mq-deadline.c line 580
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
block/mq-deadline.c line 581
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D msecs_to_jiffies(__data); =
\
block/mq-deadline.c line 582
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else =
\
block/mq-deadline.c line 583
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D __data; =
\
block/mq-deadline.c line 584
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return ret; =
\
block/mq-deadline.c line 586
Quoted 2 lines
block/mq-deadline.c new file +2
-0+} +STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, =
INT_MAX, 1);
block/mq-deadline.c line 587
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], =
0, INT_MAX, 1);
block/mq-deadline.c line 588
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, =
INT_MIN, INT_MAX, 0);
block/mq-deadline.c line 589
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, =
0);
block/mq-deadline.c line 590
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, =
INT_MAX, 0);
Quoted 60 lines
block/mq-deadline.c new file +59
-1+#undef STORE_FUNCTION + +#define DD_ATTR (name) \ + __ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \ + deadline_##name##_store) + +static struct elv_fs_entry deadline_attrs[] =3D { +DD_ATTR (read_expire), +DD_ATTR (write_expire), +DD_ATTR (writes_starved), +DD_ATTR (front_merges), +DD_ATTR (fifo_batch), + __ATTR_NULL +}; + +static struct elevator_type mq_deadline =3D { + .ops.mq =3D { + .get_request =3D dd_get_request, + .put_request =3D dd_put_request, + .insert_requests =3D dd_insert_requests, + .dispatch_requests =3D dd_dispatch_requests, + .completed_request =3D dd_completed_request, + .next_request =3D elv_rb_latter_request, + .former_request =3D elv_rb_former_request, + .bio_merge =3D dd_bio_merge, + .request_merge =3D dd_request_merge, + .requests_merged =3D dd_merged_requests, + .request_merged =3D dd_request_merged, + .has_work =3D dd_has_work, + .init_sched =3D dd_init_queue, + .exit_sched =3D dd_exit_queue, + }, + + .uses_mq =3D true, + .elevator_attrs =3D deadline_attrs, + .elevator_name =3D "mq-deadline", + .elevator_owner =3D THIS_MODULE, +}; + +static int __init deadline_init (void ) +{ +if (!queue_depth) { +pr_err ("mq-deadline: queue depth must be > 0\n" ); +return -EINVAL ; + } +return elv_register (&mq_deadline); +} + +static void __exit deadline_exit(void) +{ +elv_unregister (&mq_deadline); +} + +module_init (deadline_init); +module_exit (deadline_exit); + +MODULE_AUTHOR ("Jens Axboe" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("MQ deadline IO scheduler" ); --=20
Quoted 4 lines
2.7.4
=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
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 2 lines
Il giorno 20 gen 2017, alle ore 14:14, Paolo Valente =
<[email protected]> ha scritto:
Quoted 3 lines
=20
Quoted 2 lines
=20
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 8 lines
Quoted 4 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20=20
Jens,
no spin_lock_irq* in the code. So, also request dispatches are guaranteed to never be executed in IRQ context?
Or maybe the opposite? That is, all scheduler functions invoked in IRQ = context?
Thanks,
Paolo
Quoted 14 lines
I'm asking this
question to understand whether I'm missing something that, even in BFQ, would somehow allow me to not disable irqs in critical sections, even if there is the slice_idle-expiration handler. Be patient with my ignorance.
=20
Thanks,
Paolo
=20Quoted 5 lines
Signed-off-by Jens Axboe <[email protected]>---
block/Kconfig.iosched | 6 + block/Makefile | 1 + block/mq-deadline.c | 649 =
++++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 17 lines
Quoted 17 lines
3 files changed, 656 insertions(+)create mode 100644
block/mq-deadline.c
=20block/Kconfig.iosched +0
-0@@ -32,6 +32,12 @@ config IOSCHED_CFQ=20
This is the default I/O scheduler.
=20block/Kconfig.iosched +6
-0+config MQ_IOSCHED_DEADLINE + tristate "MQ deadline I/O scheduler" + default y + ---help--- + MQ version of the deadline IO scheduler. +
Quoted 8 lines
block/Makefile obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
Quoted 8 lines
config
CFQ_GROUP_IOSCHEDbool "CFQ Group Scheduling support" depends on IOSCHED_CFQ && BLK_CGROUPblock/Makefile +0
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
blk-throttle.o
Quoted 7 lines
Quoted 7 lines
obj-$(CONFIG_IOSCHED_NOOP) +=3D noop-iosched.o
obj-$(CONFIG_IOSCHED_DEADLINE) +=3D deadline-iosched.o
obj-$(CONFIG_IOSCHED_CFQ) +=3D cfq-iosched.o
+obj-$(CONFIG_MQ_IOSCHED_DEADLINE) +=3D mq-deadline.o
=20
obj-$(CONFIG_BLOCK_COMPAT) +=3D compat_ioctl.o
obj-$(CONFIG_BLK_CMDLINE_PARSER) +=3D cmdline-parser.o
Quoted 8 lines
block/mq-deadline.c line 2
Quoted 8 lines
block/mq-deadline.c new file +2
-0@@ -0,0 +1,649 @@ +/* +* MQ Deadline i/o scheduler - adaptation of the legacy deadline =
scheduler,
Quoted 17 lines
Quoted 17 lines
block/mq-deadline.c new file +17
-0+* for the blk-mq scheduling framework +* +* Copyright (C) 2016 Jens Axboe <[email protected]> +*/ +#include <linux/kernel.h> +#include <linux/fs.h> +#include <linux/blkdev.h> +#include <linux/blk-mq.h> +#include <linux/elevator.h> +#include <linux/bio.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/init.h> +#include <linux/compiler.h> +#include <linux/rbtree.h> +#include <linux/sbitmap.h> +
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+#include "blk.h" +#include "blk-mq.h" +#include "blk-mq-tag.h" +#include "blk-mq-sched.h" + +static unsigned int queue_depth =3D 256; +module_param (queue_depth, uint,0644 ); +MODULE_PARM_DESC(queue_depth, "Use this value as the scheduler queue =
depth");
Quoted 5 lines
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+ +/* +* See Documentation/block/deadline-iosched.txt +*/ +static const int read_expire =3D HZ / 2; /* max time before a read =
is submitted. */
Quoted 1 line
block/mq-deadline.c line 33
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int write_expire =3D 5 * HZ; /* ditto for writes, these =
limits are SOFT! */
Quoted 1 line
block/mq-deadline.c line 34
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int writes_starved =3D 2; /* max times reads can =
starve a write */
Quoted 1 line
block/mq-deadline.c line 35
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int fifo_batch =3D 16; /* # of sequential =
requests treated as one
Quoted 1 line
block/mq-deadline.c line 36
Quoted 1 line
block/mq-deadline.c new file +1
-0+ by the above parameters. For =
throughput. */
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ +struct deadline_data { +/* +* run time data +*/ + +/* +* requests (deadline_rq s) are present on both sort_list and =
fifo_list
Quoted 9 lines
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+*/ +struct rb_root sort_list[2 ]; +struct list_head fifo_list[2 ]; + +/* +* next in sort order. read, write or both are NULL +*/ +struct request *next_rq[2 ]; +unsigned int batching;/* number of sequential requests =
made */
Quoted 1 line
block/mq-deadline.c line 54
Quoted 1 line
block/mq-deadline.c new file +1
-0+unsigned int starved;/* times reads have starved =
writes */
Quoted 50 lines
Quoted 50 lines
block/mq-deadline.c new file +50
-0+ +/* +* settings that change how the i/o scheduler behaves +*/ +int fifo_expire[2 ]; +int fifo_batch; +int writes_starved; +int front_merges; + +spinlock_t lock; +struct list_head dispatch; +struct blk_mq_tags *tags; +atomic_t wait_index; +}; + +static inline struct rb_root * +deadline_rb_root (struct deadline_data *dd,struct request *rq) +{ +return &dd->sort_list[rq_data_dir (rq)]; +} + +/* +* get the request after `rq' in sector-sorted order +*/ +static inline struct request * +deadline_latter_request (struct request *rq) +{ + struct rb_node *node =3D rb_next(&rq->rb_node); + +if (node) +return rb_entry_rq (node); + +return NULL ; +} + +static void +deadline_add_rq_rb (struct deadline_data *dd,struct request *rq) +{ + struct rb_root *root =3D deadline_rb_root(dd, rq); + +elv_rb_add (root, rq); +} + +static inline void +deadline_del_rq_rb (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); + + if (dd->next_rq[data_dir] =3D=3D rq) + dd->next_rq[data_dir] =3D deadline_latter_request(rq);
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ +elv_rb_del (deadline_rb_root (dd, rq), rq); +} + +/* +* remove rq from rbtree and fifo. +*/ +static void deadline_remove_request(struct request_queue *q, struct =
request *rq)
Quoted 7 lines
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct deadline_data *dd =3D q->elevator->elevator_data; + +list_del_init (&rq->queuelist); + +/* +* We might not be on the rbtree, if we are doing an insert =
merge
Quoted 10 lines
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+*/ +if (!RB_EMPTY_NODE (&rq->rb_node)) +deadline_del_rq_rb (dd, rq); + +elv_rqhash_del (q, rq); + if (q->last_merge =3D=3D rq) + q->last_merge =3D NULL; +} + +static void dd_request_merged(struct request_queue *q, struct =
request *req,
Quoted 6 lines
Quoted 6 lines
block/mq-deadline.c new file +6
-0+ int type) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; + +/* +* if the merge was a front merge, we need to reposition request
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+*/ + if (type =3D=3D ELEVATOR_FRONT_MERGE) { +elv_rb_del (deadline_rb_root (dd, req), req); +deadline_add_rq_rb (dd, req); + } +} + +static void dd_merged_requests(struct request_queue *q, struct =
request *req,
Quoted 7 lines
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct request *next) +{ +/* +* if next expires before rq, assign its expire time to rq +* and move into next position (next will be deleted) in fifo +*/ + if (!list_empty(&req->queuelist) && =
!list_empty(&next->queuelist)) {
Quoted 25 lines
Quoted 25 lines
block/mq-deadline.c new file +25
-0+if (time_before ((unsigned long )next->fifo_time, + (unsigned long )req->fifo_time)) { +list_move (&req->queuelist, &next->queuelist); + req->fifo_time =3D next->fifo_time; + } + } + +/* +* kill knowledge of next, this one is a goner +*/ +deadline_remove_request (q, next); +} + +/* +* move an entry to dispatch queue +*/ +static void +deadline_move_request (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); + + dd->next_rq[READ] =3D NULL; + dd->next_rq[WRITE] =3D NULL; + dd->next_rq[data_dir] =3D deadline_latter_request(rq); +
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+/* +* take it off the sort and fifo list +*/ +deadline_remove_request (rq->q, rq); +} + +/* +* deadline_check_fifo returns 0 if there are no expired requests on =
the fifo,
Quoted 3 lines
block/mq-deadline.c
Quoted 3 lines
block/mq-deadline.c new file +3
-0+* 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir]) +*/ +static inline int deadline_check_fifo(struct deadline_data *dd, int =
ddir)
Quoted 9 lines
Quoted 9 lines
block/mq-deadline.c new file +9
-0+{ + struct request *rq =3D rq_entry_fifo(dd->fifo_list[ddir].next); + +/* +* rq is expired! +*/ +if (time_after_eq (jiffies, (unsigned long )rq->fifo_time)) +return 1 ; +
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+return 0 ; +} + +/* +* deadline_dispatch_requests selects the best request according to +* read/write expire, fifo_batch, etc +*/ +static struct request *__dd_dispatch_request(struct blk_mq_hw_ctx =
*hctx)
Quoted 2 lines
block/mq-deadline.c line 205
Quoted 2 lines
block/mq-deadline.c new file +2
-0+{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+struct request *rq; +bool reads, writes; +int data_dir; + +spin_lock (&dd->lock); + +if (!list_empty (&dd->dispatch)) { + rq =3D list_first_entry(&dd->dispatch, struct request, =
queuelist);
Quoted 13 lines
Quoted 13 lines
block/mq-deadline.c new file +13
-0+list_del_init (&rq->queuelist); + goto done; + } + + reads =3D !list_empty(&dd->fifo_list[READ]); + writes =3D !list_empty(&dd->fifo_list[WRITE]); + +/* +* batches are currently reads XOR writes +*/ +if (dd->next_rq[WRITE ]) + rq =3D dd->next_rq[WRITE]; +else
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ rq =3D dd->next_rq[READ]; + +if (rq && dd->batching < dd->fifo_batch) +/* we have a next request are still entitled to batch */ + goto dispatch_request; + +/* +* at this point we are not running a batch. select the =
appropriate
Quoted 27 lines
Quoted 27 lines
block/mq-deadline.c new file +27
-0+* data direction (read / write) +*/ + +if (reads) { +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[READ ])); + + if (writes && (dd->starved++ >=3D dd->writes_starved)) + goto dispatch_writes; + + data_dir =3D READ; + + goto dispatch_find_request; + } + +/* +* there are either no reads or writes have been starved +*/ + +if (writes) { +dispatch_writes: +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[WRITE ])); + + dd->starved =3D 0; + + data_dir =3D WRITE; + + goto dispatch_find_request;
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ } + +spin_unlock (&dd->lock); +return NULL ; + +dispatch_find_request: +/* +* we are not running a batch, find best request for selected =
data_dir
Quoted 2 lines
block/mq-deadline.c line 271
Quoted 2 lines
block/mq-deadline.c new file +2
-0+*/ + if (deadline_check_fifo(dd, data_dir) || !dd->next_rq[data_dir]) =
{
Quoted 2 lines
block/mq-deadline.c line 273
Quoted 2 lines
block/mq-deadline.c new file +2
-0+/* +* A deadline has expired, the last request was in the =
other
Quoted 1 line
block/mq-deadline.c line 274
Quoted 1 line
block/mq-deadline.c new file +1
-0+* direction, or we have run out of higher-sectored =
requests.
Quoted 1 line
block/mq-deadline.c line 275
Quoted 1 line
block/mq-deadline.c new file +1
-0+* Start again from the request with the earliest expiry =
time.
Quoted 5 lines
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+*/ + rq =3D rq_entry_fifo(dd->fifo_list[data_dir].next); + }else { +/* +* The last req was the same dir and we have a next =
request in
Quoted 1 line
block/mq-deadline.c line 281
Quoted 1 line
block/mq-deadline.c new file +1
-0+* sort order. No expired requests so continue on from =
here.
Quoted 14 lines
Quoted 14 lines
block/mq-deadline.c new file +14
-0+*/ + rq =3D dd->next_rq[data_dir]; + } + + dd->batching =3D 0; + +dispatch_request: +/* +* rq is the selected appropriate request. +*/ + dd->batching++; +deadline_move_request (dd, rq); +done: + rq->rq_flags |=3D RQF_STARTED;
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+spin_unlock (&dd->lock); +return rq; +} + +static void dd_dispatch_requests (struct blk_mq_hw_ctx *hctx, +struct list_head *rq_list) +{ + blk_mq_sched_dispatch_shadow_requests(hctx, rq_list, =
__dd_dispatch_request);
Quoted 9 lines
Quoted 9 lines
block/mq-deadline.c new file +9
-0+} + +static void dd_exit_queue (struct elevator_queue *e) +{ + struct deadline_data *dd =3D e->elevator_data; + +BUG_ON (!list_empty (&dd->fifo_list[READ ])); +BUG_ON (!list_empty (&dd->fifo_list[WRITE ])); +
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+blk_mq_sched_free_requests (dd->tags); +kfree (dd); +} + +/* +* initialize elevator private data (deadline_data). +*/ +static int dd_init_queue(struct request_queue *q, struct =
elevator_type *e)
Quoted 32 lines
Quoted 32 lines
block/mq-deadline.c new file +32
-0+{ +struct deadline_data *dd; +struct elevator_queue *eq; + + eq =3D elevator_alloc(q, e); +if (!eq) +return -ENOMEM ; + + dd =3D kzalloc_node(sizeof(*dd), GFP_KERNEL, q->node); +if (!dd) { +kobject_put (&eq->kobj); +return -ENOMEM ; + } + eq->elevator_data =3D dd; + + dd->tags =3D blk_mq_sched_alloc_requests(queue_depth, q->node); +if (!dd->tags) { +kfree (dd); +kobject_put (&eq->kobj); +return -ENOMEM ; + } + +INIT_LIST_HEAD (&dd->fifo_list[READ ]); +INIT_LIST_HEAD (&dd->fifo_list[WRITE ]); + dd->sort_list[READ] =3D RB_ROOT; + dd->sort_list[WRITE] =3D RB_ROOT; + dd->fifo_expire[READ] =3D read_expire; + dd->fifo_expire[WRITE] =3D write_expire; + dd->writes_starved =3D writes_starved; + dd->front_merges =3D 1; + dd->fifo_batch =3D fifo_batch; +spin_lock_init (&dd->lock);
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+INIT_LIST_HEAD (&dd->dispatch); +atomic_set (&dd->wait_index,0 ); + + q->elevator =3D eq; +return 0 ; +} + +static int dd_request_merge(struct request_queue *q, struct request =
**rq,
Quoted 15 lines
Quoted 15 lines
block/mq-deadline.c new file +15
-0+ struct bio *bio) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; + sector_t sector =3D bio_end_sector(bio); +struct request *__rq; + +if (!dd->front_merges) +return ELEVATOR_NO_MERGE ; + + __rq =3D elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector); +if (__rq) { + BUG_ON(sector !=3D blk_rq_pos(__rq)); + +if (elv_bio_merge_ok (__rq, bio)) { + *rq =3D __rq;
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+return ELEVATOR_FRONT_MERGE ; + } + } + +return ELEVATOR_NO_MERGE ; +} + +static bool dd_bio_merge(struct blk_mq_hw_ctx *hctx, struct bio =
*bio)
Quoted 8 lines
Quoted 8 lines
block/mq-deadline.c new file +8
-0+{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; +int ret; + +spin_lock (&dd->lock); + ret =3D blk_mq_sched_try_merge(q, bio); +spin_unlock (&dd->lock);
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ +return ret; +} + +/* +* add rq to rbtree and fifo +*/ +static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq,
Quoted 5 lines
Quoted 5 lines
block/mq-deadline.c new file +5
-0+ bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + const int data_dir =3D rq_data_dir(rq);
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ +if (blk_mq_sched_try_insert_merge (q, rq)) +return ; + +blk_mq_sched_request_inserted (rq); + +/* +* If we're trying to insert a real request, just send it =
directly
Quoted 1 line
block/mq-deadline.c line 413
Quoted 1 line
block/mq-deadline.c new file +1
-0+* to the hardware dispatch list. This only happens for a =
requeue,
Quoted 34 lines
Quoted 34 lines
block/mq-deadline.c new file +34
-0+* or FUA/FLUSH requests. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) { +spin_lock (&hctx->lock); +list_add_tail (&rq->queuelist, &hctx->dispatch); +spin_unlock (&hctx->lock); +return ; + } + + if (at_head || rq->cmd_type !=3D REQ_TYPE_FS) { +if (at_head) +list_add (&rq->queuelist, &dd->dispatch); +else +list_add_tail (&rq->queuelist, &dd->dispatch); + }else { +deadline_add_rq_rb (dd, rq); + +if (rq_mergeable (rq)) { +elv_rqhash_add (q, rq); +if (!q->last_merge) + q->last_merge =3D rq; + } + +/* +* set expire time and add to fifo list +*/ + rq->fifo_time =3D jiffies + dd->fifo_expire[data_dir]; +list_add_tail (&rq->queuelist, &dd->fifo_list[data_dir]); + } +} + +static void dd_insert_requests (struct blk_mq_hw_ctx *hctx, +struct list_head *list,bool at_head) +{
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + +spin_lock (&dd->lock); +while (!list_empty (list)) { +struct request *rq; + + rq =3D list_first_entry(list, struct request, =
queuelist);
Quoted 7 lines
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+list_del_init (&rq->queuelist); +dd_insert_request (hctx, rq, at_head); + } +spin_unlock (&dd->lock); +} + +static struct request *dd_get_request(struct request_queue *q, =
unsigned int op,
Quoted 7 lines
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct blk_mq_alloc_data *data) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +struct request *rq; + +/* +* The flush machinery intercepts before we insert the request. =
As
Quoted 6 lines
block/mq-deadline.c
Quoted 6 lines
block/mq-deadline.c new file +6
-0+* a work-around, just hand it back a real request. +*/ +if (unlikely (op & (REQ_PREFLUSH |REQ_FUA ))) + rq =3D __blk_mq_alloc_request(data, op); +else { + rq =3D blk_mq_sched_alloc_shadow_request(q, data, =
dd->tags, &dd->wait_index);
Quoted 5 lines
Quoted 5 lines
block/mq-deadline.c new file +5
-0+if (rq) +blk_mq_rq_ctx_init (q, data->ctx, rq, op); + } + +return rq;
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+} + +static bool dd_put_request (struct request *rq) +{ +/* +* If it's a real request, we just have to free it. For a shadow +* request, we should only free it if we haven't started it. A +* started request is mapped to a real one, and the real one =
will
Quoted 15 lines
Quoted 15 lines
block/mq-deadline.c new file +15
-0+* free it. We can get here with request merges, since we then +* free the request before we start/issue it. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) +return false; + +if (!(rq->rq_flags &RQF_STARTED )) { + struct request_queue *q =3D rq->q; + struct deadline_data *dd =3D q->elevator->elevator_data; + +/* +* IO completion would normally do this, but if we merge +* and free before we issue the request, drop both the +* tag and queue ref +*/
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+blk_mq_sched_free_shadow_request (dd->tags, rq); +blk_queue_exit (q); + } + +return true; +} + +static void dd_completed_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq)
Quoted 9 lines
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+{ + struct request *sched_rq =3D rq->end_io_data; + +/* +* sched_rq can be NULL, if we haven't setup the shadow yet +* because we failed getting one. +*/ +if (sched_rq) { + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
Quoted 9 lines
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+ +blk_mq_sched_free_shadow_request (dd->tags, sched_rq); +blk_mq_start_stopped_hw_queue (hctx, true); + } +} + +static bool dd_has_work (struct blk_mq_hw_ctx *hctx) +{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
Quoted 17 lines
Quoted 17 lines
block/mq-deadline.c new file +17
-0+ +return !list_empty_careful (&dd->dispatch) || + !list_empty_careful (&dd->fifo_list[0 ]) || + !list_empty_careful (&dd->fifo_list[1 ]); +} + +/* +* sysfs parts below +*/ +static ssize_t +deadline_var_show (int var,char *page) +{ +return sprintf (page,"%d\n" , var); +} + +static ssize_t +deadline_var_store (int *var,const char *page,size_t count)
Quoted 8 lines
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+{ + char *p =3D (char *) page; + + *var =3D simple_strtol(p, &p, 10); +return count; +} + +#define SHOW_FUNCTION (__FUNC, __VAR, __CONV) =
\
Quoted 1 line
block/mq-deadline.c line 555
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, char *page) =
\
Quoted 1 line
block/mq-deadline.c line 556
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
Quoted 1 line
block/mq-deadline.c line 557
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
Quoted 1 line
block/mq-deadline.c line 558
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data =3D __VAR; =
\
Quoted 1 line
block/mq-deadline.c line 559
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
Quoted 1 line
block/mq-deadline.c line 560
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D jiffies_to_msecs(__data); =
\
Quoted 1 line
block/mq-deadline.c line 561
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return deadline_var_show(__data, (page)); =
\
Quoted 3 lines
block/mq-deadline.c
Quoted 3 lines
block/mq-deadline.c new file +3
-0+} +SHOW_FUNCTION (deadline_read_expire_show, dd->fifo_expire[READ ],1 ); +SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[WRITE], =
1);
Quoted 6 lines
block/mq-deadline.c
Quoted 6 lines
block/mq-deadline.c new file +6
-0+SHOW_FUNCTION (deadline_writes_starved_show, dd->writes_starved,0 ); +SHOW_FUNCTION (deadline_front_merges_show, dd->front_merges,0 ); +SHOW_FUNCTION (deadline_fifo_batch_show, dd->fifo_batch,0 ); +#undef SHOW_FUNCTION + +#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) =
\
Quoted 1 line
block/mq-deadline.c line 571
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, const char *page, =
size_t count) \
Quoted 1 line
block/mq-deadline.c line 572
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
Quoted 1 line
block/mq-deadline.c line 573
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
Quoted 1 line
block/mq-deadline.c line 574
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data; =
\
Quoted 1 line
block/mq-deadline.c line 575
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int ret =3D deadline_var_store(&__data, (page), count); =
\
Quoted 1 line
block/mq-deadline.c line 576
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__data < (MIN)) =
\
Quoted 1 line
block/mq-deadline.c line 577
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MIN); =
\
Quoted 1 line
block/mq-deadline.c line 578
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else if (__data > (MAX)) =
\
Quoted 1 line
block/mq-deadline.c line 579
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MAX); =
\
Quoted 1 line
block/mq-deadline.c line 580
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
Quoted 1 line
block/mq-deadline.c line 581
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D msecs_to_jiffies(__data); =
\
Quoted 1 line
block/mq-deadline.c line 582
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else =
\
Quoted 1 line
block/mq-deadline.c line 583
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D __data; =
\
Quoted 1 line
block/mq-deadline.c line 584
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return ret; =
\
Quoted 2 lines
block/mq-deadline.c line 586
Quoted 2 lines
block/mq-deadline.c new file +2
-0+} +STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], =
0, INT_MAX, 1);
Quoted 1 line
block/mq-deadline.c line 587
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], =
0, INT_MAX, 1);
Quoted 1 line
block/mq-deadline.c line 588
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, =
INT_MIN, INT_MAX, 0);
Quoted 1 line
block/mq-deadline.c line 589
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, =
0);
Quoted 1 line
block/mq-deadline.c line 590
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, =
INT_MAX, 0);
Quoted 56 lines
Quoted 56 lines
block/mq-deadline.c new file +56
-0+#undef STORE_FUNCTION + +#define DD_ATTR (name) \ + __ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \ + deadline_##name##_store) + +static struct elv_fs_entry deadline_attrs[] =3D { +DD_ATTR (read_expire), +DD_ATTR (write_expire), +DD_ATTR (writes_starved), +DD_ATTR (front_merges), +DD_ATTR (fifo_batch), + __ATTR_NULL +}; + +static struct elevator_type mq_deadline =3D { + .ops.mq =3D { + .get_request =3D dd_get_request, + .put_request =3D dd_put_request, + .insert_requests =3D dd_insert_requests, + .dispatch_requests =3D dd_dispatch_requests, + .completed_request =3D dd_completed_request, + .next_request =3D elv_rb_latter_request, + .former_request =3D elv_rb_former_request, + .bio_merge =3D dd_bio_merge, + .request_merge =3D dd_request_merge, + .requests_merged =3D dd_merged_requests, + .request_merged =3D dd_request_merged, + .has_work =3D dd_has_work, + .init_sched =3D dd_init_queue, + .exit_sched =3D dd_exit_queue, + }, + + .uses_mq =3D true, + .elevator_attrs =3D deadline_attrs, + .elevator_name =3D "mq-deadline", + .elevator_owner =3D THIS_MODULE, +}; + +static int __init deadline_init (void ) +{ +if (!queue_depth) { +pr_err ("mq-deadline: queue depth must be > 0\n" ); +return -EINVAL ; + } +return elv_register (&mq_deadline); +} + +static void __exit deadline_exit(void) +{ +elv_unregister (&mq_deadline); +} + +module_init (deadline_init); +module_exit (deadline_exit); +
Quoted 8 lines
Quoted 8 lines
block/mq-deadline.c new file +3
-1+MODULE_AUTHOR ("Jens Axboe" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("MQ deadline IO scheduler" ); --=202.7.4
=20
--
To unsubscribe from this list: send the line "unsubscribe =
linux-block" in
Quoted 5 lines
Quoted 2 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html=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
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Paolo ValenteQuoted 32 lines · Paolo Valente
Quoted 11 lines
Il giorno 17 gen 2017, alle ore 03:47, Jens Axboe <[email protected]> ha scritto:
Quoted 7 lines · Paolo Valente
Quoted 6 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design.
Quoted 8 lines
Quoted 4 lines
One last question (for today ...):in mq-deadline there are no "schedule dispatch" or "unplug work" functions. In blk, CFQ and BFQ do these schedules/unplugs in a lot of cases. What's the right replacement? Just doing nothing?
You just use
blk_mq_run_hw_queue()or variants thereof to kick off queue runs.Hi Jens,
I'm working on this right now. I have a pair of quick questions about performance.In the blk version of bfq, if the in-service
bfq_queuehappen to have no more budget when the bfq dispatch function is invoked, then bfq:
returns no request (NULL), immediately expires the in-servicebfq_queue, and schedules a new dispatch. The third step is taken so that, if otherbfq_queueshave requests, then a new in-servicebfq_queuewill be selected on the upcoming new dispatch, and a new request will be provided right away.
Quoted 4 lines
My questions are: is this dispatch-schedule step still needed with blk-mq, to avoid a stall? If it is not needed to avoid a stall, would it still be needed to boost throughput, because it would force an immediate, next dispatch?
Generally that step is only needed if you don't dispatch a request for that invocation, yet you have requests to dispatch. For that case, you must ensure that the queues are run at some point in the future. So I'm inclined to answer yes to your question, though it depends on exactly how it happens. If you have the queue run in the code, comment it like that, and we can always revisit.
Quoted 3 lines
BTW, bfq-mq survived its first request completion. I will provide you with a link to a github branch as soon as bfq-mq seems able to stand up with a minimal workload.
Congratulations, that's a nice milestone!
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Paolo ValenteQuoted 7 lines · Paolo Valente
Quoted 6 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design.
Quoted 7 lines
Jens,
no spin_lock_irq* in the code. So, also request dispatches are guaranteed to never be executed in IRQ context? I'm asking this question to understand whether I'm missing something that, even in BFQ, would somehow allow me to not disable irqs in critical sections, even if there is the slice_idle-expiration handler. Be patient with my ignorance.
Yes, dispatches will never happen from IRQ context. blk-mq was designed so we didn't have to use irq disabling locks.
That said, certain parts of the API can be called from IRQ context. put_request and the completion parts, for instance. But blk-mq doesn't need to grab any locks there, and neither does mq-deadline. This might be different from bfq. lockdep can be a big help there.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Paolo ValenteQuoted 10 lines · Paolo Valente
Quoted 10 lines
Il giorno 20 gen 2017, alle ore 14:14, Paolo Valente <[email protected]> ha scritto:
Quoted 6 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design.
Quoted 5 lines
Quoted 3 lines
Jens,
no spin_lock_irq* in the code. So, also request dispatches are guaranteed to never be executed in IRQ context?Or maybe the opposite? That is, all scheduler functions invoked in IRQ context?
Nope
Signature · 1 line
Jens Axboe
Quoted 2 lines
Il giorno 18 gen 2017, alle ore 17:21, Jens Axboe <[email protected]> ha =
scritto:
Quoted 10 lines
=20
Quoted 3 lines · Paolo Valente
according to the function
blk_mq_sched_put_request, the mq.completed_request hook seems to always be invoked (if set) for a request for which the mq.put_rq_priv is invoked (if set).=20
Correct, any request that came out ofblk_mq_sched_get_request()will always have completed called on it, regardless of whether it had IO started on it or not.
=20
It seems that some request, after being dispatched, happens to have no mq.put_rq_priv invoked on it now or then. Is it expected? If it is, could you point me to the path through which the end of the life of such a request is handled?
Thanks,
Paolo
Quoted 3 lines
--=20
Jens Axboe
=20
Quoted 13 lines · Paolo Valente
Quoted 12 lines
Il giorno 18 gen 2017, alle ore 17:21, Jens Axboe <[email protected]> ha scritto:
Quoted 3 lines · Paolo Valente
according to the function
blk_mq_sched_put_request, the mq.completed_request hook seems to always be invoked (if set) for a request for which the mq.put_rq_priv is invoked (if set).Correct, any request that came out of
blk_mq_sched_get_request()will always have completed called on it, regardless of whether it had IO started on it or not.
Quoted 4 lines
It seems that some request, after being dispatched, happens to have no mq.put_rq_priv invoked on it now or then. Is it expected? If it is, could you point me to the path through which the end of the life of such a request is handled?
I'm guessing that's a flush request. I added RQF_QUEUED to check for that, if RQF_QUEUED is set, you know it has come from your get_request handler.
I'm assuming that is it, let me know.
Signature · 1 line
Jens Axboe
Quoted 2 lines
Il giorno 23 gen 2017, alle ore 18:42, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 18 gen 2017, alle ore 17:21, Jens Axboe <[email protected]> ha =
scritto:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
=20
Quoted 3 lines · Paolo Valente
according to the function
blk_mq_sched_put_request, the mq.completed_request hook seems to always be invoked (if set) for a request for which the mq.put_rq_priv is invoked (if set).
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
=20
Correct, any request that came out ofblk_mq_sched_get_request()will always have completed called on it, regardless of whether it had IO started on it or not.
=20=20
It seems that some request, after being dispatched, happens to have =
no
Quoted 8 lines
Quoted 3 lines
mq.put_rq_priv invoked on it now or then. Is it expected? If it is, could you point me to the path through which the end of the life of such a request is handled?
=20
I'm guessing that's a flush request. I addedRQF_QUEUEDto check for that, ifRQF_QUEUEDis set, you know it has come from yourget_requesthandler.
=20
Exactly, the completion-without-put_rq_priv pattern seems to occur only for requests coming from the flusher, precisely because they have the flag RQF_ELVPRIV unset. Just to understand: why is this flag unset for these requests, if they do have private elevator (bfq) data attached? What am I misunderstanding?
Just to be certain: this should be the only case where the completed_request hook is invoked while the put_rq_priv is not, right?
Thanks,
Paolo
Quoted 5 lines
I'm assuming that is it, let me know.
=20
--=20
Jens Axboe
=20
Quoted 27 lines · Paolo Valente
Quoted 17 lines
Il giorno 23 gen 2017, alle ore 18:42, Jens Axboe <[email protected]> ha scritto:
Quoted 13 lines · Paolo Valente
Quoted 12 lines
Il giorno 18 gen 2017, alle ore 17:21, Jens Axboe <[email protected]> ha scritto:
Quoted 3 lines · Paolo Valente
according to the function
blk_mq_sched_put_request, the mq.completed_request hook seems to always be invoked (if set) for a request for which the mq.put_rq_priv is invoked (if set).Correct, any request that came out of
blk_mq_sched_get_request()will always have completed called on it, regardless of whether it had IO started on it or not.Quoted 9 lines
Quoted 4 lines
It seems that some request, after being dispatched, happens to have no mq.put_rq_priv invoked on it now or then. Is it expected? If it is, could you point me to the path through which the end of the life of such a request is handled?
I'm guessing that's a flush request. I added
RQF_QUEUEDto check for that, ifRQF_QUEUEDis set, you know it has come from yourget_requesthandler.
Quoted 8 lines
Exactly, the completion-without-put_rq_priv pattern seems to occur only for requests coming from the flusher, precisely because they have the flag
RQF_ELVPRIVunset. Just to understand: why is this flag unset for these requests, if they do have private elevator (bfq) data attached? What am I misunderstanding?Just to be certain: this should be the only case where the
completed_requesthook is invoked while theput_rq_privis not, right?
They must NOT have scheduler data attached. In your get_request function, you must bypass if blk_mq_sched_bypass_insert() returns true. See how mq-deadline does that. This is important, or you will get hangs with flushes as well, since the IO scheduler private data and the flush data is unionized in the request.
Signature · 1 line
Jens Axboe
Quoted 2 lines
Il giorno 25 gen 2017, alle ore 17:13, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 23 gen 2017, alle ore 18:42, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 18 gen 2017, alle ore 17:21, Jens Axboe <[email protected]> =
ha scritto:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
according to the function
blk_mq_sched_put_request, the mq.completed_request hook seems to always be invoked (if set) for =
a
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
request for which the mq.put_rq_priv is invoked (if set).
=20
Correct, any request that came out ofblk_mq_sched_get_request()will always have completed called on it, regardless of whether it had IO started on it or not.
=20=20
It seems that some request, after being dispatched, happens to have =
no
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
mq.put_rq_priv invoked on it now or then. Is it expected? If it =
is,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
could you point me to the path through which the end of the life of such a request is handled?
=20
I'm guessing that's a flush request. I addedRQF_QUEUEDto check for that, ifRQF_QUEUEDis set, you know it has come from your =
get_request
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
handler.
=20=20
Exactly, the completion-without-put_rq_priv pattern seems to occur only for requests coming from the flusher, precisely because they =
have
Quoted 6 lines
Quoted 6 lines
the flag
RQF_ELVPRIVunset. Just to understand: why is this flag unset for these requests, if they do have private elevator (bfq) data attached? What am I misunderstanding?
=20
Just to be certain: this should be the only case where thecompleted_requesthook is invoked while theput_rq_privis not, =
right?
Quoted 3 lines
=20
They must NOT have scheduler data attached. In yourget_requestfunction, you must bypass ifblk_mq_sched_bypass_insert()returns =
true.
Yes, sorry. I'm already using blk_mq_sched_bypass_insert() to bypass insertion in the insert hook, as done in mq-deadline, and I have no get_request defined (see below).
The source of my confusion was that I assumed that flush requests had not to leave any trace in the scheduler, since the scheduler does not decide anything for them. Accordingly, I thought they did not trigger any put or completion hook. In contrast, these requests get the flag QUEUED set, in case the get_request hook is set, and then trigger both a put_request and a completed_request. In this respect, in bfq-mq I'm not using any of these three hooks (they are all NULL). I hope I'm not doing something unexpected or incoherent.
UPDATE: bfq-mq now survives for minutes. I'm debugging two occasional failures, which (un)fortunately become more and more occasional as I go on with debugging and instrumenting the code.
Thanks,
Paolo
Quoted 1 line
See how mq-deadline does that. This is important, or you will get =
hangs
Quoted 1 line
with flushes as well, since the IO scheduler private data and the =
flush
Quoted 4 lines
data is unionized in the request.
=20
--=20
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 9 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20Signed-off-by Jens Axboe <[email protected]>---
block/Kconfig.iosched | 6 + block/Makefile | 1 + block/mq-deadline.c | 649 =
++++++++++++++++++++++++++++++++++++++++++++++++++
block/Makefile obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
Quoted 25 lines
3 files changed, 656 insertions(+)create mode 100644
block/mq-deadline.c
=20block/Kconfig.iosched +0
-0@@ -32,6 +32,12 @@ config IOSCHED_CFQ=20
This is the default I/O scheduler.
=20block/Kconfig.iosched +6
-0+config MQ_IOSCHED_DEADLINE + tristate "MQ deadline I/O scheduler" + default y + ---help--- + MQ version of the deadline IO scheduler. +config
CFQ_GROUP_IOSCHEDbool "CFQ Group Scheduling support" depends on IOSCHED_CFQ && BLK_CGROUPblock/Makefile +0
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
blk-throttle.o
Quoted 13 lines
obj-$(CONFIG_IOSCHED_NOOP) +=3D noop-iosched.o
obj-$(CONFIG_IOSCHED_DEADLINE) +=3D deadline-iosched.o
obj-$(CONFIG_IOSCHED_CFQ) +=3D cfq-iosched.o
+obj-$(CONFIG_MQ_IOSCHED_DEADLINE) +=3D mq-deadline.o
=20
obj-$(CONFIG_BLOCK_COMPAT) +=3D compat_ioctl.o
obj-$(CONFIG_BLK_CMDLINE_PARSER) +=3D cmdline-parser.oblock/mq-deadline.c new file +0
-0
block/mq-deadline.c line 2
Quoted 2 lines
block/mq-deadline.c new file +2
-0@@ -0,0 +1,649 @@ +/* +* MQ Deadline i/o scheduler - adaptation of the legacy deadline =
scheduler,
Quoted 15 lines
block/mq-deadline.c new file +15
-0+* for the blk-mq scheduling framework +* +* Copyright (C) 2016 Jens Axboe <[email protected]> +*/ +#include <linux/kernel.h> +#include <linux/fs.h> +#include <linux/blkdev.h> +#include <linux/blk-mq.h> +#include <linux/elevator.h> +#include <linux/bio.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/init.h> +#include <linux/compiler.h> +#include <linux/rbtree.h>
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+#include <linux/sbitmap.h> + +#include "blk.h" +#include "blk-mq.h" +#include "blk-mq-tag.h" +#include "blk-mq-sched.h" + +static unsigned int queue_depth =3D 256; +module_param (queue_depth, uint,0644 ); +MODULE_PARM_DESC(queue_depth, "Use this value as the scheduler queue =
depth");
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+ +/* +* See Documentation/block/deadline-iosched.txt +*/ +static const int read_expire =3D HZ / 2; /* max time before a read =
is submitted. */
block/mq-deadline.c line 33
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int write_expire =3D 5 * HZ; /* ditto for writes, these =
limits are SOFT! */
block/mq-deadline.c line 34
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int writes_starved =3D 2; /* max times reads can =
starve a write */
block/mq-deadline.c line 35
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int fifo_batch =3D 16; /* # of sequential requests =
treated as one
block/mq-deadline.c line 36
Quoted 1 line
block/mq-deadline.c new file +1
-0+ by the above parameters. For =
throughput. */
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ +struct deadline_data { +/* +* run time data +*/ + +/* +* requests (deadline_rq s) are present on both sort_list and =
fifo_list
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+*/ +struct rb_root sort_list[2 ]; +struct list_head fifo_list[2 ]; + +/* +* next in sort order. read, write or both are NULL +*/ +struct request *next_rq[2 ]; +unsigned int batching;/* number of sequential requests =
made */
block/mq-deadline.c line 54
Quoted 1 line
block/mq-deadline.c new file +1
-0+unsigned int starved;/* times reads have starved =
writes */
Quoted 48 lines
block/mq-deadline.c new file +48
-0+ +/* +* settings that change how the i/o scheduler behaves +*/ +int fifo_expire[2 ]; +int fifo_batch; +int writes_starved; +int front_merges; + +spinlock_t lock; +struct list_head dispatch; +struct blk_mq_tags *tags; +atomic_t wait_index; +}; + +static inline struct rb_root * +deadline_rb_root (struct deadline_data *dd,struct request *rq) +{ +return &dd->sort_list[rq_data_dir (rq)]; +} + +/* +* get the request after `rq' in sector-sorted order +*/ +static inline struct request * +deadline_latter_request (struct request *rq) +{ + struct rb_node *node =3D rb_next(&rq->rb_node); + +if (node) +return rb_entry_rq (node); + +return NULL ; +} + +static void +deadline_add_rq_rb (struct deadline_data *dd,struct request *rq) +{ + struct rb_root *root =3D deadline_rb_root(dd, rq); + +elv_rb_add (root, rq); +} + +static inline void +deadline_del_rq_rb (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ if (dd->next_rq[data_dir] =3D=3D rq) + dd->next_rq[data_dir] =3D deadline_latter_request(rq); + +elv_rb_del (deadline_rb_root (dd, rq), rq); +} + +/* +* remove rq from rbtree and fifo. +*/ +static void deadline_remove_request(struct request_queue *q, struct =
request *rq)
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct deadline_data *dd =3D q->elevator->elevator_data; + +list_del_init (&rq->queuelist); + +/* +* We might not be on the rbtree, if we are doing an insert =
merge
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+*/ +if (!RB_EMPTY_NODE (&rq->rb_node)) +deadline_del_rq_rb (dd, rq); + +elv_rqhash_del (q, rq); + if (q->last_merge =3D=3D rq) + q->last_merge =3D NULL; +} + +static void dd_request_merged(struct request_queue *q, struct request =
*req,
Quoted 4 lines
block/mq-deadline.c new file +4
-0+ int type) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+/* +* if the merge was a front merge, we need to reposition request +*/ + if (type =3D=3D ELEVATOR_FRONT_MERGE) { +elv_rb_del (deadline_rb_root (dd, req), req); +deadline_add_rq_rb (dd, req); + } +} + +static void dd_merged_requests(struct request_queue *q, struct =
request *req,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct request *next) +{ +/* +* if next expires before rq, assign its expire time to rq +* and move into next position (next will be deleted) in fifo +*/ + if (!list_empty(&req->queuelist) && =
!list_empty(&next->queuelist)) {
Quoted 23 lines
block/mq-deadline.c new file +23
-0+if (time_before ((unsigned long )next->fifo_time, + (unsigned long )req->fifo_time)) { +list_move (&req->queuelist, &next->queuelist); + req->fifo_time =3D next->fifo_time; + } + } + +/* +* kill knowledge of next, this one is a goner +*/ +deadline_remove_request (q, next); +} + +/* +* move an entry to dispatch queue +*/ +static void +deadline_move_request (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); + + dd->next_rq[READ] =3D NULL; + dd->next_rq[WRITE] =3D NULL;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ dd->next_rq[data_dir] =3D deadline_latter_request(rq); + +/* +* take it off the sort and fifo list +*/ +deadline_remove_request (rq->q, rq); +} + +/* +* deadline_check_fifo returns 0 if there are no expired requests on =
the fifo,
block/mq-deadline.c
Quoted 3 lines
block/mq-deadline.c new file +3
-0+* 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir]) +*/ +static inline int deadline_check_fifo(struct deadline_data *dd, int =
ddir)
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct request *rq =3D rq_entry_fifo(dd->fifo_list[ddir].next); + +/* +* rq is expired! +*/ +if (time_after_eq (jiffies, (unsigned long )rq->fifo_time))
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+return 1 ; + +return 0 ; +} + +/* +* deadline_dispatch_requests selects the best request according to +* read/write expire, fifo_batch, etc +*/ +static struct request *__dd_dispatch_request(struct blk_mq_hw_ctx =
*hctx)
block/mq-deadline.c line 205
Quoted 2 lines
block/mq-deadline.c new file +2
-0+{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+struct request *rq; +bool reads, writes; +int data_dir; + +spin_lock (&dd->lock); + +if (!list_empty (&dd->dispatch)) { + rq =3D list_first_entry(&dd->dispatch, struct request, =
queuelist);
Quoted 11 lines
block/mq-deadline.c new file +11
-0+list_del_init (&rq->queuelist); + goto done; + } + + reads =3D !list_empty(&dd->fifo_list[READ]); + writes =3D !list_empty(&dd->fifo_list[WRITE]); + +/* +* batches are currently reads XOR writes +*/ +if (dd->next_rq[WRITE ])
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ rq =3D dd->next_rq[WRITE]; + else + rq =3D dd->next_rq[READ]; + +if (rq && dd->batching < dd->fifo_batch) +/* we have a next request are still entitled to batch */ + goto dispatch_request; + +/* +* at this point we are not running a batch. select the =
appropriate
Quoted 25 lines
block/mq-deadline.c new file +25
-0+* data direction (read / write) +*/ + +if (reads) { +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[READ ])); + + if (writes && (dd->starved++ >=3D dd->writes_starved)) + goto dispatch_writes; + + data_dir =3D READ; + + goto dispatch_find_request; + } + +/* +* there are either no reads or writes have been starved +*/ + +if (writes) { +dispatch_writes: +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[WRITE ])); + + dd->starved =3D 0; + + data_dir =3D WRITE;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ + goto dispatch_find_request; + } + +spin_unlock (&dd->lock); +return NULL ; + +dispatch_find_request: +/* +* we are not running a batch, find best request for selected =
data_dir
block/mq-deadline.c line 271
Quoted 2 lines
block/mq-deadline.c new file +2
-0+*/ + if (deadline_check_fifo(dd, data_dir) || !dd->next_rq[data_dir]) =
{
block/mq-deadline.c line 273
Quoted 2 lines
block/mq-deadline.c new file +2
-0+/* +* A deadline has expired, the last request was in the =
other
block/mq-deadline.c line 274
Quoted 1 line
block/mq-deadline.c new file +1
-0+* direction, or we have run out of higher-sectored =
requests.
block/mq-deadline.c line 275
Quoted 1 line
block/mq-deadline.c new file +1
-0+* Start again from the request with the earliest expiry =
time.
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+*/ + rq =3D rq_entry_fifo(dd->fifo_list[data_dir].next); + }else { +/* +* The last req was the same dir and we have a next =
request in
block/mq-deadline.c line 281
Quoted 1 line
block/mq-deadline.c new file +1
-0+* sort order. No expired requests so continue on from =
here.
Quoted 12 lines
block/mq-deadline.c new file +12
-0+*/ + rq =3D dd->next_rq[data_dir]; + } + + dd->batching =3D 0; + +dispatch_request: +/* +* rq is the selected appropriate request. +*/ + dd->batching++; +deadline_move_request (dd, rq);
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+done: + rq->rq_flags |=3D RQF_STARTED; +spin_unlock (&dd->lock); +return rq; +} + +static void dd_dispatch_requests (struct blk_mq_hw_ctx *hctx, +struct list_head *rq_list) +{ + blk_mq_sched_dispatch_shadow_requests(hctx, rq_list, =
__dd_dispatch_request);
Quoted 7 lines
block/mq-deadline.c new file +7
-0+} + +static void dd_exit_queue (struct elevator_queue *e) +{ + struct deadline_data *dd =3D e->elevator_data; + +BUG_ON (!list_empty (&dd->fifo_list[READ ]));
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+BUG_ON (!list_empty (&dd->fifo_list[WRITE ])); + +blk_mq_sched_free_requests (dd->tags); +kfree (dd); +} + +/* +* initialize elevator private data (deadline_data). +*/ +static int dd_init_queue(struct request_queue *q, struct =
elevator_type *e)
Quoted 30 lines
block/mq-deadline.c new file +30
-0+{ +struct deadline_data *dd; +struct elevator_queue *eq; + + eq =3D elevator_alloc(q, e); +if (!eq) +return -ENOMEM ; + + dd =3D kzalloc_node(sizeof(*dd), GFP_KERNEL, q->node); +if (!dd) { +kobject_put (&eq->kobj); +return -ENOMEM ; + } + eq->elevator_data =3D dd; + + dd->tags =3D blk_mq_sched_alloc_requests(queue_depth, q->node); +if (!dd->tags) { +kfree (dd); +kobject_put (&eq->kobj); +return -ENOMEM ; + } + +INIT_LIST_HEAD (&dd->fifo_list[READ ]); +INIT_LIST_HEAD (&dd->fifo_list[WRITE ]); + dd->sort_list[READ] =3D RB_ROOT; + dd->sort_list[WRITE] =3D RB_ROOT; + dd->fifo_expire[READ] =3D read_expire; + dd->fifo_expire[WRITE] =3D write_expire; + dd->writes_starved =3D writes_starved; + dd->front_merges =3D 1;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ dd->fifo_batch =3D fifo_batch; +spin_lock_init (&dd->lock); +INIT_LIST_HEAD (&dd->dispatch); +atomic_set (&dd->wait_index,0 ); + + q->elevator =3D eq; +return 0 ; +} + +static int dd_request_merge(struct request_queue *q, struct request =
**rq,
Quoted 22 lines
block/mq-deadline.c new file +22
-0+ struct bio *bio) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; + sector_t sector =3D bio_end_sector(bio); +struct request *__rq; + +if (!dd->front_merges) +return ELEVATOR_NO_MERGE ; + + __rq =3D elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector); +if (__rq) { + BUG_ON(sector !=3D blk_rq_pos(__rq)); + +if (elv_bio_merge_ok (__rq, bio)) { + *rq =3D __rq; +return ELEVATOR_FRONT_MERGE ; + } + } + +return ELEVATOR_NO_MERGE ; +} +
block/mq-deadline.c line 392
Quoted 10 lines
block/mq-deadline.c new file +10
-0+static bool dd_bio_merge (struct blk_mq_hw_ctx *hctx,struct bio *bio) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; +int ret; + +spin_lock (&dd->lock); + ret =3D blk_mq_sched_try_merge(q, bio); +spin_unlock (&dd->lock); +
Hi Jens,
first, good news, bfq is passing my first sanity checks. Still, I need a little more help for the following issue. There is a case that would be impossible to handle without modifying code outside bfq. But so far such a case never occurred, and I hope that it can never occur. I'll try to briefly list all relevant details on this concern of mine, so that you can quickly confirm my hope, or highlight where or what I am missing.
First, as done above for mq-deadline, invoking blk_mq_sched_try_merge with the scheduler lock held is of course necessary (for example, to protect q->last_merge). This may lead to put_rq_private invoked with the lock held, in case of successful merge.
As a consequence, put_rq_private may be invoked:
(1) in IRQ context, no scheduler lock held, because of a completion:
can be handled by deferring work and lock grabbing, because the completed request is not queued in the scheduler any more;
(2) in process context, scheduler lock held, because of the above successful merge: must be handled immediately, for consistency, because the request is still queued in the scheduler;
(3) in process context, no scheduler lock held, for some other reason:
some path apparently may lead to this case, although I've never seen it to happen. Immediate handling, and hence locking, may be needed, depending on whether the request is still queued in the scheduler.
So, my main question is: is case (3) actually impossible? Should it be possible, I guess we would have a problem, because of the different lock state with respect to (2).
Finally, I hope that it is certainly impossible to have a case (4): in IRQ context, no lock held, but with the request in the scheduler.
Thanks,
Paolo
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+return ret; +} + +/* +* add rq to rbtree and fifo +*/ +static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq,
block/mq-deadline.c
Quoted 13 lines
block/mq-deadline.c new file +13
-0+ bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + const int data_dir =3D rq_data_dir(rq); + +if (blk_mq_sched_try_insert_merge (q, rq)) +return ; + +blk_mq_sched_request_inserted (rq); + +/* +* If we're trying to insert a real request, just send it =
directly
block/mq-deadline.c line 413
Quoted 1 line
block/mq-deadline.c new file +1
-0+* to the hardware dispatch list. This only happens for a =
requeue,
Quoted 32 lines
block/mq-deadline.c new file +32
-0+* or FUA/FLUSH requests. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) { +spin_lock (&hctx->lock); +list_add_tail (&rq->queuelist, &hctx->dispatch); +spin_unlock (&hctx->lock); +return ; + } + + if (at_head || rq->cmd_type !=3D REQ_TYPE_FS) { +if (at_head) +list_add (&rq->queuelist, &dd->dispatch); +else +list_add_tail (&rq->queuelist, &dd->dispatch); + }else { +deadline_add_rq_rb (dd, rq); + +if (rq_mergeable (rq)) { +elv_rqhash_add (q, rq); +if (!q->last_merge) + q->last_merge =3D rq; + } + +/* +* set expire time and add to fifo list +*/ + rq->fifo_time =3D jiffies + dd->fifo_expire[data_dir]; +list_add_tail (&rq->queuelist, &dd->fifo_list[data_dir]); + } +} + +static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ struct list_head *list, bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + +spin_lock (&dd->lock); +while (!list_empty (list)) { +struct request *rq; + + rq =3D list_first_entry(list, struct request, =
queuelist);
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+list_del_init (&rq->queuelist); +dd_insert_request (hctx, rq, at_head); + } +spin_unlock (&dd->lock); +} + +static struct request *dd_get_request(struct request_queue *q, =
unsigned int op,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct blk_mq_alloc_data *data) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +struct request *rq; + +/* +* The flush machinery intercepts before we insert the request. =
As
block/mq-deadline.c
Quoted 6 lines
block/mq-deadline.c new file +6
-0+* a work-around, just hand it back a real request. +*/ +if (unlikely (op & (REQ_PREFLUSH |REQ_FUA ))) + rq =3D __blk_mq_alloc_request(data, op); +else { + rq =3D blk_mq_sched_alloc_shadow_request(q, data, =
dd->tags, &dd->wait_index);
block/mq-deadline.c
Quoted 13 lines
block/mq-deadline.c new file +13
-0+if (rq) +blk_mq_rq_ctx_init (q, data->ctx, rq, op); + } + +return rq; +} + +static bool dd_put_request (struct request *rq) +{ +/* +* If it's a real request, we just have to free it. For a shadow +* request, we should only free it if we haven't started it. A +* started request is mapped to a real one, and the real one =
will
Quoted 13 lines
block/mq-deadline.c new file +13
-0+* free it. We can get here with request merges, since we then +* free the request before we start/issue it. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) +return false; + +if (!(rq->rq_flags &RQF_STARTED )) { + struct request_queue *q =3D rq->q; + struct deadline_data *dd =3D q->elevator->elevator_data; + +/* +* IO completion would normally do this, but if we merge +* and free before we issue the request, drop both the
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+* tag and queue ref +*/ +blk_mq_sched_free_shadow_request (dd->tags, rq); +blk_queue_exit (q); + } + +return true; +} + +static void dd_completed_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq)
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+{ + struct request *sched_rq =3D rq->end_io_data; + +/* +* sched_rq can be NULL, if we haven't setup the shadow yet +* because we failed getting one. +*/ +if (sched_rq) { + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+ +blk_mq_sched_free_shadow_request (dd->tags, sched_rq); +blk_mq_start_stopped_hw_queue (hctx, true); + } +} + +static bool dd_has_work (struct blk_mq_hw_ctx *hctx) +{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
Quoted 15 lines
block/mq-deadline.c new file +15
-0+ +return !list_empty_careful (&dd->dispatch) || + !list_empty_careful (&dd->fifo_list[0 ]) || + !list_empty_careful (&dd->fifo_list[1 ]); +} + +/* +* sysfs parts below +*/ +static ssize_t +deadline_var_show (int var,char *page) +{ +return sprintf (page,"%d\n" , var); +} +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+static ssize_t +deadline_var_store (int *var,const char *page,size_t count) +{ + char *p =3D (char *) page; + + *var =3D simple_strtol(p, &p, 10); +return count; +} + +#define SHOW_FUNCTION (__FUNC, __VAR, __CONV) =
\
block/mq-deadline.c line 555
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, char *page) =
\
block/mq-deadline.c line 556
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
block/mq-deadline.c line 557
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
block/mq-deadline.c line 558
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data =3D __VAR; =
\
block/mq-deadline.c line 559
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
block/mq-deadline.c line 560
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D jiffies_to_msecs(__data); =
\
block/mq-deadline.c line 561
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return deadline_var_show(__data, (page)); =
\
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+} +SHOW_FUNCTION (deadline_read_expire_show, dd->fifo_expire[READ ],1 ); +SHOW_FUNCTION (deadline_write_expire_show, dd->fifo_expire[WRITE ],1 ); +SHOW_FUNCTION (deadline_writes_starved_show, dd->writes_starved,0 ); +SHOW_FUNCTION (deadline_front_merges_show, dd->front_merges,0 ); +SHOW_FUNCTION (deadline_fifo_batch_show, dd->fifo_batch,0 ); +#undef SHOW_FUNCTION + +#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) =
\
block/mq-deadline.c line 571
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, const char *page, =
size_t count) \
block/mq-deadline.c line 572
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
block/mq-deadline.c line 573
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
block/mq-deadline.c line 574
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data; =
\
block/mq-deadline.c line 575
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int ret =3D deadline_var_store(&__data, (page), count); =
\
block/mq-deadline.c line 576
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__data < (MIN)) =
\
block/mq-deadline.c line 577
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MIN); =
\
block/mq-deadline.c line 578
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else if (__data > (MAX)) =
\
block/mq-deadline.c line 579
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MAX); =
\
block/mq-deadline.c line 580
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
block/mq-deadline.c line 581
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D msecs_to_jiffies(__data); =
\
block/mq-deadline.c line 582
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else =
\
block/mq-deadline.c line 583
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D __data; =
\
block/mq-deadline.c line 584
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return ret; =
\
block/mq-deadline.c line 586
Quoted 2 lines
block/mq-deadline.c new file +2
-0+} +STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, =
INT_MAX, 1);
block/mq-deadline.c line 587
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], =
0, INT_MAX, 1);
block/mq-deadline.c line 588
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, =
INT_MIN, INT_MAX, 0);
block/mq-deadline.c line 589
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, =
0);
block/mq-deadline.c line 590
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, =
INT_MAX, 0);
Quoted 62 lines
block/mq-deadline.c new file +59
-1+#undef STORE_FUNCTION + +#define DD_ATTR (name) \ + __ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \ + deadline_##name##_store) + +static struct elv_fs_entry deadline_attrs[] =3D { +DD_ATTR (read_expire), +DD_ATTR (write_expire), +DD_ATTR (writes_starved), +DD_ATTR (front_merges), +DD_ATTR (fifo_batch), + __ATTR_NULL +}; + +static struct elevator_type mq_deadline =3D { + .ops.mq =3D { + .get_request =3D dd_get_request, + .put_request =3D dd_put_request, + .insert_requests =3D dd_insert_requests, + .dispatch_requests =3D dd_dispatch_requests, + .completed_request =3D dd_completed_request, + .next_request =3D elv_rb_latter_request, + .former_request =3D elv_rb_former_request, + .bio_merge =3D dd_bio_merge, + .request_merge =3D dd_request_merge, + .requests_merged =3D dd_merged_requests, + .request_merged =3D dd_request_merged, + .has_work =3D dd_has_work, + .init_sched =3D dd_init_queue, + .exit_sched =3D dd_exit_queue, + }, + + .uses_mq =3D true, + .elevator_attrs =3D deadline_attrs, + .elevator_name =3D "mq-deadline", + .elevator_owner =3D THIS_MODULE, +}; + +static int __init deadline_init (void ) +{ +if (!queue_depth) { +pr_err ("mq-deadline: queue depth must be > 0\n" ); +return -EINVAL ; + } +return elv_register (&mq_deadline); +} + +static void __exit deadline_exit(void) +{ +elv_unregister (&mq_deadline); +} + +module_init (deadline_init); +module_exit (deadline_exit); + +MODULE_AUTHOR ("Jens Axboe" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("MQ deadline IO scheduler" ); --=202.7.4
=20
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 9 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20Signed-off-by Jens Axboe <[email protected]>---
block/Kconfig.iosched | 6 + block/Makefile | 1 + block/mq-deadline.c | 649 =
++++++++++++++++++++++++++++++++++++++++++++++++++
block/Makefile obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
Quoted 25 lines
3 files changed, 656 insertions(+)create mode 100644
block/mq-deadline.c
=20block/Kconfig.iosched +0
-0@@ -32,6 +32,12 @@ config IOSCHED_CFQ=20
This is the default I/O scheduler.
=20block/Kconfig.iosched +6
-0+config MQ_IOSCHED_DEADLINE + tristate "MQ deadline I/O scheduler" + default y + ---help--- + MQ version of the deadline IO scheduler. +config
CFQ_GROUP_IOSCHEDbool "CFQ Group Scheduling support" depends on IOSCHED_CFQ && BLK_CGROUPblock/Makefile +0
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_BLK_DEV_THROTTLING) +=3D =
blk-throttle.o
Quoted 13 lines
obj-$(CONFIG_IOSCHED_NOOP) +=3D noop-iosched.o
obj-$(CONFIG_IOSCHED_DEADLINE) +=3D deadline-iosched.o
obj-$(CONFIG_IOSCHED_CFQ) +=3D cfq-iosched.o
+obj-$(CONFIG_MQ_IOSCHED_DEADLINE) +=3D mq-deadline.o
=20
obj-$(CONFIG_BLOCK_COMPAT) +=3D compat_ioctl.o
obj-$(CONFIG_BLK_CMDLINE_PARSER) +=3D cmdline-parser.oblock/mq-deadline.c new file +0
-0
block/mq-deadline.c line 2
Quoted 2 lines
block/mq-deadline.c new file +2
-0@@ -0,0 +1,649 @@ +/* +* MQ Deadline i/o scheduler - adaptation of the legacy deadline =
scheduler,
Quoted 15 lines
block/mq-deadline.c new file +15
-0+* for the blk-mq scheduling framework +* +* Copyright (C) 2016 Jens Axboe <[email protected]> +*/ +#include <linux/kernel.h> +#include <linux/fs.h> +#include <linux/blkdev.h> +#include <linux/blk-mq.h> +#include <linux/elevator.h> +#include <linux/bio.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/init.h> +#include <linux/compiler.h> +#include <linux/rbtree.h>
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+#include <linux/sbitmap.h> + +#include "blk.h" +#include "blk-mq.h" +#include "blk-mq-tag.h" +#include "blk-mq-sched.h" + +static unsigned int queue_depth =3D 256; +module_param (queue_depth, uint,0644 ); +MODULE_PARM_DESC(queue_depth, "Use this value as the scheduler queue =
depth");
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+ +/* +* See Documentation/block/deadline-iosched.txt +*/ +static const int read_expire =3D HZ / 2; /* max time before a read =
is submitted. */
block/mq-deadline.c line 33
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int write_expire =3D 5 * HZ; /* ditto for writes, these =
limits are SOFT! */
block/mq-deadline.c line 34
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int writes_starved =3D 2; /* max times reads can =
starve a write */
block/mq-deadline.c line 35
Quoted 1 line
block/mq-deadline.c new file +1
-0+static const int fifo_batch =3D 16; /* # of sequential requests =
treated as one
block/mq-deadline.c line 36
Quoted 1 line
block/mq-deadline.c new file +1
-0+ by the above parameters. For =
throughput. */
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+ +struct deadline_data { +/* +* run time data +*/ + +/* +* requests (deadline_rq s) are present on both sort_list and =
fifo_list
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+*/ +struct rb_root sort_list[2 ]; +struct list_head fifo_list[2 ]; + +/* +* next in sort order. read, write or both are NULL +*/ +struct request *next_rq[2 ]; +unsigned int batching;/* number of sequential requests =
made */
block/mq-deadline.c line 54
Quoted 1 line
block/mq-deadline.c new file +1
-0+unsigned int starved;/* times reads have starved =
writes */
Quoted 48 lines
block/mq-deadline.c new file +48
-0+ +/* +* settings that change how the i/o scheduler behaves +*/ +int fifo_expire[2 ]; +int fifo_batch; +int writes_starved; +int front_merges; + +spinlock_t lock; +struct list_head dispatch; +struct blk_mq_tags *tags; +atomic_t wait_index; +}; + +static inline struct rb_root * +deadline_rb_root (struct deadline_data *dd,struct request *rq) +{ +return &dd->sort_list[rq_data_dir (rq)]; +} + +/* +* get the request after `rq' in sector-sorted order +*/ +static inline struct request * +deadline_latter_request (struct request *rq) +{ + struct rb_node *node =3D rb_next(&rq->rb_node); + +if (node) +return rb_entry_rq (node); + +return NULL ; +} + +static void +deadline_add_rq_rb (struct deadline_data *dd,struct request *rq) +{ + struct rb_root *root =3D deadline_rb_root(dd, rq); + +elv_rb_add (root, rq); +} + +static inline void +deadline_del_rq_rb (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ if (dd->next_rq[data_dir] =3D=3D rq) + dd->next_rq[data_dir] =3D deadline_latter_request(rq); + +elv_rb_del (deadline_rb_root (dd, rq), rq); +} + +/* +* remove rq from rbtree and fifo. +*/ +static void deadline_remove_request(struct request_queue *q, struct =
request *rq)
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct deadline_data *dd =3D q->elevator->elevator_data; + +list_del_init (&rq->queuelist); + +/* +* We might not be on the rbtree, if we are doing an insert =
merge
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+*/ +if (!RB_EMPTY_NODE (&rq->rb_node)) +deadline_del_rq_rb (dd, rq); + +elv_rqhash_del (q, rq); + if (q->last_merge =3D=3D rq) + q->last_merge =3D NULL; +} + +static void dd_request_merged(struct request_queue *q, struct request =
*req,
Quoted 4 lines
block/mq-deadline.c new file +4
-0+ int type) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+/* +* if the merge was a front merge, we need to reposition request +*/ + if (type =3D=3D ELEVATOR_FRONT_MERGE) { +elv_rb_del (deadline_rb_root (dd, req), req); +deadline_add_rq_rb (dd, req); + } +} + +static void dd_merged_requests(struct request_queue *q, struct =
request *req,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct request *next) +{ +/* +* if next expires before rq, assign its expire time to rq +* and move into next position (next will be deleted) in fifo +*/ + if (!list_empty(&req->queuelist) && =
!list_empty(&next->queuelist)) {
Quoted 23 lines
block/mq-deadline.c new file +23
-0+if (time_before ((unsigned long )next->fifo_time, + (unsigned long )req->fifo_time)) { +list_move (&req->queuelist, &next->queuelist); + req->fifo_time =3D next->fifo_time; + } + } + +/* +* kill knowledge of next, this one is a goner +*/ +deadline_remove_request (q, next); +} + +/* +* move an entry to dispatch queue +*/ +static void +deadline_move_request (struct deadline_data *dd,struct request *rq) +{ + const int data_dir =3D rq_data_dir(rq); + + dd->next_rq[READ] =3D NULL; + dd->next_rq[WRITE] =3D NULL;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ dd->next_rq[data_dir] =3D deadline_latter_request(rq); + +/* +* take it off the sort and fifo list +*/ +deadline_remove_request (rq->q, rq); +} + +/* +* deadline_check_fifo returns 0 if there are no expired requests on =
the fifo,
block/mq-deadline.c
Quoted 3 lines
block/mq-deadline.c new file +3
-0+* 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir]) +*/ +static inline int deadline_check_fifo(struct deadline_data *dd, int =
ddir)
Quoted 7 lines
block/mq-deadline.c new file +7
-0+{ + struct request *rq =3D rq_entry_fifo(dd->fifo_list[ddir].next); + +/* +* rq is expired! +*/ +if (time_after_eq (jiffies, (unsigned long )rq->fifo_time))
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+return 1 ; + +return 0 ; +} + +/* +* deadline_dispatch_requests selects the best request according to +* read/write expire, fifo_batch, etc +*/ +static struct request *__dd_dispatch_request(struct blk_mq_hw_ctx =
*hctx)
block/mq-deadline.c line 205
Quoted 2 lines
block/mq-deadline.c new file +2
-0+{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c
Quoted 8 lines
block/mq-deadline.c new file +8
-0+struct request *rq; +bool reads, writes; +int data_dir; + +spin_lock (&dd->lock); + +if (!list_empty (&dd->dispatch)) { + rq =3D list_first_entry(&dd->dispatch, struct request, =
queuelist);
Quoted 11 lines
block/mq-deadline.c new file +11
-0+list_del_init (&rq->queuelist); + goto done; + } + + reads =3D !list_empty(&dd->fifo_list[READ]); + writes =3D !list_empty(&dd->fifo_list[WRITE]); + +/* +* batches are currently reads XOR writes +*/ +if (dd->next_rq[WRITE ])
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ rq =3D dd->next_rq[WRITE]; + else + rq =3D dd->next_rq[READ]; + +if (rq && dd->batching < dd->fifo_batch) +/* we have a next request are still entitled to batch */ + goto dispatch_request; + +/* +* at this point we are not running a batch. select the =
appropriate
Quoted 25 lines
block/mq-deadline.c new file +25
-0+* data direction (read / write) +*/ + +if (reads) { +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[READ ])); + + if (writes && (dd->starved++ >=3D dd->writes_starved)) + goto dispatch_writes; + + data_dir =3D READ; + + goto dispatch_find_request; + } + +/* +* there are either no reads or writes have been starved +*/ + +if (writes) { +dispatch_writes: +BUG_ON (RB_EMPTY_ROOT (&dd->sort_list[WRITE ])); + + dd->starved =3D 0; + + data_dir =3D WRITE;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ + goto dispatch_find_request; + } + +spin_unlock (&dd->lock); +return NULL ; + +dispatch_find_request: +/* +* we are not running a batch, find best request for selected =
data_dir
block/mq-deadline.c line 271
Quoted 2 lines
block/mq-deadline.c new file +2
-0+*/ + if (deadline_check_fifo(dd, data_dir) || !dd->next_rq[data_dir]) =
{
block/mq-deadline.c line 273
Quoted 2 lines
block/mq-deadline.c new file +2
-0+/* +* A deadline has expired, the last request was in the =
other
block/mq-deadline.c line 274
Quoted 1 line
block/mq-deadline.c new file +1
-0+* direction, or we have run out of higher-sectored =
requests.
block/mq-deadline.c line 275
Quoted 1 line
block/mq-deadline.c new file +1
-0+* Start again from the request with the earliest expiry =
time.
block/mq-deadline.c
Quoted 5 lines
block/mq-deadline.c new file +5
-0+*/ + rq =3D rq_entry_fifo(dd->fifo_list[data_dir].next); + }else { +/* +* The last req was the same dir and we have a next =
request in
block/mq-deadline.c line 281
Quoted 1 line
block/mq-deadline.c new file +1
-0+* sort order. No expired requests so continue on from =
here.
Quoted 12 lines
block/mq-deadline.c new file +12
-0+*/ + rq =3D dd->next_rq[data_dir]; + } + + dd->batching =3D 0; + +dispatch_request: +/* +* rq is the selected appropriate request. +*/ + dd->batching++; +deadline_move_request (dd, rq);
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+done: + rq->rq_flags |=3D RQF_STARTED; +spin_unlock (&dd->lock); +return rq; +} + +static void dd_dispatch_requests (struct blk_mq_hw_ctx *hctx, +struct list_head *rq_list) +{ + blk_mq_sched_dispatch_shadow_requests(hctx, rq_list, =
__dd_dispatch_request);
Quoted 7 lines
block/mq-deadline.c new file +7
-0+} + +static void dd_exit_queue (struct elevator_queue *e) +{ + struct deadline_data *dd =3D e->elevator_data; + +BUG_ON (!list_empty (&dd->fifo_list[READ ]));
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+BUG_ON (!list_empty (&dd->fifo_list[WRITE ])); + +blk_mq_sched_free_requests (dd->tags); +kfree (dd); +} + +/* +* initialize elevator private data (deadline_data). +*/ +static int dd_init_queue(struct request_queue *q, struct =
elevator_type *e)
Quoted 30 lines
block/mq-deadline.c new file +30
-0+{ +struct deadline_data *dd; +struct elevator_queue *eq; + + eq =3D elevator_alloc(q, e); +if (!eq) +return -ENOMEM ; + + dd =3D kzalloc_node(sizeof(*dd), GFP_KERNEL, q->node); +if (!dd) { +kobject_put (&eq->kobj); +return -ENOMEM ; + } + eq->elevator_data =3D dd; + + dd->tags =3D blk_mq_sched_alloc_requests(queue_depth, q->node); +if (!dd->tags) { +kfree (dd); +kobject_put (&eq->kobj); +return -ENOMEM ; + } + +INIT_LIST_HEAD (&dd->fifo_list[READ ]); +INIT_LIST_HEAD (&dd->fifo_list[WRITE ]); + dd->sort_list[READ] =3D RB_ROOT; + dd->sort_list[WRITE] =3D RB_ROOT; + dd->fifo_expire[READ] =3D read_expire; + dd->fifo_expire[WRITE] =3D write_expire; + dd->writes_starved =3D writes_starved; + dd->front_merges =3D 1;
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ dd->fifo_batch =3D fifo_batch; +spin_lock_init (&dd->lock); +INIT_LIST_HEAD (&dd->dispatch); +atomic_set (&dd->wait_index,0 ); + + q->elevator =3D eq; +return 0 ; +} + +static int dd_request_merge(struct request_queue *q, struct request =
**rq,
Quoted 29 lines
block/mq-deadline.c new file +29
-0+ struct bio *bio) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; + sector_t sector =3D bio_end_sector(bio); +struct request *__rq; + +if (!dd->front_merges) +return ELEVATOR_NO_MERGE ; + + __rq =3D elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector); +if (__rq) { + BUG_ON(sector !=3D blk_rq_pos(__rq)); + +if (elv_bio_merge_ok (__rq, bio)) { + *rq =3D __rq; +return ELEVATOR_FRONT_MERGE ; + } + } + +return ELEVATOR_NO_MERGE ; +} + +static bool dd_bio_merge (struct blk_mq_hw_ctx *hctx,struct bio *bio) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; +int ret; + +spin_lock (&dd->lock);
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ ret =3D blk_mq_sched_try_merge(q, bio); +spin_unlock (&dd->lock); + +return ret; +} + +/* +* add rq to rbtree and fifo +*/ +static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq,
block/mq-deadline.c line 408
Quoted 9 lines
block/mq-deadline.c new file +9
-0+ bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + const int data_dir =3D rq_data_dir(rq); + +if (blk_mq_sched_try_insert_merge (q, rq)) +return ; +
A related doubt: shouldn't blk_mq_sched_try_insert_merge be invoked with = the scheduler lock held too, as blk_mq_sched_try_merge, to protect (at = least) q->last_merge?
In bfq this function is invoked with the lock held.
Thanks,
Paolo
block/mq-deadline.c
Quoted 4 lines
block/mq-deadline.c new file +4
-0+blk_mq_sched_request_inserted (rq); + +/* +* If we're trying to insert a real request, just send it =
directly
block/mq-deadline.c line 413
Quoted 1 line
block/mq-deadline.c new file +1
-0+* to the hardware dispatch list. This only happens for a =
requeue,
Quoted 32 lines
block/mq-deadline.c new file +32
-0+* or FUA/FLUSH requests. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) { +spin_lock (&hctx->lock); +list_add_tail (&rq->queuelist, &hctx->dispatch); +spin_unlock (&hctx->lock); +return ; + } + + if (at_head || rq->cmd_type !=3D REQ_TYPE_FS) { +if (at_head) +list_add (&rq->queuelist, &dd->dispatch); +else +list_add_tail (&rq->queuelist, &dd->dispatch); + }else { +deadline_add_rq_rb (dd, rq); + +if (rq_mergeable (rq)) { +elv_rqhash_add (q, rq); +if (!q->last_merge) + q->last_merge =3D rq; + } + +/* +* set expire time and add to fifo list +*/ + rq->fifo_time =3D jiffies + dd->fifo_expire[data_dir]; +list_add_tail (&rq->queuelist, &dd->fifo_list[data_dir]); + } +} + +static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+ struct list_head *list, bool at_head) +{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + +spin_lock (&dd->lock); +while (!list_empty (list)) { +struct request *rq; + + rq =3D list_first_entry(list, struct request, =
queuelist);
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+list_del_init (&rq->queuelist); +dd_insert_request (hctx, rq, at_head); + } +spin_unlock (&dd->lock); +} + +static struct request *dd_get_request(struct request_queue *q, =
unsigned int op,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct blk_mq_alloc_data *data) +{ + struct deadline_data *dd =3D q->elevator->elevator_data; +struct request *rq; + +/* +* The flush machinery intercepts before we insert the request. =
As
block/mq-deadline.c
Quoted 6 lines
block/mq-deadline.c new file +6
-0+* a work-around, just hand it back a real request. +*/ +if (unlikely (op & (REQ_PREFLUSH |REQ_FUA ))) + rq =3D __blk_mq_alloc_request(data, op); +else { + rq =3D blk_mq_sched_alloc_shadow_request(q, data, =
dd->tags, &dd->wait_index);
block/mq-deadline.c
Quoted 13 lines
block/mq-deadline.c new file +13
-0+if (rq) +blk_mq_rq_ctx_init (q, data->ctx, rq, op); + } + +return rq; +} + +static bool dd_put_request (struct request *rq) +{ +/* +* If it's a real request, we just have to free it. For a shadow +* request, we should only free it if we haven't started it. A +* started request is mapped to a real one, and the real one =
will
Quoted 13 lines
block/mq-deadline.c new file +13
-0+* free it. We can get here with request merges, since we then +* free the request before we start/issue it. +*/ +if (!blk_mq_sched_rq_is_shadow (rq)) +return false; + +if (!(rq->rq_flags &RQF_STARTED )) { + struct request_queue *q =3D rq->q; + struct deadline_data *dd =3D q->elevator->elevator_data; + +/* +* IO completion would normally do this, but if we merge +* and free before we issue the request, drop both the
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+* tag and queue ref +*/ +blk_mq_sched_free_shadow_request (dd->tags, rq); +blk_queue_exit (q); + } + +return true; +} + +static void dd_completed_request(struct blk_mq_hw_ctx *hctx, struct =
request *rq)
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+{ + struct request *sched_rq =3D rq->end_io_data; + +/* +* sched_rq can be NULL, if we haven't setup the shadow yet +* because we failed getting one. +*/ +if (sched_rq) { + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+ +blk_mq_sched_free_shadow_request (dd->tags, sched_rq); +blk_mq_start_stopped_hw_queue (hctx, true); + } +} + +static bool dd_has_work (struct blk_mq_hw_ctx *hctx) +{ + struct deadline_data *dd =3D =
hctx->queue->elevator->elevator_data;
Quoted 15 lines
block/mq-deadline.c new file +15
-0+ +return !list_empty_careful (&dd->dispatch) || + !list_empty_careful (&dd->fifo_list[0 ]) || + !list_empty_careful (&dd->fifo_list[1 ]); +} + +/* +* sysfs parts below +*/ +static ssize_t +deadline_var_show (int var,char *page) +{ +return sprintf (page,"%d\n" , var); +} +
block/mq-deadline.c
Quoted 10 lines
block/mq-deadline.c new file +10
-0+static ssize_t +deadline_var_store (int *var,const char *page,size_t count) +{ + char *p =3D (char *) page; + + *var =3D simple_strtol(p, &p, 10); +return count; +} + +#define SHOW_FUNCTION (__FUNC, __VAR, __CONV) =
\
block/mq-deadline.c line 555
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, char *page) =
\
block/mq-deadline.c line 556
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
block/mq-deadline.c line 557
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
block/mq-deadline.c line 558
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data =3D __VAR; =
\
block/mq-deadline.c line 559
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
block/mq-deadline.c line 560
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D jiffies_to_msecs(__data); =
\
block/mq-deadline.c line 561
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return deadline_var_show(__data, (page)); =
\
block/mq-deadline.c
Quoted 9 lines
block/mq-deadline.c new file +9
-0+} +SHOW_FUNCTION (deadline_read_expire_show, dd->fifo_expire[READ ],1 ); +SHOW_FUNCTION (deadline_write_expire_show, dd->fifo_expire[WRITE ],1 ); +SHOW_FUNCTION (deadline_writes_starved_show, dd->writes_starved,0 ); +SHOW_FUNCTION (deadline_front_merges_show, dd->front_merges,0 ); +SHOW_FUNCTION (deadline_fifo_batch_show, dd->fifo_batch,0 ); +#undef SHOW_FUNCTION + +#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) =
\
block/mq-deadline.c line 571
Quoted 1 line
block/mq-deadline.c new file +1
-0+static ssize_t __FUNC(struct elevator_queue *e, const char *page, =
size_t count) \
block/mq-deadline.c line 572
Quoted 1 line
block/mq-deadline.c new file +1
-0+{ =
\
block/mq-deadline.c line 573
Quoted 1 line
block/mq-deadline.c new file +1
-0+ struct deadline_data *dd =3D e->elevator_data; =
\
block/mq-deadline.c line 574
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int __data; =
\
block/mq-deadline.c line 575
Quoted 1 line
block/mq-deadline.c new file +1
-0+ int ret =3D deadline_var_store(&__data, (page), count); =
\
block/mq-deadline.c line 576
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__data < (MIN)) =
\
block/mq-deadline.c line 577
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MIN); =
\
block/mq-deadline.c line 578
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else if (__data > (MAX)) =
\
block/mq-deadline.c line 579
Quoted 1 line
block/mq-deadline.c new file +1
-0+ __data =3D (MAX); =
\
block/mq-deadline.c line 580
Quoted 1 line
block/mq-deadline.c new file +1
-0+ if (__CONV) =
\
block/mq-deadline.c line 581
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D msecs_to_jiffies(__data); =
\
block/mq-deadline.c line 582
Quoted 1 line
block/mq-deadline.c new file +1
-0+ else =
\
block/mq-deadline.c line 583
Quoted 1 line
block/mq-deadline.c new file +1
-0+ *(__PTR) =3D __data; =
\
block/mq-deadline.c line 584
Quoted 1 line
block/mq-deadline.c new file +1
-0+ return ret; =
\
block/mq-deadline.c line 586
Quoted 2 lines
block/mq-deadline.c new file +2
-0+} +STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, =
INT_MAX, 1);
block/mq-deadline.c line 587
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], =
0, INT_MAX, 1);
block/mq-deadline.c line 588
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, =
INT_MIN, INT_MAX, 0);
block/mq-deadline.c line 589
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, =
0);
block/mq-deadline.c line 590
Quoted 1 line
block/mq-deadline.c new file +1
-0+STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, =
INT_MAX, 0);
Quoted 60 lines
block/mq-deadline.c new file +59
-1+#undef STORE_FUNCTION + +#define DD_ATTR (name) \ + __ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \ + deadline_##name##_store) + +static struct elv_fs_entry deadline_attrs[] =3D { +DD_ATTR (read_expire), +DD_ATTR (write_expire), +DD_ATTR (writes_starved), +DD_ATTR (front_merges), +DD_ATTR (fifo_batch), + __ATTR_NULL +}; + +static struct elevator_type mq_deadline =3D { + .ops.mq =3D { + .get_request =3D dd_get_request, + .put_request =3D dd_put_request, + .insert_requests =3D dd_insert_requests, + .dispatch_requests =3D dd_dispatch_requests, + .completed_request =3D dd_completed_request, + .next_request =3D elv_rb_latter_request, + .former_request =3D elv_rb_former_request, + .bio_merge =3D dd_bio_merge, + .request_merge =3D dd_request_merge, + .requests_merged =3D dd_merged_requests, + .request_merged =3D dd_request_merged, + .has_work =3D dd_has_work, + .init_sched =3D dd_init_queue, + .exit_sched =3D dd_exit_queue, + }, + + .uses_mq =3D true, + .elevator_attrs =3D deadline_attrs, + .elevator_name =3D "mq-deadline", + .elevator_owner =3D THIS_MODULE, +}; + +static int __init deadline_init (void ) +{ +if (!queue_depth) { +pr_err ("mq-deadline: queue depth must be > 0\n" ); +return -EINVAL ; + } +return elv_register (&mq_deadline); +} + +static void __exit deadline_exit(void) +{ +elv_unregister (&mq_deadline); +} + +module_init (deadline_init); +module_exit (deadline_exit); + +MODULE_AUTHOR ("Jens Axboe" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("MQ deadline IO scheduler" ); --=20
Quoted 4 lines
2.7.4
=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
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Paolo ValenteQuoted 11 lines · Paolo Valente
Review
Quoted 10 lines
(quoted diff) +10
-0+static bool dd_bio_merge(struct blk_mq_hw_ctx *hctx, struct bio *bio) +{ + struct request_queue *q = hctx->queue; + struct deadline_data *dd = q->elevator->elevator_data; + int ret; + + spin_lock(&dd->lock); + ret = blk_mq_sched_try_merge(q, bio); + spin_unlock(&dd->lock); +
Quoted 8 lines
Hi Jens,
first, good news, bfq is passing my first sanity checks. Still, I need a little more help for the following issue. There is a case that would be impossible to handle without modifying code outside bfq. But so far such a case never occurred, and I hope that it can never occur. I'll try to briefly list all relevant details on this concern of mine, so that you can quickly confirm my hope, or highlight where or what I am missing.
Remember my earlier advice - it's not a problem to change anything in the core, in fact I would be surprised if you did not need to. My foresight isn't THAT good! It's much better to fix up an inconsistency there, rather than work around it in the consumer of that API.
Quoted 4 lines
First, as done above for mq-deadline, invoking
blk_mq_sched_try_mergewith the scheduler lock held is of course necessary (for example, to protectq->last_merge). This may lead toput_rq_privateinvoked with the lock held, in case of successful merge.
Right, or some other lock with the same scope, as per my other email.
Quoted 12 lines
As a consequence,
put_rq_privatemay be invoked:
(1) in IRQ context, no scheduler lock held, because of a completion:
can be handled by deferring work and lock grabbing, because the completed request is not queued in the scheduler any more;
(2) in process context, scheduler lock held, because of the above successful merge: must be handled immediately, for consistency, because the request is still queued in the scheduler;
(3) in process context, no scheduler lock held, for some other reason:
some path apparently may lead to this case, although I've never seen it to happen. Immediate handling, and hence locking, may be needed, depending on whether the request is still queued in the scheduler.
Quoted 3 lines
So, my main question is: is case (3) actually impossible? Should it be possible, I guess we would have a problem, because of the different lock state with respect to (2).
I agree, there's some inconsistency there, if you potentially need to grab the lock in your put_rq_private handler. The problem case is #2, when we have the merge. I would probably suggest that the best way to handle that is to pass back the dropped request so we can put it outside of holding the lock.
Let me see if I can come up with a good solution for this. We have to be consistent in how we invoke the scheduler functions, we can't have hooks that are called in unknown lock states. I also don't want you to have to add defer work handling in that kind of path, that will impact your performance and overhead.
Quoted 2 lines
Finally, I hope that it is certainly impossible to have a case (4): in IRQ context, no lock held, but with the request in the scheduler.
That should not be possible.
Edit: since I'm on a flight and email won't send, I had a few minutes to hack this up. Totally untested, but something like the below should do it. Not super pretty... I'll play with this a bit more tomorrow.
block/blk-core.c +9 -3
@@ -1609,7 +1609,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio) {struct blk_plug *plug;int el_ret, where =ELEVATOR_INSERT_SORT ; -struct request *req; +struct request *req, *free;unsigned int request_count =0 ;unsigned int wb_acct;
@@ -1650,15 +1650,21 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)if (el_ret ==ELEVATOR_BACK_MERGE ) {if (bio_attempt_back_merge (q, req, bio)) {elv_bio_merged (q, req, bio); -if (!attempt_back_merge (q, req)) + free =attempt_back_merge (q, req); +if (!free)elv_merged_request (q, req, el_ret); +else +__blk_put_request (q, free); goto out_unlock; } }else if (el_ret ==ELEVATOR_FRONT_MERGE ) {if (bio_attempt_front_merge (q, req, bio)) {elv_bio_merged (q, req, bio); -if (!attempt_front_merge (q, req)) + free =attempt_front_merge (q, req); +if (!free)elv_merged_request (q, req, el_ret); +else +__blk_put_request (q, free); goto out_unlock; } }
block/blk-merge.c +23 -16
@@ -661,29 +661,29 @@ static void blk_account_io_merge(struct request *req)/* * Has to be called with the request spinlock acquired */ -static int attempt_merge (struct request_queue *q,struct request *req, -struct request *next) +static struct request *attempt_merge (struct request_queue *q, +struct request *req,struct request *next) {if (!rq_mergeable (req) || !rq_mergeable (next)) -return 0 ; +return NULL ;if (req_op (req) !=req_op (next)) -return 0 ; +return NULL ;/* * not contiguous */ if (blk_rq_pos (req) +blk_rq_sectors (req) !=blk_rq_pos (next)) -return 0 ; +return NULL ;if (rq_data_dir (req) !=rq_data_dir (next) || req->rq_disk != next->rq_disk ||req_no_special_merge (next)) -return 0 ; +return NULL ;if (req_op (req) ==REQ_OP_WRITE_SAME && !blk_write_same_mergeable (req->bio, next->bio)) -return 0 ; +return NULL ;/* * If we are allowed to merge, then append bio list
@@ -692,7 +692,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,* counts here. */ if (!ll_merge_requests_fn (q, req, next)) -return 0 ; +return NULL ;/* * If failfast settings disagree or any of the two is already
@@ -732,30 +732,32 @@ static int attempt_merge(struct request_queue *q, struct request *req,if (blk_rq_cpu_valid (next)) req->cpu = next->cpu; -/* owner-ship of bio passed from next to req */ +/* +* owner-ship of bio passed from next to req, return 'next' for +* the caller to free +*/ next->bio =NULL ; -__blk_put_request (q, next); -return 1 ; +return next; } -int attempt_back_merge (struct request_queue *q,struct request *rq) +struct request *attempt_back_merge (struct request_queue *q,struct request *rq) {struct request *next =elv_latter_request (q, rq);if (next)return attempt_merge (q, rq, next); -return 0 ; +return NULL ; } -int attempt_front_merge (struct request_queue *q,struct request *rq) +struct request *attempt_front_merge (struct request_queue *q,struct request *rq) {struct request *prev =elv_former_request (q, rq);if (prev)return attempt_merge (q, prev, rq); -return 0 ; +return NULL ; } int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
@@ -767,7 +769,12 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq,if (!e->type->ops.sq.elevator_allow_rq_merge_fn (q, rq, next))return 0 ; -return attempt_merge (q, rq, next); +if (attempt_merge (q, rq, next)) { +__blk_put_request (q, next); +return 1 ; + } + +return 0 ; }bool blk_rq_merge_ok (struct request *rq,struct bio *bio)
block/blk-mq-sched.c +6 -3
@@ -234,7 +234,8 @@ void blk_mq_sched_move_to_dispatch(struct blk_mq_hw_ctx *hctx, }EXPORT_SYMBOL_GPL (blk_mq_sched_move_to_dispatch); -bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio) +bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio, +struct request **merged_request) {struct request *rq;int ret;
@@ -244,7 +245,8 @@ bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio)if (!blk_mq_sched_allow_merge (q, rq, bio))return false;if (bio_attempt_back_merge (q, rq, bio)) { -if (!attempt_back_merge (q, rq)) + *merged_request =attempt_back_merge (q, rq); +if (!*merged_request)elv_merged_request (q, rq, ret);return true; }
@@ -252,7 +254,8 @@ bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio)if (!blk_mq_sched_allow_merge (q, rq, bio))return false;if (bio_attempt_front_merge (q, rq, bio)) { -if (!attempt_front_merge (q, rq)) + *merged_request =attempt_front_merge (q, rq); +if (!*merged_request)elv_merged_request (q, rq, ret);return true; }
block/blk-mq-sched.h +2 -1
@@ -16,7 +16,8 @@ void blk_mq_sched_put_request(struct request *rq);void blk_mq_sched_request_inserted (struct request *rq);bool blk_mq_sched_bypass_insert (struct blk_mq_hw_ctx *hctx,struct request *rq); -bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio); +bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio, +struct request **merged_request);bool __blk_mq_sched_bio_merge (struct request_queue *q,struct bio *bio);bool blk_mq_sched_try_insert_merge (struct request_queue *q,struct request *rq);void blk_mq_sched_restart_queues (struct blk_mq_hw_ctx *hctx);
block/blk.h +2 -2
@@ -204,8 +204,8 @@ int ll_back_merge_fn(struct request_queue *q, struct request *req, struct bio *bio);int ll_front_merge_fn (struct request_queue *q,struct request *req,struct bio *bio); -int attempt_back_merge (struct request_queue *q,struct request *rq); -int attempt_front_merge (struct request_queue *q,struct request *rq); +struct request *attempt_back_merge (struct request_queue *q,struct request *rq); +struct request *attempt_front_merge (struct request_queue *q,struct request *rq);int blk_attempt_req_merge (struct request_queue *q,struct request *rq,struct request *next);void blk_recalc_rq_segments (struct request *rq);
block/mq-deadline.c +6 -2
@@ -371,12 +371,16 @@ static bool dd_bio_merge(struct blk_mq_hw_ctx *hctx, struct bio *bio) {struct request_queue *q = hctx->queue;struct deadline_data *dd = q->elevator->elevator_data; -int ret; +struct request *free =NULL ; +bool ret;spin_lock (&dd->lock); - ret =blk_mq_sched_try_merge (q, bio); + ret =blk_mq_sched_try_merge (q, bio, &free);spin_unlock (&dd->lock); +if (free) +blk_mq_free_request (free); +return ret; }
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Paolo ValenteQuoted 18 lines · Paolo Valente
block/mq-deadline.c line 408
Quoted 13 lines
block/mq-deadline.c new file +13
-0+/* +* add rq to rbtree and fifo +*/ +static void dd_insert_request (struct blk_mq_hw_ctx *hctx,struct request *rq, +bool at_head) +{ +struct request_queue *q = hctx->queue; +struct deadline_data *dd = q->elevator->elevator_data; +const int data_dir =rq_data_dir (rq); + +if (blk_mq_sched_try_insert_merge (q, rq)) +return ; +A related doubt: shouldn't
blk_mq_sched_try_insert_mergebe invoked with the scheduler lock held too, asblk_mq_sched_try_merge, to protect (at least)q->last_merge?
Quoted 1 line
In bfq this function is invoked with the lock held.
It doesn't matter which lock you use, as long as:
1) You use the same one consistently
2) It has the same scope as the queue lock (the one you call the scheduler lock)
mq-deadline sets up a per-queue structure, deadline_data, and it has a lock embedded in that structure. This is what mq-deadline uses to serialize access to its data structures, as well as those in the queue (like last_merge).
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 02 feb 2017, alle ore 06:19, Jens Axboe <[email protected]> ha =
scritto:
Quoted 3 lines
=20
Quoted 1 line · Paolo Valente
Quoted 1 line
+static bool dd_bio_merge(struct
blk_mq_hw_ctx*hctx, struct bio =
*bio)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+{ + struct request_queue *q =3D hctx->queue; + struct deadline_data *dd =3D q->elevator->elevator_data; + int ret; +
Quoted 8 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ spin_lock(&dd->lock); + ret =3D blk_mq_sched_try_merge(q, bio); + spin_unlock(&dd->lock); +=20
Hi Jens,
first, good news, bfq is passing my first sanity checks. Still, I need a little more help for the following issue. There is a case =
that
Quoted 1 line
Quoted 1 line
would be impossible to handle without modifying code outside bfq. =
But
Quoted 1 line
Quoted 1 line
so far such a case never occurred, and I hope that it can never =
occur.
Quoted 1 line
Quoted 1 line
I'll try to briefly list all relevant details on this concern of =
mine,
Quoted 8 lines
Quoted 2 lines
so that you can quickly confirm my hope, or highlight where or what I am missing.
=20
Remember my earlier advice - it's not a problem to change anything in the core, in fact I would be surprised if you did not need to. My foresight isn't THAT good! It's much better to fix up an inconsistency there, rather than work around it in the consumer of that API. =20
Quoted 15 lines
Quoted 4 lines
First, as done above for mq-deadline, invoking
blk_mq_sched_try_mergewith the scheduler lock held is of course necessary (for example, to protectq->last_merge). This may lead toput_rq_privateinvoked with the lock held, in case of successful merge.=20
Right, or some other lock with the same scope, as per my other email. =20Quoted 8 lines
As a consequence,
put_rq_privatemay be invoked:
(1) in IRQ context, no scheduler lock held, because of a completion:
can be handled by deferring work and lock grabbing, because the completed request is not queued in the scheduler any more;
(2) in process context, scheduler lock held, because of the above successful merge: must be handled immediately, for consistency, because the request is still queued in the scheduler;
(3) in process context, no scheduler lock held, for some other =
reason:
Quoted 7 lines
Quoted 7 lines
some path apparently may lead to this case, although I've never seen it to happen. Immediate handling, and hence locking, may be needed, depending on whether the request is still queued in the scheduler. =20
So, my main question is: is case (3) actually impossible? Should it be possible, I guess we would have a problem, because of the different lock state with respect to (2).
Quoted 5 lines
=20
I agree, there's some inconsistency there, if you potentially need to grab the lock in yourput_rq_privatehandler. The problem case is #2, when we have the merge. I would probably suggest that the best way to handle that is to pass back the dropped request so we can put it =
outside
Quoted 3 lines
of holding the lock.
=20
Let me see if I can come up with a good solution for this. We have to =
be
Quoted 1 line
consistent in how we invoke the scheduler functions, we can't have =
hooks
Quoted 1 line
that are called in unknown lock states. I also don't want you to have =
to
Quoted 3 lines
add defer work handling in that kind of path, that will impact your performance and overhead.
=20
I'll try to learn from your solution, because, as of now, I don't see how to avoid deferred work for the case where put_rq_private is invoked in interrupt context. In fact, for this case, we cannot grab the lock, unless we turn all spin_lock into spin_lock_irq*.
Quoted 1 line
Quoted 1 line
Finally, I hope that it is certainly impossible to have a case (4): =
in
Quoted 5 lines
Quoted 1 line
IRQ context, no lock held, but with the request in the scheduler.
=20
That should not be possible.
=20
Edit: since I'm on a flight and email won't send, I had a few minutes =
to
Quoted 4 lines
hack this up. Totally untested, but something like the below should do it. Not super pretty... I'll play with this a bit more tomorrow. =20
=20
The scheme is clear. One comment, in case it could make sense and avoid more complexity: since put_rq_priv is invoked in two different contexts, process or interrupt, I didn't feel so confusing that, when put_rq_priv is invoked in the context where the lock cannot be held (unless one is willing to pay with irq disabling all the times), the lock is not held, while, when invoked in the context where the lock can be held, the lock is actually held, or must be taken.
Thanks,
Paolo
block/blk-core.c static blk_qc_t blk_queue_bio(struct =
Quoted 5 lines
block/blk-core.c +0
-0@@ -1609,7 +1609,7 @@ static blk_qc_t blk_queue_bio(struct =
request_queue *q, struct bio *bio)
block/blk-core.c static blk_qc_t blk_queue_bio(struct =
Quoted 9 lines
block/blk-core.c +1
-1{struct blk_plug *plug; int el_ret, where =3D ELEVATOR_INSERT_SORT; -struct request *req; +struct request *req, *free; unsigned int request_count =3D 0;unsigned int wb_acct;=20
block/blk-core.c +0
-0@@ -1650,15 +1650,21 @@ static blk_qc_t blk_queue_bio(struct =
request_queue *q, struct bio *bio)
block/blk-merge.c static void blk_account_io_merge(struct request =
Quoted 28 lines
block/blk-core.c +8
-2if (el_ret =3D=3D ELEVATOR_BACK_MERGE) {if (bio_attempt_back_merge (q, req, bio)) {elv_bio_merged (q, req, bio); -if (!attempt_back_merge (q, req)) + free =3D attempt_back_merge(q, req); +if (!free)elv_merged_request (q, req, el_ret); +else +__blk_put_request (q, free); goto out_unlock; } } else if (el_ret =3D=3D ELEVATOR_FRONT_MERGE) {if (bio_attempt_front_merge (q, req, bio)) {elv_bio_merged (q, req, bio); -if (!attempt_front_merge (q, req)) + free =3D attempt_front_merge(q, req); +if (!free)elv_merged_request (q, req, el_ret); +else +__blk_put_request (q, free); goto out_unlock; } }block/blk-merge.c +0
-0@@ -661,29 +661,29 @@ static void blk_account_io_merge(struct request =
*req)
block/blk-merge.c static void blk_account_io_merge(struct request *req)
Quoted 4 lines
block/blk-merge.c +0
-1/* * Has to be called with the request spinlock acquired */ -static int attempt_merge(struct request_queue *q, struct request =
*req,
block/blk-merge.c static void blk_account_io_merge(struct request *req)
Quoted 3 lines
block/blk-merge.c +2
-1- struct request *next) +static struct request *attempt_merge(struct request_queue *q, + struct request *req, struct request =
*next)
block/blk-merge.c static int attempt_merge(struct request_queue *q, =
Quoted 30 lines
block/blk-merge.c +1
-1{if (!rq_mergeable (req) || !rq_mergeable (next)) -return 0 ; +return NULL ;=20
if (req_op(req) !=3D req_op(next))block/blk-merge.c +1
-1-return 0 ; +return NULL ;=20
/* * not contiguous */ if (blk_rq_pos(req) + blk_rq_sectors(req) !=3D blk_rq_pos(next))block/blk-merge.c +1
-1-return 0 ; +return NULL ;=20
if (rq_data_dir(req) !=3D rq_data_dir(next) || req->rq_disk !=3D next->rq_disk || req_no_special_merge(next))block/blk-merge.c +1
-1-return 0 ; +return NULL ;=20
if (req_op(req) =3D=3D REQ_OP_WRITE_SAME && !blk_write_same_mergeable(req->bio, next->bio))block/blk-merge.c +1
-1-return 0 ; +return NULL ;=20
/* * If we are allowed to merge, then append bio listblock/blk-merge.c +0
-0@@ -692,7 +692,7 @@ static int attempt_merge(struct request_queue *q, =
struct request *req,
block/blk-merge.c static int attempt_merge(struct request_queue =
Quoted 9 lines
block/blk-merge.c +1
-1* counts here. */ if (!ll_merge_requests_fn (q, req, next)) -return 0 ; +return NULL ;=20
/* * If failfast settings disagree or any of the two is alreadyblock/blk-merge.c +0
-0@@ -732,30 +732,32 @@ static int attempt_merge(struct request_queue =
*q, struct request *req,
Quoted 14 lines
block/blk-merge.c +0
-0if (blk_rq_cpu_valid (next)) req->cpu =3D next->cpu;=20
block/blk-merge.c +4
-1-/* owner-ship of bio passed from next to req */ +/* +* owner-ship of bio passed from next to req, return 'next' for +* the caller to free +*/ next->bio =3D NULL;block/blk-merge.c +1
-2-__blk_put_request (q, next); -return 1 ; +return next;}
=20
block/blk-merge.c
Quoted 2 lines
block/blk-merge.c +1
-1-int attempt_back_merge (struct request_queue *q,struct request *rq) +struct request *attempt_back_merge(struct request_queue *q, struct =
request *rq)
block/blk-merge.c
Quoted 12 lines
{ struct request *next =3D elv_latter_request(q, rq); =20 if (next) return attempt_merge(q, rq, next);=20
block/blk-merge.c +1
-1-return 0 ; +return NULL ;}
=20block/blk-merge.c +1
-1-int attempt_front_merge (struct request_queue *q,struct request *rq) +struct request *attempt_front_merge(struct request_queue *q, struct =
request *rq)
block/blk-merge.c int blk_attempt_req_merge(struct request_queue =
Quoted 12 lines
{ struct request *prev =3D elv_former_request(q, rq); =20 if (prev) return attempt_merge(q, prev, rq);=20
block/blk-merge.c +1
-1-return 0 ; +return NULL ;}
=20
int blk_attempt_req_merge(structrequest_queue*q, struct request *rq,block/blk-merge.c +0
-0@@ -767,7 +769,12 @@ int blk_attempt_req_merge(struct request_queue =
*q, struct request *rq,
block/blk-merge.c int blk_attempt_req_merge(struct request_queue = · line 769
Quoted 1 line
block/blk-merge.c +0
-0if (!e->type->ops.sq.elevator_allow_rq_merge_fn(q, rq, =
next))
block/blk-mq-sched.c void blk_mq_sched_move_to_dispatch(struct =
Quoted 17 lines
block/blk-merge.c +0
-0return 0 ;=20
block/blk-merge.c +6
-1-return attempt_merge (q, rq, next); +if (attempt_merge (q, rq, next)) { +__blk_put_request (q, next); +return 1 ; + } + +return 0 ;}
=20
boolblk_rq_merge_ok(struct request *rq, struct bio *bio)block/blk-mq-sched.c +0
-0@@ -234,7 +234,8 @@ void blk_mq_sched_move_to_dispatch(struct =
blk_mq_hw_ctx *hctx,
block/blk-mq-sched.c bool blk_mq_sched_try_merge(struct request_queue =
Quoted 10 lines
block/blk-mq-sched.c +0
-0}EXPORT_SYMBOL_GPL (blk_mq_sched_move_to_dispatch);=20
block/blk-mq-sched.c +2
-1-bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio) +bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio, +struct request **merged_request){ struct request *rq; int ret;block/blk-mq-sched.c +0
-0@@ -244,7 +245,8 @@ bool blk_mq_sched_try_merge(struct request_queue =
*q, struct bio *bio)
block/blk-mq-sched.c bool blk_mq_sched_try_merge(struct request_queue =
Quoted 10 lines
block/blk-mq-sched.c +2
-1if (!blk_mq_sched_allow_merge (q, rq, bio))return false;if (bio_attempt_back_merge (q, rq, bio)) { -if (!attempt_back_merge (q, rq)) + *merged_request =3D attempt_back_merge(q, rq); +if (!*merged_request)elv_merged_request (q, rq, ret);return true; }@@ -252,7 +254,8 @@ bool blk_mq_sched_try_merge(struct request_queue =
*q, struct bio *bio)
Quoted 14 lines
block/blk-mq-sched.c +2
-1if (!blk_mq_sched_allow_merge (q, rq, bio))return false;if (bio_attempt_front_merge (q, rq, bio)) { -if (!attempt_front_merge (q, rq)) + *merged_request =3D attempt_front_merge(q, rq); +if (!*merged_request)elv_merged_request (q, rq, ret);return true; }block/blk-mq-sched.h +0
-0@@ -16,7 +16,8 @@ void blk_mq_sched_put_request(struct request *rq);
Quoted 3 lines
=20
voidblk_mq_sched_request_inserted(struct request *rq); bool blk_mq_sched_bypass_insert(structblk_mq_hw_ctx*hctx, struct =
request *rq);
Quoted 1 line
-bool blk_mq_sched_try_merge(struct
request_queue*q, struct bio =
*bio);
Quoted 3 lines
block/blk-mq-sched.h +2
-0+bool blk_mq_sched_try_merge (struct request_queue *q,struct bio *bio, +struct request **merged_request);bool __blk_mq_sched_bio_merge(struct
request_queue*q, struct bio =
*bio);
Quoted 1 line
bool blk_mq_sched_try_insert_merge(struct
request_queue*q, struct =
request *rq);
block/blk.h int ll_back_merge_fn(struct request_queue *q, =
Quoted 6 lines
void
blk_mq_sched_restart_queues(struct blk_mq_hw_ctx *hctx);block/blk.h +0
-0@@ -204,8 +204,8 @@ int ll_back_merge_fn(struct request_queue *q, =
struct request *req,
block/blk.h int ll_back_merge_fn(struct request_queue *q, struct request *req,
Quoted 6 lines
block/blk.h +0
-0struct bio *bio);int ll_front_merge_fn(struct
request_queue*q, struct request *req,=20struct bio *bio);block/blk.h +1
-2-int attempt_back_merge (struct request_queue *q,struct request *rq); -int attempt_front_merge (struct request_queue *q,struct request *rq); +struct request *attempt_back_merge(struct request_queue *q, struct =
request *rq);
Quoted 1 line
+struct request *attempt_front_merge(struct
request_queue*q, struct =
request *rq);
block/mq-deadline.c static bool dd_bio_merge(struct blk_mq_hw_ctx =
Quoted 8 lines
int blk_attempt_req_merge(struct
request_queue*q, struct request *rq,struct request *next);void
blk_recalc_rq_segments(struct request *rq);block/mq-deadline.c +0
-0@@ -371,12 +371,16 @@ static bool dd_bio_merge(struct blk_mq_hw_ctx =
*hctx, struct bio *bio)
Quoted 22 lines
block/mq-deadline.c +2
-1{ struct request_queue *q =3D hctx->queue; struct deadline_data *dd =3D q->elevator->elevator_data; -int ret; + struct request *free =3D NULL; +bool ret;=20
spin_lock(&dd->lock);block/mq-deadline.c +1
-1- ret =3D blk_mq_sched_try_merge(q, bio); + ret =3D blk_mq_sched_try_merge(q, bio, &free);spin_unlock(&dd->lock);=20
block/mq-deadline.c +3
-0+if (free) +blk_mq_free_request (free); +return ret; }=20
=20
--=20
Jens Axboe
=20
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 7 lines · Paolo Valente
The scheme is clear. One comment, in case it could make sense and avoid more complexity: since
put_rq_privis invoked in two different contexts, process or interrupt, I didn't feel so confusing that, whenput_rq_privis invoked in the context where the lock cannot be held (unless one is willing to pay with irq disabling all the times), the lock is not held, while, when invoked in the context where the lock can be held, the lock is actually held, or must be taken.
If you grab the same lock from put_rq_priv, yes, you must make it IRQ disabling in all contexts, and use _irqsave() from put_rq_priv. If it's just freeing resources, you could potentially wait and do that when someone else needs them, since that part will come from proces context. That would need two locks, though.
As I said above, I would not worry about the IRQ disabling lock.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 2 lines
Il giorno 02 feb 2017, alle ore 16:30, Jens Axboe <[email protected]> ha =
scritto:
Quoted 9 lines
=20
Quoted 7 lines · Paolo Valente
The scheme is clear. One comment, in case it could make sense and avoid more complexity: since
put_rq_privis invoked in two different contexts, process or interrupt, I didn't feel so confusing that, whenput_rq_privis invoked in the context where the lock cannot be held (unless one is willing to pay with irq disabling all the times), the lock is not held, while, when invoked in the context where the lock can be held, the lock is actually held, or must be taken.
Quoted 3 lines
=20
If you grab the same lock fromput_rq_priv, yes, you must make it IRQ disabling in all contexts, and use_irqsave()fromput_rq_priv. If =
it's
Quoted 2 lines
just freeing resources, you could potentially wait and do that when someone else needs them, since that part will come from proces =
context.
Quoted 4 lines
That would need two locks, though.
=20
As I said above, I would not worry about the IRQ disabling lock. =20
I'm sorry, I focused only on the IRQ-disabling consequence of grabbing a scheduler lock also in IRQ context. I thought it was a serious enough issue to avoid this option. Yet there is also a deadlock problem related to this option. In fact, the IRQ handler may preempt some process-context code that already holds some other locks, and, if some of these locks are already held by another process, which is executing on another CPU and which then tries to take the scheduler lock, or which happens to be preempted by an IRQ handler trying to grab the scheduler lock, then a deadlock occurs. This is not just a speculation, but a problem that did occur before I moved to a deferred-work solution, and that can be readily reproduced. Before moving to a deferred work solution, I tried various code manipulations to avoid these deadlocks without resorting to deferred work, but at no avail.
At any rate, bfq seems now to work, so I can finally move from just asking questions endlessly, to proposing actual code to discuss on. I'm about to: port this version of bfq to your improved/fixed blk-mq-sched version in for-4.11 (port postponed, to avoid introducing further changes in code that did not yet wok), run more extensive tests, polish commits a little bit, and finally share a branch.
Thanks,
Paolo
Quoted 5 lines
--=20
Jens Axboe
=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
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 21 lines · Paolo Valente
Quoted 12 lines
Il giorno 02 feb 2017, alle ore 16:30, Jens Axboe <[email protected]> ha scritto:
Quoted 7 lines · Paolo Valente
The scheme is clear. One comment, in case it could make sense and avoid more complexity: since
put_rq_privis invoked in two different contexts, process or interrupt, I didn't feel so confusing that, whenput_rq_privis invoked in the context where the lock cannot be held (unless one is willing to pay with irq disabling all the times), the lock is not held, while, when invoked in the context where the lock can be held, the lock is actually held, or must be taken.Quoted 8 lines
If you grab the same lock from
put_rq_priv, yes, you must make it IRQ disabling in all contexts, and use_irqsave()fromput_rq_priv. If it's just freeing resources, you could potentially wait and do that when someone else needs them, since that part will come from proces context. That would need two locks, though.As I said above, I would not worry about the IRQ disabling lock.
Quoted 14 lines
I'm sorry, I focused only on the IRQ-disabling consequence of grabbing a scheduler lock also in IRQ context. I thought it was a serious enough issue to avoid this option. Yet there is also a deadlock problem related to this option. In fact, the IRQ handler may preempt some process-context code that already holds some other locks, and, if some of these locks are already held by another process, which is executing on another CPU and which then tries to take the scheduler lock, or which happens to be preempted by an IRQ handler trying to grab the scheduler lock, then a deadlock occurs. This is not just a speculation, but a problem that did occur before I moved to a deferred-work solution, and that can be readily reproduced. Before moving to a deferred work solution, I tried various code manipulations to avoid these deadlocks without resorting to deferred work, but at no avail.
There are two important rules here:
1) If a lock is ever used in interrupt context, anyone acquiring it must ensure that interrupts gets disabled.
2) If multiple locks are needed, they need to be acquired in the right order.
Instead of talking in hypotheticals, be more specific. With the latest code, the scheduler lock should now be fine, there should be no cases where you are being invoked with it held. I'm assuming you are running with lockdep enabled on your kernel? Post the stack traces from your problem (and your code...), then we can take a look.
Don't punt to deferring work from your put_rq_private() function, that's a suboptimal work around. It needs to be fixed for real.
Quoted 6 lines
At any rate, bfq seems now to work, so I can finally move from just asking questions endlessly, to proposing actual code to discuss on. I'm about to: port this version of bfq to your improved/fixed blk-mq-sched version in for-4.11 (port postponed, to avoid introducing further changes in code that did not yet wok), run more extensive tests, polish commits a little bit, and finally share a branch.
Post the code sooner rather than later. There are bound to be things that need to be improved or fixed up, let's start this process now. The framework is pretty much buttoned up at this point, so there's time to shift the attention a bit to a consumer of it.
Signature · 1 line
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 2 lines
Il giorno 02 feb 2017, alle ore 22:32, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
=20
Quoted 1 line
Il giorno 02 feb 2017, alle ore 16:30, Jens Axboe <[email protected]> ha =
scritto:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
=20
Quoted 2 lines · Paolo Valente
The scheme is clear. One comment, in case it could make sense and avoid more complexity: since
put_rq_privis invoked in two =
different
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
contexts, process or interrupt, I didn't feel so confusing that, =
when
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
put_rq_privis invoked in the context where the lock cannot be held (unless one is willing to pay with irq disabling all the times), =
the
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
lock is not held, while, when invoked in the context where the lock can be held, the lock is actually held, or must be taken.
=20
If you grab the same lock fromput_rq_priv, yes, you must make it =
IRQ
Quoted 1 line
Quoted 1 line
Quoted 1 line
disabling in all contexts, and use
_irqsave()fromput_rq_priv. If =
it's
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
just freeing resources, you could potentially wait and do that when someone else needs them, since that part will come from proces =
context.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
That would need two locks, though.
=20
As I said above, I would not worry about the IRQ disabling lock. =20=20
I'm sorry, I focused only on the IRQ-disabling consequence of =
grabbing
Quoted 4 lines
Quoted 4 lines
a scheduler lock also in IRQ context. I thought it was a serious enough issue to avoid this option. Yet there is also a deadlock problem related to this option. In fact, the IRQ handler may preempt some process-context code that already holds some other locks, and, =
if
Quoted 7 lines
Quoted 7 lines
some of these locks are already held by another process, which is executing on another CPU and which then tries to take the scheduler lock, or which happens to be preempted by an IRQ handler trying to grab the scheduler lock, then a deadlock occurs. This is not just a speculation, but a problem that did occur before I moved to a deferred-work solution, and that can be readily reproduced. Before moving to a deferred work solution, I tried various code =
manipulations
Quoted 1 line
Quoted 1 line
to avoid these deadlocks without resorting to deferred work, but at =
no
Quoted 5 lines
Quoted 1 line
avail.
=20
There are two important rules here:
=20
1) If a lock is ever used in interrupt context, anyone acquiring it =
must
Quoted 11 lines
ensure that interrupts gets disabled.
=20
2) If multiple locks are needed, they need to be acquired in the right order.
=20
Instead of talking in hypotheticals, be more specific. With the latest code, the scheduler lock should now be fine, there should be no cases where you are being invoked with it held. I'm assuming you are running with lockdep enabled on your kernel? Post the stack traces from your problem (and your code...), then we can take a look.
=20
Hi Jens,
your last change (freeing requests outside merges) did remove two of out three deadlock scenarios for which I turned some handlers into deferred work items in bfq-mq. For the remaining one, I'm about to send a separate email, with the description of the deadlock, together with the patch that, applied on top of the bfq-mq branch, causes the deadlock by turning moving back the body of exit_icq from a deferred work to the exit_icq hook itself. And, yes, as I'll write below, I'm finally about to share a branch containing bfq-mq.
Quoted 1 line
Don't punt to deferring work from your
put_rq_private()function, =
that's
Quoted 2 lines
a suboptimal work around. It needs to be fixed for real. =20
Yeah, sub-optimal also in terms of poor developer time: I spent a lot of time letting that deferred work, and hopefully be a little efficient! The actual problem has been that I preferred to try to get to the bottom of those deadlocks on my own, and not to bother you also on that issue. Maybe next time I will ask you one more question instead of one less :)
Quoted 4 lines
Quoted 4 lines
At any rate, bfq seems now to work, so I can finally move from just asking questions endlessly, to proposing actual code to discuss on. I'm about to: port this version of bfq to your improved/fixed blk-mq-sched version in for-4.11 (port postponed, to avoid =
introducing
Quoted 5 lines
Quoted 2 lines
further changes in code that did not yet wok), run more extensive tests, polish commits a little bit, and finally share a branch.
=20
Post the code sooner rather than later. There are bound to be things that need to be improved or fixed up, let's start this process now. =
The
Quoted 3 lines
framework is pretty much buttoned up at this point, so there's time to shift the attention a bit to a consumer of it.
=20
Ok, to follow this suggestion of yours at 100%, I have postponed several steps (removal of any invariant check or extra log message, merging of the various files bfq is made of in just one file, code polishing), and I'm about to share my current WIP branch in a follow-up message.
Thanks,
Paolo
Quoted 2 lines
--=20
Jens Axboe
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
In reply to Jens AxboeQuoted 2 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha =
scritto:
Quoted 5 lines
=20
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design. =20Signed-off-by Jens Axboe <[email protected]>
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static void dd_merged_requests(struct request_queue *q, struct =
request *req,
block/mq-deadline.c
Quoted 7 lines
block/mq-deadline.c new file +7
-0+ struct request *next) +{ +/* +* if next expires before rq, assign its expire time to rq +* and move into next position (next will be deleted) in fifo +*/ + if (!list_empty(&req->queuelist) && =
!list_empty(&next->queuelist)) {
block/mq-deadline.c line 157
Quoted 7 lines
block/mq-deadline.c new file +7
-0+if (time_before ((unsigned long )next->fifo_time, + (unsigned long )req->fifo_time)) { +list_move (&req->queuelist, &next->queuelist); + req->fifo_time =3D next->fifo_time; + } + } +
Jens,
while trying to imagine the possible causes of Bart's hang with bfq-mq, I've bumped into the following doubt: in the above function (in my case, in bfq-mq-'s equivalent of the above function), are we sure that neither req or next could EVER be in dd->dispatch instead of dd->fifo_list? I've tried to verify it, but, although I think it has = never
happened in my tests, I was not able to make sure that no unlucky combination may ever happen (considering also the use of blk_rq_is_passthrough too, to decide where to put a new request).
I'm making a blunder, right?
Thanks,
Paolo
Re: [PATCH 7/8] mq-deadline: add blk-mq adaptation of the deadline IO scheduler
Quoted 35 lines · Paolo Valente
Quoted 7 lines
Il giorno 17 dic 2016, alle ore 01:12, Jens Axboe <[email protected]> ha scritto:
This is basically identical to deadline-iosched, except it registers as a MQ capable scheduler. This is still a single queue design.
Signed-off-by Jens Axboe <[email protected]>...
Quoted 6 lines
block/mq-deadline.c new file +6
-0+ +static void dd_merged_requests (struct request_queue *q,struct request *req, +struct request *next) +{ +/* +* if next expires before rq, assign its expire time to rq block/mq-deadline.c line 157
Quoted 10 lines
block/mq-deadline.c new file +10
-0+* and move into next position (next will be deleted) in fifo +*/ +if (!list_empty (&req->queuelist) && !list_empty (&next->queuelist)) { +if (time_before ((unsigned long )next->fifo_time, + (unsigned long )req->fifo_time)) { +list_move (&req->queuelist, &next->queuelist); + req->fifo_time = next->fifo_time; + } + } +Jens,
while trying to imagine the possible causes of Bart's hang with bfq-mq, I've bumped into the following doubt: in the above function (in my case, in bfq-mq-'s equivalent of the above function), are we sure that neither req or next could EVER be indd->dispatchinstead ofdd->fifo_list? I've tried to verify it, but, although I think it has never happened in my tests, I was not able to make sure that no unlucky combination may ever happen (considering also the use ofblk_rq_is_passthroughtoo, to decide where to put a new request).
Quoted 1 line
I'm making a blunder, right?
If a request goes into dd->dispatch, it's going to be found for merging. Hence we can never call the above on the request.
Signature · 1 line
Jens Axboe