public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Hannes Reinecke <hare@suse.de>
Cc: "Ewan D. Milne" <emilne@redhat.com>,
	linux-nvme@lists.infradead.org, tsong@purestorage.com,
	jmeneghi@redhat.com, mlombard@redhat.com, ming.lei@redhat.com
Subject: Re: [PATCH 1/3] block: introduce blk_queue_nr_active()
Date: Wed, 27 Sep 2023 19:37:17 +0800	[thread overview]
Message-ID: <ZRQT7aaSKBRChzSV@fedora> (raw)
In-Reply-To: <c63ee412-3f34-49c7-b873-16b37683dc90@suse.de>

On Wed, Sep 27, 2023 at 09:36:11AM +0200, Hannes Reinecke wrote:
> On 9/25/23 18:31, Ewan D. Milne wrote:
> > Returns a count of the total number of active requests
> > in a queue.  For non-shared tags (the usual case) this is
> > the sum of nr_active from all of the hctxs.
> > 
> Bit of an exaggeration here.
> Shared tags are in use if the hardware supports only a global tag space
> (ie basically all SCSI and FC HBAs).
> 
> > Signed-off-by: Ewan D. Milne <emilne@redhat.com>
> > ---
> >   block/blk-mq.h         |  5 -----
> >   include/linux/blk-mq.h | 33 ++++++++++++++++++++++++++-------
> >   2 files changed, 26 insertions(+), 12 deletions(-)
> > 
> > diff --git a/block/blk-mq.h b/block/blk-mq.h
> > index 1743857e0b01..fbc65eefa017 100644
> > --- a/block/blk-mq.h
> > +++ b/block/blk-mq.h
> > @@ -214,11 +214,6 @@ static inline bool blk_mq_tag_is_reserved(struct blk_mq_tags *tags,
> >   	return tag < tags->nr_reserved_tags;
> >   }
> > -static inline bool blk_mq_is_shared_tags(unsigned int flags)
> > -{
> > -	return flags & BLK_MQ_F_TAG_HCTX_SHARED;
> > -}
> > -
> >   static inline struct blk_mq_tags *blk_mq_tags_from_data(struct blk_mq_alloc_data *data)
> >   {
> >   	if (data->rq_flags & RQF_SCHED_TAGS)
> > diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
> > index 01e8c31db665..c921ae5236ab 100644
> > --- a/include/linux/blk-mq.h
> > +++ b/include/linux/blk-mq.h
> > @@ -716,6 +716,32 @@ int blk_rq_poll(struct request *rq, struct io_comp_batch *iob,
> >   bool blk_mq_queue_inflight(struct request_queue *q);
> > +#define queue_for_each_hw_ctx(q, hctx, i)				\
> > +	xa_for_each(&(q)->hctx_table, (i), (hctx))
> > +
> > +#define hctx_for_each_ctx(hctx, ctx, i)					\
> > +	for ((i) = 0; (i) < (hctx)->nr_ctx &&				\
> > +	     ({ ctx = (hctx)->ctxs[(i)]; 1; }); (i)++)
> > +
> > +static inline bool blk_mq_is_shared_tags(unsigned int flags)
> > +{
> > +	return flags & BLK_MQ_F_TAG_HCTX_SHARED;
> > +}
> > +
> > +static inline unsigned int blk_mq_queue_nr_active(struct request_queue *q)
> > +{
> > +	unsigned int nr_active = 0;
> > +	struct blk_mq_hw_ctx *hctx;
> > +	unsigned long i;
> > +
> > +	queue_for_each_hw_ctx(q, hctx, i) {
> > +		if (unlikely(blk_mq_is_shared_tags(hctx->flags)))
> > +			return atomic_read(&q->nr_active_requests_shared_tags);
> > +		nr_active += atomic_read(&hctx->nr_active);
> > +	}
> > +	return nr_active;
> > +}
> > +
> >   enum {
> >   	/* return when out of requests */
> >   	BLK_MQ_REQ_NOWAIT	= (__force blk_mq_req_flags_t)(1 << 0),
> > @@ -941,13 +967,6 @@ static inline void *blk_mq_rq_to_pdu(struct request *rq)
> >   	return rq + 1;
> >   }
> > -#define queue_for_each_hw_ctx(q, hctx, i)				\
> > -	xa_for_each(&(q)->hctx_table, (i), (hctx))
> > -
> > -#define hctx_for_each_ctx(hctx, ctx, i)					\
> > -	for ((i) = 0; (i) < (hctx)->nr_ctx &&				\
> > -	     ({ ctx = (hctx)->ctxs[(i)]; 1; }); (i)++)
> > -
> >   static inline void blk_mq_cleanup_rq(struct request *rq)
> >   {
> >   	if (rq->q->mq_ops->cleanup_rq)
> 
> Well. As discussed, using xarray on 'small' arrays is horrible for
> performance. We really should revert the patch from Ming to
> turn it back into a simple array; that'll make traversing much faster.

But queue_for_each_hw_ctx() isn't supposed for fast path, and it is always
expensive to run cross-queue things.

It also means any way running cross-queue thing in fast path may not be
one good idea.

Thanks,
Ming



  reply	other threads:[~2023-09-27 11:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25 16:31 [PATCH 0/3] NVMe multipath path selector enhancements Ewan D. Milne
2023-09-25 16:31 ` [PATCH 1/3] block: introduce blk_queue_nr_active() Ewan D. Milne
2023-09-25 20:56   ` Bart Van Assche
2023-09-27 14:49     ` Ewan Milne
2023-09-27 14:58       ` Bart Van Assche
2023-09-27  7:36   ` Hannes Reinecke
2023-09-27 11:37     ` Ming Lei [this message]
2023-09-27 13:34     ` Ewan Milne
2023-10-03 20:11       ` Uday Shankar
2023-10-04  9:19         ` Sagi Grimberg
2023-09-27  9:49   ` Ming Lei
2023-09-27 13:54     ` Ewan Milne
2023-09-27 10:56   ` Sagi Grimberg
2023-09-27 13:50     ` Ewan Milne
2023-09-28 10:56       ` Sagi Grimberg
2023-09-25 16:31 ` [PATCH 2/3] nvme-multipath: Implement new iopolicy "queue-depth" Ewan D. Milne
2023-09-27  7:38   ` Hannes Reinecke
2023-09-27 11:02     ` Sagi Grimberg
2023-09-27 13:42     ` Ewan Milne
2023-09-25 16:31 ` [PATCH 3/3] nvme-multipath: add "use_nonoptimized" module option Ewan D. Milne
2023-09-27  7:41   ` Hannes Reinecke
2023-09-27 11:31     ` Sagi Grimberg
2023-09-27 13:11       ` John Meneghini
2023-09-27 13:45     ` Ewan Milne

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=ZRQT7aaSKBRChzSV@fedora \
    --to=ming.lei@redhat.com \
    --cc=emilne@redhat.com \
    --cc=hare@suse.de \
    --cc=jmeneghi@redhat.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mlombard@redhat.com \
    --cc=tsong@purestorage.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