linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Will Deacon <will@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, John Garry <john.garry@huawei.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Hannes Reinecke <hare@suse.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	paulmck@kernel.org
Subject: Re: [PATCH V8 07/11] blk-mq: stop to handle IO and drain IO before hctx becomes inactive
Date: Thu, 30 Apr 2020 08:39:45 +0800	[thread overview]
Message-ID: <20200430003945.GA719313@T590> (raw)
In-Reply-To: <20200429173400.GC30247@willie-the-truck>

On Wed, Apr 29, 2020 at 06:34:01PM +0100, Will Deacon wrote:
> On Wed, Apr 29, 2020 at 09:43:27PM +0800, Ming Lei wrote:
> > On Wed, Apr 29, 2020 at 01:27:57PM +0100, Will Deacon wrote:
> > > On Wed, Apr 29, 2020 at 05:46:16PM +0800, Ming Lei wrote:
> > > > On Wed, Apr 29, 2020 at 09:07:29AM +0100, Will Deacon wrote:
> > > > > On Wed, Apr 29, 2020 at 10:16:12AM +0800, Ming Lei wrote:
> > > > > > On Tue, Apr 28, 2020 at 05:58:37PM +0200, Peter Zijlstra wrote:
> > > > > > > On Sat, Apr 25, 2020 at 05:48:32PM +0200, Christoph Hellwig wrote:
> > > > > > > >  		atomic_inc(&data.hctx->nr_active);
> > > > > > > >  	}
> > > > > > > >  	data.hctx->tags->rqs[rq->tag] = rq;
> > > > > > > >  
> > > > > > > >  	/*
> > > > > > > > +	 * Ensure updates to rq->tag and tags->rqs[] are seen by
> > > > > > > > +	 * blk_mq_tags_inflight_rqs.  This pairs with the smp_mb__after_atomic
> > > > > > > > +	 * in blk_mq_hctx_notify_offline.  This only matters in case a process
> > > > > > > > +	 * gets migrated to another CPU that is not mapped to this hctx.
> > > > > > > >  	 */
> > > > > > > > +	if (rq->mq_ctx->cpu != get_cpu())
> > > > > > > >  		smp_mb();
> > > > > > > > +	put_cpu();
> > > > > > > 
> > > > > > > This looks exceedingly weird; how do you think you can get to another
> > > > > > > CPU and not have an smp_mb() implied in the migration itself? Also, what
> > > > > > 
> > > > > > What we need is one smp_mb() between the following two OPs:
> > > > > > 
> > > > > > 1) 
> > > > > >    rq->tag = rq->internal_tag;
> > > > > >    data.hctx->tags->rqs[rq->tag] = rq;
> > > > > > 
> > > > > > 2) 
> > > > > > 	if (unlikely(test_bit(BLK_MQ_S_INACTIVE, &rq->mq_hctx->state)))
> > > > > > 
> > > > > > And the pair of the above barrier is in blk_mq_hctx_notify_offline().
> > > > > 
> > > > > I'm struggling with this, so let me explain why. My understanding of the
> > > > > original patch [1] and your explanation above is that you want *either* of
> > > > > the following behaviours
> > > > > 
> > > > >   - __blk_mq_get_driver_tag() (i.e. (1) above) and test_bit(BLK_MQ_S_INACTIVE, ...)
> > > > >     run on the same CPU with barrier() between them, or
> > > > > 
> > > > >   - There is a migration and therefore an implied smp_mb() between them
> > > > > 
> > > > > However, given that most CPUs can speculate loads (and therefore the
> > > > > test_bit() operation), I don't understand how the "everything runs on the
> > > > > same CPU" is safe if a barrier() is required.  In other words, if the
> > > > > barrier() is needed to prevent the compiler hoisting the load, then the CPU
> > > > > can still cause problems.
> > > > 
> > > > Do you think the speculate loads may return wrong value of
> > > > BLK_MQ_S_INACTIVE bit in case of single CPU? BTW, writing the bit is
> > > > done on the same CPU. If yes, this machine may not obey cache consistency,
> > > > IMO.
> > > 
> > > If the write is on the same CPU, then the read will of course return the
> > > value written by that write, otherwise we'd have much bigger problems!
> > 
> > OK, then it is nothing to with speculate loads.
> > 
> > > 
> > > But then I'm confused, because you're saying that the write is done on the
> > > same CPU, but previously you were saying that migration occuring before (1)
> > > was problematic. Can you explain a bit more about that case, please? What
> > > is running before (1) that is relevant here?
> > 
> > Please see the following two code paths:
> > 
> > [1] code path1:
> > blk_mq_hctx_notify_offline():
> > 	set_bit(BLK_MQ_S_INACTIVE, &hctx->state);
> > 
> > 	smp_mb() or smp_mb_after_atomic()
> > 
> > 	blk_mq_hctx_drain_inflight_rqs():
> > 		blk_mq_tags_inflight_rqs()
> > 			rq = hctx->tags->rqs[index]
> > 			and
> > 			READ rq->tag
> > 
> > [2] code path2:
> > 	blk_mq_get_driver_tag():
> > 
> > 		process might be migrated to other CPU here and chance is small,
> > 		then the follow code will be run on CPU different with code path1
> > 
> > 		rq->tag = rq->internal_tag;
> > 		hctx->tags->rqs[rq->tag] = rq;
> 
> I /think/ this can be distilled to the SB litmus test:
> 
> 	// blk_mq_hctx_notify_offline()		blk_mq_get_driver_tag();
> 	Wstate = INACTIVE			Wtag
> 	smp_mb()				smp_mb()
> 	Rtag					Rstate
> 
> and you want to make sure that either blk_mq_get_driver_tag() sees the
> state as INACTIVE and does the cleanup, or it doesn't and
> blk_mq_hctx_notify_offline() sees the newly written tag and waits for the
> request to complete (I don't get how that happens, but hey).
> 
> Is that right?

Yeah, exactly.

> 
> > 		barrier() in case that code path2 is run on same CPU with code path1
> > 		OR
> > 		smp_mb() in case that code path2 is run on different CPU with code path1 because
> > 		of process migration
> > 		
> > 		test_bit(BLK_MQ_S_INACTIVE, &data.hctx->state)
> 
> Couldn't you just check this at the start of blk_mq_get_driver_tag() as
> well, and then make the smp_mb() unconditional?

As I mentioned, the chance for the current process(calling
blk_mq_get_driver_tag()) migration is very small, we do want to
avoid the extra smp_mb() in the fast path.

Thanks,
Ming


  reply	other threads:[~2020-04-30  0:40 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24 10:23 [PATCH V8 00/11] blk-mq: improvement CPU hotplug Ming Lei
2020-04-24 10:23 ` [PATCH V8 01/11] block: clone nr_integrity_segments and write_hint in blk_rq_prep_clone Ming Lei
2020-04-24 10:32   ` Christoph Hellwig
2020-04-24 12:43   ` Hannes Reinecke
2020-04-24 16:11   ` Martin K. Petersen
2020-04-24 10:23 ` [PATCH V8 02/11] block: add helper for copying request Ming Lei
2020-04-24 10:35   ` Christoph Hellwig
2020-04-24 12:43   ` Hannes Reinecke
2020-04-24 16:12   ` Martin K. Petersen
2020-04-24 10:23 ` [PATCH V8 03/11] blk-mq: mark blk_mq_get_driver_tag as static Ming Lei
2020-04-24 12:44   ` Hannes Reinecke
2020-04-24 16:13   ` Martin K. Petersen
2020-04-24 10:23 ` [PATCH V8 04/11] blk-mq: assign rq->tag in blk_mq_get_driver_tag Ming Lei
2020-04-24 10:35   ` Christoph Hellwig
2020-04-24 13:02   ` Hannes Reinecke
2020-04-25  2:54     ` Ming Lei
2020-04-25 18:26       ` Hannes Reinecke
2020-04-24 10:23 ` [PATCH V8 05/11] blk-mq: support rq filter callback when iterating rqs Ming Lei
2020-04-24 13:17   ` Hannes Reinecke
2020-04-25  3:04     ` Ming Lei
2020-04-24 10:23 ` [PATCH V8 06/11] blk-mq: prepare for draining IO when hctx's all CPUs are offline Ming Lei
2020-04-24 13:23   ` Hannes Reinecke
2020-04-25  3:24     ` Ming Lei
2020-04-24 10:23 ` [PATCH V8 07/11] blk-mq: stop to handle IO and drain IO before hctx becomes inactive Ming Lei
2020-04-24 10:38   ` Christoph Hellwig
2020-04-25  3:17     ` Ming Lei
2020-04-25  8:32       ` Christoph Hellwig
2020-04-25  9:34         ` Ming Lei
2020-04-25  9:53           ` Ming Lei
2020-04-25 15:48             ` Christoph Hellwig
2020-04-26  2:06               ` Ming Lei
2020-04-26  8:19                 ` John Garry
2020-04-27 15:36                 ` Christoph Hellwig
2020-04-28  1:10                   ` Ming Lei
2020-04-27 19:03               ` Paul E. McKenney
2020-04-28  6:54                 ` Christoph Hellwig
2020-04-28 15:58               ` Peter Zijlstra
2020-04-29  2:16                 ` Ming Lei
2020-04-29  8:07                   ` Will Deacon
2020-04-29  9:46                     ` Ming Lei
2020-04-29 12:27                       ` Will Deacon
2020-04-29 13:43                         ` Ming Lei
2020-04-29 17:34                           ` Will Deacon
2020-04-30  0:39                             ` Ming Lei [this message]
2020-04-30 11:04                               ` Will Deacon
2020-04-30 14:02                                 ` Ming Lei
2020-05-05 15:46                                   ` Christoph Hellwig
2020-05-06  1:24                                     ` Ming Lei
2020-05-06  7:28                                       ` Will Deacon
2020-05-06  8:07                                         ` Ming Lei
2020-05-06  9:56                                           ` Will Deacon
2020-05-06 10:22                                             ` Ming Lei
2020-04-29 17:46                           ` Paul E. McKenney
2020-04-30  0:43                             ` Ming Lei
2020-04-24 13:27   ` Hannes Reinecke
2020-04-25  3:30     ` Ming Lei
2020-04-24 13:42   ` John Garry
2020-04-25  3:41     ` Ming Lei
2020-04-24 10:23 ` [PATCH V8 08/11] block: add blk_end_flush_machinery Ming Lei
2020-04-24 10:41   ` Christoph Hellwig
2020-04-25  3:44     ` Ming Lei
2020-04-25  8:11       ` Christoph Hellwig
2020-04-25  9:51         ` Ming Lei
2020-04-24 13:47   ` Hannes Reinecke
2020-04-25  3:47     ` Ming Lei
2020-04-24 10:23 ` [PATCH V8 09/11] blk-mq: add blk_mq_hctx_handle_dead_cpu for handling cpu dead Ming Lei
2020-04-24 10:42   ` Christoph Hellwig
2020-04-25  3:48     ` Ming Lei
2020-04-24 13:48   ` Hannes Reinecke
2020-04-24 10:23 ` [PATCH V8 10/11] blk-mq: re-submit IO in case that hctx is inactive Ming Lei
2020-04-24 10:44   ` Christoph Hellwig
2020-04-25  3:52     ` Ming Lei
2020-04-24 13:55   ` Hannes Reinecke
2020-04-25  3:59     ` Ming Lei
2020-04-24 10:23 ` [PATCH V8 11/11] block: deactivate hctx when the hctx is actually inactive Ming Lei
2020-04-24 10:43   ` Christoph Hellwig
2020-04-24 13:56   ` Hannes Reinecke
2020-04-24 15:23 ` [PATCH V8 00/11] blk-mq: improvement CPU hotplug Jens Axboe
2020-04-24 15:40   ` Christoph Hellwig
2020-04-24 15:41     ` Jens Axboe

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=20200430003945.GA719313@T590 \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=john.garry@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).