Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Documentation/block/deadline-iosched.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@ that comes at basically 0 cost we leave that on. We simply disable the
rbtree front sector lookup when the io scheduler merge function is called.


dispatch_direct (bool)
----------------------

Enabled by default. Allows new requests to bypass the scheduler's sort tree,
FIFO and merge hash when the hardware context is not congested, stopped or
quiesced. On fast devices such as NVMe SSDs with spare capacity, sorting and
merging may offer little benefit while adding CPU overhead and limiting
bandwidth. Direct dispatch can reduce this overhead and submission latency.

Direct dispatch reduces opportunities for merging and sorting, and may bypass
queued requests, including higher priority or expired requests. Set
dispatch_direct to 0 to restore normal scheduler insertion.


Nov 11 2002, Jens Axboe <jens.axboe@oracle.com>
40 changes: 31 additions & 9 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2761,17 +2761,26 @@ static bool blk_mq_get_budget_and_tag(struct request *rq)
static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
struct request *rq)
{
bool use_sched = rq->rq_flags & RQF_USE_SCHED;
bool run_queue_async = use_sched || (rq->cmd_flags & REQ_NOWAIT);
blk_status_t ret;

if (blk_mq_hctx_stopped(hctx) || blk_queue_quiesced(rq->q)) {
blk_mq_insert_request(rq, 0);
blk_mq_run_hw_queue(hctx, false);
blk_mq_run_hw_queue(hctx, use_sched);
return;
}

if ((rq->rq_flags & RQF_USE_SCHED) || !blk_mq_get_budget_and_tag(rq)) {
if (use_sched) {
struct elevator_mq_ops *ops = &rq->q->elevator->type->ops;

if (ops->skip_request)
use_sched = !ops->skip_request(rq);
}

if (use_sched || !blk_mq_get_budget_and_tag(rq)) {
blk_mq_insert_request(rq, 0);
blk_mq_run_hw_queue(hctx, rq->cmd_flags & REQ_NOWAIT);
blk_mq_run_hw_queue(hctx, run_queue_async);
return;
}

Expand Down Expand Up @@ -2937,9 +2946,14 @@ static void blk_mq_dispatch_list(struct rq_list *rqs, bool from_sched)
spin_unlock(&this_hctx->lock);
blk_mq_run_hw_queue(this_hctx, from_sched);
} else if (this_hctx->queue->elevator) {
this_hctx->queue->elevator->type->ops.insert_requests(this_hctx,
&list, 0);
blk_mq_run_hw_queue(this_hctx, from_sched);
if (!this_hctx->dispatch_busy && !from_sched)
blk_mq_run_dispatch_ops(this_hctx->queue,
blk_mq_try_issue_list_directly(this_hctx, &list));
if (!list_empty(&list)) {
this_hctx->queue->elevator->type->ops.insert_requests(
this_hctx, &list, 0);
blk_mq_run_hw_queue(this_hctx, from_sched);
}
} else {
blk_mq_insert_requests(this_hctx, this_ctx, &list, from_sched);
}
Expand Down Expand Up @@ -2994,13 +3008,22 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
static void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
struct list_head *list)
{
struct elevator_queue *e = hctx->queue->elevator;
int queued = 0;
blk_status_t ret = BLK_STS_OK;

while (!list_empty(list)) {
struct request *rq = list_first_entry(list, struct request,
queuelist);

/* Scheduler requests need approval and dispatch accounting. */
if (e && (READ_ONCE(hctx->dispatch_busy) ||
blk_mq_hctx_stopped(hctx) ||
blk_queue_quiesced(hctx->queue) ||
!e->type->ops.skip_request ||
!e->type->ops.skip_request(rq)))
break;

list_del_init(&rq->queuelist);
ret = blk_mq_request_issue_directly(rq, list_empty(list));
switch (ret) {
Expand All @@ -3020,7 +3043,7 @@ static void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
}

out:
if (ret != BLK_STS_OK)
if (ret != BLK_STS_OK || !list_empty(list))
blk_mq_commit_rqs(hctx, queued, false);
}

Expand Down Expand Up @@ -3234,8 +3257,7 @@ void blk_mq_submit_bio(struct bio *bio)
}

hctx = rq->mq_hctx;
if ((rq->rq_flags & RQF_USE_SCHED) ||
(hctx->dispatch_busy && (q->nr_hw_queues == 1 || !is_sync))) {
if (hctx->dispatch_busy && (q->nr_hw_queues == 1 || !is_sync)) {
blk_mq_insert_request(rq, 0);
blk_mq_run_hw_queue(hctx, true);
} else {
Expand Down
1 change: 1 addition & 0 deletions block/elevator.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct elevator_mq_ops {
void (*insert_requests)(struct blk_mq_hw_ctx *hctx, struct list_head *list,
blk_insert_t flags);
struct request *(*dispatch_request)(struct blk_mq_hw_ctx *);
bool (*skip_request)(struct request *rq);
bool (*has_work)(struct blk_mq_hw_ctx *);
void (*completed_request)(struct request *, u64);
void (*requeue_request)(struct request *);
Expand Down
50 changes: 48 additions & 2 deletions block/mq-deadline.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct deadline_data {
int writes_starved;
int front_merges;
int prio_aging_expire;
bool dispatch_direct;

spinlock_t lock;
};
Expand Down Expand Up @@ -310,8 +311,11 @@ static struct request *dd_start_request(struct deadline_data *dd,
enum dd_prio prio = ioprio_class_to_prio[ioprio_class];

dd->per_prio[prio].latest_pos[data_dir] = blk_rq_pos(rq);
dd->per_prio[prio].stats.dispatched++;
rq->rq_flags |= RQF_STARTED;
/* Count each request once, including direct dispatch followed by requeue. */
if (!(rq->rq_flags & RQF_STARTED)) {
dd->per_prio[prio].stats.dispatched++;
rq->rq_flags |= RQF_STARTED;
}
return rq;
}

Expand Down Expand Up @@ -550,6 +554,7 @@ static int dd_init_sched(struct request_queue *q, struct elevator_queue *eq)
dd->last_dir = DD_WRITE;
dd->fifo_batch = fifo_batch;
dd->prio_aging_expire = prio_aging_expire;
dd->dispatch_direct = true;
spin_lock_init(&dd->lock);

/* We dispatch from request queue wide instead of hw queue */
Expand Down Expand Up @@ -728,6 +733,29 @@ static bool dd_has_work(struct blk_mq_hw_ctx *hctx)
return false;
}

/*
* When blk-mq finds the hctx uncongested, let new requests skip the sort tree,
* FIFO and merge hash
*/
static bool dd_skip_request(struct request *rq)
{
struct deadline_data *dd = rq->q->elevator->elevator_data;
const enum dd_data_dir data_dir = rq_data_dir(rq);
const enum dd_prio prio = ioprio_class_to_prio[dd_rq_ioclass(rq)];
struct dd_per_prio *per_prio = &dd->per_prio[prio];

if (!READ_ONCE(dd->dispatch_direct) || rq->elv.priv[0] ||
READ_ONCE(rq->mq_hctx->dispatch_busy))
return false;

spin_lock(&dd->lock);
per_prio->stats.inserted++;
rq->elv.priv[0] = per_prio;
dd_start_request(dd, data_dir, rq);
spin_unlock(&dd->lock);
return true;
}

/*
* sysfs parts below
*/
Expand All @@ -745,6 +773,7 @@ SHOW_JIFFIES(deadline_prio_aging_expire_show, dd->prio_aging_expire);
SHOW_INT(deadline_writes_starved_show, dd->writes_starved);
SHOW_INT(deadline_front_merges_show, dd->front_merges);
SHOW_INT(deadline_fifo_batch_show, dd->fifo_batch);
SHOW_INT(deadline_dispatch_direct_show, READ_ONCE(dd->dispatch_direct));
#undef SHOW_INT
#undef SHOW_JIFFIES

Expand Down Expand Up @@ -778,6 +807,21 @@ STORE_INT(deadline_fifo_batch_store, &dd->fifo_batch, 0, INT_MAX);
#undef STORE_INT
#undef STORE_JIFFIES

static ssize_t deadline_dispatch_direct_store(struct elevator_queue *e,
const char *page, size_t count)
{
struct deadline_data *dd = e->elevator_data;
bool enabled;
int ret;

ret = kstrtobool(page, &enabled);
if (ret)
return ret;

WRITE_ONCE(dd->dispatch_direct, enabled);
return count;
}

#define DD_ATTR(name) \
__ATTR(name, 0644, deadline_##name##_show, deadline_##name##_store)

Expand All @@ -788,6 +832,7 @@ static const struct elv_fs_entry deadline_attrs[] = {
DD_ATTR(front_merges),
DD_ATTR(fifo_batch),
DD_ATTR(prio_aging_expire),
DD_ATTR(dispatch_direct),
__ATTR_NULL
};

Expand Down Expand Up @@ -989,6 +1034,7 @@ static struct elevator_type mq_deadline = {
.limit_depth = dd_limit_depth,
.insert_requests = dd_insert_requests,
.dispatch_request = dd_dispatch_request,
.skip_request = dd_skip_request,
.prepare_request = dd_prepare_request,
.finish_request = dd_finish_request,
.next_request = elv_rb_latter_request,
Expand Down
Loading