All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: John Garry <john.garry@huawei.com>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, kashyap.desai@broadcom.com,
	hare@suse.de
Subject: Re: [PATCH] blk-mq: Fix blk_mq_tagset_busy_iter() for shared tags
Date: Wed, 13 Oct 2021 18:20:46 +0800	[thread overview]
Message-ID: <YWay/n+BJTLm1Alb@T590> (raw)
In-Reply-To: <79266509-f327-9de3-d22e-0e9fe00387ee@huawei.com>

On Wed, Oct 13, 2021 at 11:01:11AM +0100, John Garry wrote:
> On 13/10/2021 10:22, Ming Lei wrote:
> > On Wed, Oct 13, 2021 at 04:40:59PM +0800, John Garry wrote:
> > > Since it is now possible for a tagset to share a single set of tags, the
> > > iter function should not re-iter the tags for the count of #hw queues in
> > > that case. Rather it should just iter once.
> > > 
> > > Fixes: e0fdf846c7bb ("blk-mq: Use shared tags for shared sbitmap support")
> > > Reported-by: Kashyap Desai<kashyap.desai@broadcom.com>
> > > Signed-off-by: John Garry<john.garry@huawei.com>
> > > 
> > > diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
> > > index 72a2724a4eee..c943b6529619 100644
> > > --- a/block/blk-mq-tag.c
> > > +++ b/block/blk-mq-tag.c
> > > @@ -378,9 +378,12 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
> > >   void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
> > >   		busy_tag_iter_fn *fn, void *priv)
> > >   {
> > > -	int i;
> > > +	unsigned int flags = tagset->flags;
> > > +	int i, nr_tags;
> > > +
> > > +	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
> > > -	for (i = 0; i < tagset->nr_hw_queues; i++) {
> > > +	for (i = 0; i < nr_tags; i++) {
> > >   		if (tagset->tags && tagset->tags[i])
> > >   			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
> > >   					      BT_TAG_ITER_STARTED);
> > blk_mq_queue_tag_busy_iter() needn't such change?
> 
> I didn't think so.
> 
> blk_mq_queue_tag_busy_iter() will indeed re-iter the tags per hctx. However
> in bt_iter(), we check rq->mq_hctx == hctx for calling the iter callback:
> 
> static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
> {
> 	...
> 
> 	if (rq->q == hctx->queue && rq->mq_hctx == hctx)
> 		ret = iter_data->fn(hctx, rq, iter_data->data, reserved);
> 
> And this would only pass for the correct hctx which we're iter'ing for.

It is true for both shared and non-shared sbitmap since we don't share
hctx, so what does matter? With single shared tags, you can iterate over
all requests originated from all hw queues, right?

> Indeed, it would be nice not to iter excessive times, but I didn't see a
> straightforward way to change that.

In Kashyap's report, the lock contention is actually from
blk_mq_queue_tag_busy_iter(), see:

https://lore.kernel.org/linux-block/8867352d-2107-1f8a-0f1c-ef73450bf256@huawei.com/

> 
> There is also blk_mq_all_tag_iter():
> 
> void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
> 		void *priv)
> {
> 	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
> }
> 
> But then the only user is blk_mq_hctx_has_requests():
> 
> static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)
> {
> 	struct blk_mq_tags *tags = hctx->sched_tags ?
> 			hctx->sched_tags : hctx->tags;
> 	struct rq_iter_data data = {
> 		.hctx	= hctx,
> 	};
> 
> 	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
> 	return data.has_rq;
> }

This above one only iterates over the specified hctx/tags, it won't be
affected.

> 
> But, again like bt_iter(), blk_mq_has_request() will check the hctx matches:

Not see what matters wrt. checking hctx.



Thanks,
Ming


  reply	other threads:[~2021-10-13 10:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-13  8:40 [PATCH] blk-mq: Fix blk_mq_tagset_busy_iter() for shared tags John Garry
2021-10-13  9:22 ` Ming Lei
2021-10-13 10:01   ` John Garry
2021-10-13 10:20     ` Ming Lei [this message]
2021-10-13 11:11       ` John Garry
2021-10-13 14:29         ` Ming Lei
2021-10-13 15:13           ` John Garry
2021-10-18  8:08             ` John Garry
2021-10-18  9:07               ` Ming Lei
2021-10-18  9:33                 ` John Garry

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=YWay/n+BJTLm1Alb@T590 \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=john.garry@huawei.com \
    --cc=kashyap.desai@broadcom.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.