The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: Ming Lei <tom.leiming@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH 3/4] blk-mq: establish new mapping before cpu starts handling requests
Date: Sat, 27 Jun 2015 02:14:17 +0900	[thread overview]
Message-ID: <1435338857.30650.6.camel@mita-ThinkPad-T540p> (raw)
In-Reply-To: <CAC5umyjOZgRz2FF0skXMuKFLMtbnMO5Hdx0pkvBUaHk2+QfAng@mail.gmail.com>

Akinobu Mita <akinobu.mita@gmail.com> wrote:
> 2015-06-26 0:40 GMT+09:00 Ming Lei <tom.leiming@gmail.com>:
> > On Thu, 25 Jun 2015 21:49:43 +0900
> > Akinobu Mita <akinobu.mita@gmail.com> wrote:
> >> For example, there is a single hw queue (hctx) and two CPU queues
> >> (ctx0 for CPU0, and ctx1 for CPU1).  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 ctx0, so the request in
> >> ctx1->rq_list is ignored.
> >
> > Per current design, the request should have been inserted into ctx0 instead
> > of ctx1 because ctx1 isn't mapped yet even though ctx1->cpu becomes ONLINE.
> >
> > So how about the following patch? which looks much simpler.
> 
> OK, I'll try this patch to see if the problem disappears.

This doesn't fix the problem.  Because:

> > diff --git a/block/blk-mq.c b/block/blk-mq.c
> > index f537796..2f45b73 100644
> > --- a/block/blk-mq.c
> > +++ b/block/blk-mq.c
> > @@ -1034,7 +1034,12 @@ void blk_mq_insert_request(struct request *rq, bool at_head, bool run_queue,
> >         struct blk_mq_ctx *ctx = rq->mq_ctx, *current_ctx;
> >
> >         current_ctx = blk_mq_get_ctx(q);
> > -       if (!cpu_online(ctx->cpu))
> > +       /*
> > +        * ctx->cpu may become ONLINE but ctx hasn't been mapped to
> > +        * hctx yet because there is a tiny race window between
> > +        * ctx->cpu ONLINE and doing the remap
> > +        */
> > +       if (!blk_mq_ctx_mapped(ctx))
> >                 rq->mq_ctx = ctx = current_ctx;

The process running on just onlined CPU1 in the above example can
satisfy this condition and current_ctx will be ctx1.  So the same
scenario can happen (the request is ignored by flush_busy_ctxs).

I found simple alternative solution that assigns the offline CPUs
unique ctx->index_hw.

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 594eea0..a8fcfbf 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1787,10 +1787,11 @@ static void blk_mq_map_swqueue(struct
request_queue *q)
 	 */
 	queue_for_each_ctx(q, ctx, i) {
 		/* If the cpu isn't online, the cpu is mapped to first hctx */
-		if (!cpu_online(i))
-			continue;
+		if (!cpu_online(i) && cpu_possible(i))
+			hctx = q->mq_ops->map_queue(q, 0);
+		else
+			hctx = q->mq_ops->map_queue(q, i);
 
-		hctx = q->mq_ops->map_queue(q, i);
 		cpumask_set_cpu(i, hctx->cpumask);
 		ctx->index_hw = hctx->nr_ctx;
 		hctx->ctxs[hctx->nr_ctx++] = ctx;
-- 




  reply	other threads:[~2015-06-26 17:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-21 13:52 [PATCH 0/4] blk-mq: fix race conditions on cpu hotplug handling Akinobu Mita
2015-06-21 13:52 ` [PATCH 1/4] blk-mq: fix sysfs registration/unregistration race Akinobu Mita
2015-06-24  8:59   ` Ming Lei
2015-06-21 13:52 ` [PATCH 2/4] blk-mq: fix q->mq_map access race Akinobu Mita
2015-06-24  9:23   ` Ming Lei
2015-06-21 13:52 ` [PATCH 3/4] blk-mq: establish new mapping before cpu starts handling requests Akinobu Mita
2015-06-24  9:46   ` Ming Lei
2015-06-24 14:34     ` Akinobu Mita
2015-06-24 16:24       ` Ming Lei
2015-06-25  2:56         ` Akinobu Mita
2015-06-25  8:07           ` Ming Lei
2015-06-25 12:49             ` Akinobu Mita
2015-06-25 15:40               ` Ming Lei
2015-06-25 23:35                 ` Akinobu Mita
2015-06-26 17:14                   ` Akinobu Mita [this message]
2015-06-27 16:08                     ` Ming Lei
2015-06-29 14:25                       ` Akinobu Mita
2015-06-30  9:06                         ` Ming Lei
2015-06-21 13:52 ` [PATCH 4/4] blk-mq: fix mq_usage_counter race when switching to percpu mode Akinobu Mita
2015-06-24 12:35   ` Ming Lei
2015-06-29 14:31     ` Akinobu Mita

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=1435338857.30650.6.camel@mita-ThinkPad-T540p \
    --to=akinobu.mita@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tom.leiming@gmail.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