From: Paolo Valente <paolo.valente@unimore.it>
To: "Jens Axboe" <axboe@fb.com>, "Matias Bjørling" <m@bjorling.me>,
"Arianna Avanzini" <avanzini@google.com>
Cc: Paolo Valente <paolo.valente@unimore.it>,
Akinobu Mita <akinobu.mita@gmail.com>,
"Luis R. Rodriguez" <mcgrof@suse.com>,
Ming Lei <ming.lei@canonical.com>,
Mike Krinkin <krinkin.m.u@gmail.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH BUGFIX V2 1/3] null_blk: set a separate timer for each command
Date: Tue, 1 Dec 2015 11:48:17 +0100 [thread overview]
Message-ID: <1448966899-3399-2-git-send-email-paolo.valente@unimore.it> (raw)
In-Reply-To: <1448966899-3399-1-git-send-email-paolo.valente@unimore.it>
For the Timer IRQ mode (i.e., when command completions are delayed),
there is one timer for each CPU. Each of these timers
. has a completion queue associated with it, containing all the
command completions to be executed when the timer fires;
. is set, and a new completion-to-execute is inserted into its
completion queue, every time the dispatch code for a new command
happens to be executed on the CPU related to the timer.
This implies that, if the dispatch of a new command happens to be
executed on a CPU whose timer has already been set, but has not yet
fired, then the timer is set again, to the completion time of the
newly arrived command. When the timer eventually fires, all its queued
completions are executed.
This way of handling delayed command completions entails the following
problem: if more than one command completion is inserted into the
queue of a timer before the timer fires, then the expiration time for
the timer is moved forward every time each of these completions is
enqueued. As a consequence, only the last completion enqueued enjoys a
correct execution time, while all previous completions are unjustly
delayed until the last completion is executed (and at that time they
are executed all together).
Specifically, if all the above completions are enqueued almost at the
same time, then the problem is negligible. On the opposite end, if
every completion is enqueued a while after the previous completion was
enqueued (in the extreme case, it is enqueued only right before the
timer would have expired), then every enqueued completion, except for
the last one, experiences an inflated delay, proportional to the number
of completions enqueued after it. In the end, commands, and thus I/O
requests, may be completed at an arbitrarily lower rate than the
desired one.
This commit addresses this issue by replacing per-CPU timers with
per-command timers, i.e., by associating an individual timer with each
command.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini@google.com>
---
drivers/block/null_blk.c | 79 +++++++++++++++---------------------------------
1 file changed, 24 insertions(+), 55 deletions(-)
diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
index 5c8ba54..08932f5 100644
--- a/drivers/block/null_blk.c
+++ b/drivers/block/null_blk.c
@@ -18,6 +18,7 @@ struct nullb_cmd {
struct bio *bio;
unsigned int tag;
struct nullb_queue *nq;
+ struct hrtimer timer;
};
struct nullb_queue {
@@ -49,17 +50,6 @@ static int null_major;
static int nullb_indexes;
static struct kmem_cache *ppa_cache;
-struct completion_queue {
- struct llist_head list;
- struct hrtimer timer;
-};
-
-/*
- * These are per-cpu for now, they will need to be configured by the
- * complete_queues parameter and appropriately mapped.
- */
-static DEFINE_PER_CPU(struct completion_queue, completion_queues);
-
enum {
NULL_IRQ_NONE = 0,
NULL_IRQ_SOFTIRQ = 1,
@@ -180,6 +170,8 @@ static void free_cmd(struct nullb_cmd *cmd)
put_tag(cmd->nq, cmd->tag);
}
+static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer);
+
static struct nullb_cmd *__alloc_cmd(struct nullb_queue *nq)
{
struct nullb_cmd *cmd;
@@ -190,6 +182,11 @@ static struct nullb_cmd *__alloc_cmd(struct nullb_queue *nq)
cmd = &nq->cmds[tag];
cmd->tag = tag;
cmd->nq = nq;
+ if (irqmode == NULL_IRQ_TIMER) {
+ hrtimer_init(&cmd->timer, CLOCK_MONOTONIC,
+ HRTIMER_MODE_REL);
+ cmd->timer.function = null_cmd_timer_expired;
+ }
return cmd;
}
@@ -238,47 +235,28 @@ static void end_cmd(struct nullb_cmd *cmd)
static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)
{
- struct completion_queue *cq;
- struct llist_node *entry;
- struct nullb_cmd *cmd;
-
- cq = &per_cpu(completion_queues, smp_processor_id());
-
- while ((entry = llist_del_all(&cq->list)) != NULL) {
- entry = llist_reverse_order(entry);
- do {
- struct request_queue *q = NULL;
+ struct nullb_cmd *cmd = container_of(timer, struct nullb_cmd, timer);
+ struct request_queue *q = NULL;
- cmd = container_of(entry, struct nullb_cmd, ll_list);
- entry = entry->next;
- if (cmd->rq)
- q = cmd->rq->q;
- end_cmd(cmd);
+ if (cmd->rq)
+ q = cmd->rq->q;
- if (q && !q->mq_ops && blk_queue_stopped(q)) {
- spin_lock(q->queue_lock);
- if (blk_queue_stopped(q))
- blk_start_queue(q);
- spin_unlock(q->queue_lock);
- }
- } while (entry);
+ if (q && !q->mq_ops && blk_queue_stopped(q)) {
+ spin_lock(q->queue_lock);
+ if (blk_queue_stopped(q))
+ blk_start_queue(q);
+ spin_unlock(q->queue_lock);
}
+ end_cmd(cmd);
return HRTIMER_NORESTART;
}
static void null_cmd_end_timer(struct nullb_cmd *cmd)
{
- struct completion_queue *cq = &per_cpu(completion_queues, get_cpu());
-
- cmd->ll_list.next = NULL;
- if (llist_add(&cmd->ll_list, &cq->list)) {
- ktime_t kt = ktime_set(0, completion_nsec);
+ ktime_t kt = ktime_set(0, completion_nsec);
- hrtimer_start(&cq->timer, kt, HRTIMER_MODE_REL_PINNED);
- }
-
- put_cpu();
+ hrtimer_start(&cmd->timer, kt, HRTIMER_MODE_REL);
}
static void null_softirq_done_fn(struct request *rq)
@@ -376,6 +354,10 @@ static int null_queue_rq(struct blk_mq_hw_ctx *hctx,
{
struct nullb_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
+ if (irqmode == NULL_IRQ_TIMER) {
+ hrtimer_init(&cmd->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+ cmd->timer.function = null_cmd_timer_expired;
+ }
cmd->rq = bd->rq;
cmd->nq = hctx->driver_data;
@@ -813,19 +795,6 @@ static int __init null_init(void)
mutex_init(&lock);
- /* Initialize a separate list for each CPU for issuing softirqs */
- for_each_possible_cpu(i) {
- struct completion_queue *cq = &per_cpu(completion_queues, i);
-
- init_llist_head(&cq->list);
-
- if (irqmode != NULL_IRQ_TIMER)
- continue;
-
- hrtimer_init(&cq->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
- cq->timer.function = null_cmd_timer_expired;
- }
-
null_major = register_blkdev(0, "nullb");
if (null_major < 0)
return null_major;
--
1.9.1
next prev parent reply other threads:[~2015-12-01 10:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-02 14:31 [PATCH BUGFIX 0/3] null_blk: fix throughout losses and hangs Paolo Valente
2015-11-02 14:31 ` [PATCH BUGFIX 1/3] null_blk: set a separate timer for each command Paolo Valente
2015-11-02 16:14 ` Jens Axboe
2015-11-03 9:01 ` Paolo Valente
2015-11-29 17:27 ` Paolo Valente
2015-11-30 15:55 ` Jens Axboe
2015-12-01 10:48 ` [PATCH BUGFIX V2 0/3] null_blk: fix throughput losses and hangs Paolo Valente
2015-12-01 10:48 ` Paolo Valente [this message]
2015-12-01 10:48 ` [PATCH BUGFIX V2 2/3] null_blk: guarantee device restart in all irq modes Paolo Valente
2015-12-01 10:48 ` [PATCH BUGFIX V2 3/3] null_blk: change type of completion_nsec to unsigned long Paolo Valente
2015-12-01 17:52 ` [PATCH BUGFIX V2 0/3] null_blk: fix throughput losses and hangs Jens Axboe
2015-11-02 14:31 ` [PATCH BUGFIX 2/3] null_blk: guarantee device restart in all irq modes Paolo Valente
2015-11-02 16:25 ` Jens Axboe
2015-11-03 9:02 ` Paolo Valente
2015-11-02 14:31 ` [PATCH BUGFIX 3/3] null_blk: change type of completion_nsec to unsigned long Paolo Valente
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448966899-3399-2-git-send-email-paolo.valente@unimore.it \
--to=paolo.valente@unimore.it \
--cc=akinobu.mita@gmail.com \
--cc=avanzini@google.com \
--cc=axboe@fb.com \
--cc=krinkin.m.u@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=m@bjorling.me \
--cc=mcgrof@suse.com \
--cc=ming.lei@canonical.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®