Re: [PATCH V2] scsi: core: avoid host-wide host_busy counter for scsi_mq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux