public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: linux-scsi@vger.kernel.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Jens Axboe <axboe@kernel.dk>,
	"Ewan D . Milne" <emilne@redhat.com>,
	Omar Sandoval <osandov@fb.com>, Christoph Hellwig <hch@lst.de>,
	Kashyap Desai <kashyap.desai@broadcom.com>,
	Hannes Reinecke <hare@suse.de>,
	Laurence Oberman <loberman@redhat.com>,
	Bart Van Assche <bart.vanassche@wdc.com>
Subject: Re: [PATCH V2] scsi: core: avoid host-wide host_busy counter for scsi_mq
Date: Tue, 8 Oct 2019 12:07:08 +0800	[thread overview]
Message-ID: <20191008040707.GD5556@ming.t460p> (raw)
In-Reply-To: <ae46a16c-3289-dc5c-9e7d-570d4b1de8e0@acm.org>

On Mon, Oct 07, 2019 at 08:20:20PM -0700, Bart Van Assche wrote:
> On 2019-10-06 00:44, Ming Lei wrote:
> > +struct scsi_host_mq_in_flight {
> > +	int cnt;
> > +};
> 
> Is this structure useful? Have you considered to use the 'int' datatype
> directly and to leave out struct scsi_host_mq_in_flight?

OK, will switch to 'int' in V2.

> 
> >  /**
> >   * scsi_host_busy - Return the host busy counter
> >   * @shost:	Pointer to Scsi_Host to inc.
> >   **/
> >  int scsi_host_busy(struct Scsi_Host *shost)
> >  {
> > -	return atomic_read(&shost->host_busy);
> > +	struct scsi_host_mq_in_flight in_flight = {
> > +		.cnt = 0,
> > +	};
> 
> In case struct scsi_host_mq_in_flight would be retained, have you
> considered to use "{ }" to initialize "in_flight"?
> 
> > -static void scsi_dec_host_busy(struct Scsi_Host *shost)
> > +static void scsi_dec_host_busy(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
> >  {
> >  	unsigned long flags;
> >  
> >  	rcu_read_lock();
> > -	atomic_dec(&shost->host_busy);
> > +	clear_bit(SCMD_STATE_INFLIGHT, &cmd->state);
> 
> If a new state variable would be introduced for SCSI commands, would it
> be possible to use non-atomic operations to set and clear
> SCMD_STATE_INFLIGHT? In other words, are any of the functions that
> modify this bit ever called concurrently?

scsi_host_queue_ready() is always called before calling
host->hostt->queuecommand(scmd), and scsi_dec_host_busy() is called
after calling into host->hostt->queuecommand(scmd) in non-failure path.

So the answer is no, they won't be called concurrently, even they won't
be called concurrently with test_and_set_bit(SCMD_STATE_COMPLETE, &cmd->state)
in scsi_mq_done(), which can avoid to re-order between setting SCMD_STATE_INFLIGHT
and clearing SCMD_STATE_INFLIGHT.

The only exception is that clear_bit(SCMD_STATE_COMPLETE) may be run
concurrently with clear_bit(SCMD_STATE_INFLIGHT) because .complete() may
be called in another CPU remotely, but that only happens in case of
blk_should_fake_timeout().

So looks it is safe to change to non-atomic __set_bit() and
__clear__bit().

Thanks,
Ming

      reply	other threads:[~2019-10-08  4:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-06  7:44 [PATCH V2] scsi: core: avoid host-wide host_busy counter for scsi_mq Ming Lei
2019-10-08  3:20 ` Bart Van Assche
2019-10-08  4:07   ` Ming Lei [this message]

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=20191008040707.GD5556@ming.t460p \
    --to=ming.lei@redhat.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=axboe@kernel.dk \
    --cc=bart.vanassche@wdc.com \
    --cc=bvanassche@acm.org \
    --cc=emilne@redhat.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kashyap.desai@broadcom.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=loberman@redhat.com \
    --cc=martin.petersen@oracle.com \
    --cc=osandov@fb.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