public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Ming Lei <ming.lei@redhat.com>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org,
	Dongli Zhang <dongli.zhang@oracle.com>,
	James Smart <james.smart@broadcom.com>,
	Bart Van Assche <bart.vanassche@wdc.com>,
	linux-scsi@vger.kernel.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Christoph Hellwig <hch@lst.de>,
	"James E . J . Bottomley" <jejb@linux.vnet.ibm.com>,
	jianchao wang <jianchao.w.wang@oracle.com>
Subject: Re: [PATCH V4 7/7] SCSI: don't hold device refcount in IO path
Date: Thu, 04 Apr 2019 10:14:29 -0700	[thread overview]
Message-ID: <1554398069.118779.253.camel@acm.org> (raw)
In-Reply-To: <20190404084320.24681-8-ming.lei@redhat.com>

On Thu, 2019-04-04 at 16:43 +0800, Ming Lei wrote:
> scsi_device's refcount is always grabbed in IO path.
> 
> Turns out it isn't necessary, because blk_queue_cleanup() will
> drain any in-flight IOs, then cancel timeout/requeue work, and
> SCSI's requeue_work is canceled too in __scsi_remove_device().
> 
> Also scsi_device won't go away until blk_cleanup_queue() is done.
> 
> So don't hold the refcount in IO path, especially the refcount isn't
> required in IO path since blk_queue_enter() / blk_queue_exit()
> is introduced in the legacy block layer.
> 
> Cc: Dongli Zhang <dongli.zhang@oracle.com>
> Cc: James Smart <james.smart@broadcom.com>
> Cc: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: linux-scsi@vger.kernel.org,
> Cc: Martin K . Petersen <martin.petersen@oracle.com>,
> Cc: Christoph Hellwig <hch@lst.de>,
> Cc: James E . J . Bottomley <jejb@linux.vnet.ibm.com>,
> Cc: jianchao wang <jianchao.w.wang@oracle.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>  drivers/scsi/scsi_lib.c | 28 ++--------------------------
>  1 file changed, 2 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 601b9f1de267..3369d66911eb 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -141,8 +141,6 @@ scsi_set_blocked(struct scsi_cmnd *cmd, int reason)
>  
>  static void scsi_mq_requeue_cmd(struct scsi_cmnd *cmd)
>  {
> -       struct scsi_device *sdev = cmd->device;
> -
>         if (cmd->request->rq_flags & RQF_DONTPREP) {
>                 cmd->request->rq_flags &= ~RQF_DONTPREP;
>                 scsi_mq_uninit_cmd(cmd);
> @@ -150,7 +148,6 @@ static void scsi_mq_requeue_cmd(struct scsi_cmnd *cmd)
>                 WARN_ON_ONCE(true);
>         }
>         blk_mq_requeue_request(cmd->request, true);
> -       put_device(&sdev->sdev_gendev);
>  }
>  
>  /**
> @@ -189,19 +186,7 @@ static void __scsi_queue_insert(struct scsi_cmnd *cmd, int reason, bool unbusy)
>          */
>         cmd->result = 0;
>  
> -       /*
> -        * Before a SCSI command is dispatched,
> -        * get_device(&sdev->sdev_gendev) is called and the host,
> -        * target and device busy counters are increased. Since
> -        * requeuing a request causes these actions to be repeated and
> -        * since scsi_device_unbusy() has already been called,
> -        * put_device(&device->sdev_gendev) must still be called. Call
> -        * put_device() after blk_mq_requeue_request() to avoid that
> -        * removal of the SCSI device can start before requeueing has
> -        * happened.
> -        */
>         blk_mq_requeue_request(cmd->request, true);
> -       put_device(&device->sdev_gendev);
>  }
>  
>  /*
> @@ -619,7 +604,6 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
>                 blk_mq_run_hw_queues(q, true);
>  
>         percpu_ref_put(&q->q_usage_counter);
> -       put_device(&sdev->sdev_gendev);
>         return false;
>  }
>  
> @@ -1613,7 +1597,6 @@ static void scsi_mq_put_budget(struct blk_mq_hw_ctx *hctx)
>         struct scsi_device *sdev = q->queuedata;
>  
>         atomic_dec(&sdev->device_busy);
> -       put_device(&sdev->sdev_gendev);
>  }
>  
>  static bool scsi_mq_get_budget(struct blk_mq_hw_ctx *hctx)
> @@ -1621,16 +1604,9 @@ static bool scsi_mq_get_budget(struct blk_mq_hw_ctx *hctx)
>         struct request_queue *q = hctx->queue;
>         struct scsi_device *sdev = q->queuedata;
>  
> -       if (!get_device(&sdev->sdev_gendev))
> -               goto out;
> -       if (!scsi_dev_queue_ready(q, sdev))
> -               goto out_put_device;
> -
> -       return true;
> +       if (scsi_dev_queue_ready(q, sdev))
> +               return true;
>  
> -out_put_device:
> -       put_device(&sdev->sdev_gendev);
> -out:
>         if (atomic_read(&sdev->device_busy) == 0 && !scsi_device_blocked(sdev))
>                 blk_mq_delay_run_hw_queue(hctx, SCSI_QUEUE_DELAY);
>         return false;

Reviewed-by: Bart Van Assche <bvanassche@acm.org>




      reply	other threads:[~2019-04-04 17:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-04  8:43 [PATCH V4 0/7] blk-mq: fix races related with freeing queue Ming Lei
2019-04-04  8:43 ` [PATCH V4 1/7] blk-mq: grab .q_usage_counter when queuing request from plug code path Ming Lei
2019-04-04 15:58   ` Bart Van Assche
2019-04-04 20:45     ` Ming Lei
2019-04-04 21:30   ` Bart Van Assche
2019-04-05  9:26   ` Dongli Zhang
2019-04-05 13:52     ` Ming Lei
2019-04-04  8:43 ` [PATCH V4 2/7] blk-mq: move cancel of requeue_work into blk_mq_release Ming Lei
2019-04-04  8:43 ` [PATCH V4 3/7] blk-mq: quiesce queue before updating nr_hw_queues Ming Lei
2019-04-04 15:57   ` Bart Van Assche
2019-04-04 20:55     ` Ming Lei
2019-04-08  3:16   ` jianchao.wang
2019-04-08  9:01     ` Ming Lei
2019-04-04  8:43 ` [PATCH V4 4/7] blk-mq: free hw queue's resource in hctx's release handler Ming Lei
2019-04-04  8:43 ` [PATCH V4 5/7] blk-mq: move cancel of hctx->run_work into blk_mq_hw_sysfs_release Ming Lei
2019-04-04  8:43 ` [PATCH V4 6/7] block: don't drain in-progress dispatch in blk_cleanup_queue() Ming Lei
2019-04-04  8:43 ` [PATCH V4 7/7] SCSI: don't hold device refcount in IO path Ming Lei
2019-04-04 17:14   ` Bart Van Assche [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=1554398069.118779.253.camel@acm.org \
    --to=bvanassche@acm.org \
    --cc=axboe@kernel.dk \
    --cc=bart.vanassche@wdc.com \
    --cc=dongli.zhang@oracle.com \
    --cc=hch@lst.de \
    --cc=james.smart@broadcom.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=jianchao.w.wang@oracle.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=ming.lei@redhat.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