public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Lee Duncan <lduncan@suse.com>
To: Mike Christie <michael.christie@oracle.com>,
	cleech@redhat.com, martin.petersen@oracle.com,
	linux-scsi@vger.kernel.org, jejb@linux.ibm.com
Subject: Re: [PATCH 10/12] scsi: iscsi: Try to avoid taking back_lock in xmit path
Date: Fri, 18 Mar 2022 10:37:05 -0700	[thread overview]
Message-ID: <2e31342e-a8ac-3ece-98a1-9b103a0a2ec6@suse.com> (raw)
In-Reply-To: <20220308002747.122682-11-michael.christie@oracle.com>

On 3/7/22 16:27, Mike Christie wrote:
> We need the back lock when freeing a task, so we hold it when calling
> __iscsi_put_task from the completion path to make it easier and to avoid
> having to retake it in that path. For iscsi_put_task we just grabbed it
> while also doing the decrement on the refcount but it's only really needed
> if the refcount is zero and we free the task. This modifies iscsi_put_task
> to just take the lock when needed then has the xmit path use it. Normally
> we will then not take the back lock from the xmit path. It will only be
> rare cases where the network is so fast that we get a response right after
> we send the header/data.
> 
> Signed-off-by: Mike Christie <michael.christie@oracle.com>
> ---
>   drivers/scsi/libiscsi.c | 30 ++++++++++++++----------------
>   1 file changed, 14 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
> index a2d0daf5bd60..cde389225059 100644
> --- a/drivers/scsi/libiscsi.c
> +++ b/drivers/scsi/libiscsi.c
> @@ -490,6 +490,12 @@ bool iscsi_get_task(struct iscsi_task *task)
>   }
>   EXPORT_SYMBOL_GPL(iscsi_get_task);
>   
> +/**
> + * __iscsi_put_task - drop the refcount on a task
> + * @task: iscsi_task to drop the refcount on
> + *
> + * The back_lock must be held when calling in case it frees the task.
> + */
>   void __iscsi_put_task(struct iscsi_task *task)
>   {
>   	if (refcount_dec_and_test(&task->refcount))
> @@ -501,10 +507,11 @@ void iscsi_put_task(struct iscsi_task *task)
>   {
>   	struct iscsi_session *session = task->conn->session;
>   
> -	/* regular RX path uses back_lock */
> -	spin_lock_bh(&session->back_lock);
> -	__iscsi_put_task(task);
> -	spin_unlock_bh(&session->back_lock);
> +	if (refcount_dec_and_test(&task->refcount)) {
> +		spin_lock_bh(&session->back_lock);
> +		iscsi_free_task(task);
> +		spin_unlock_bh(&session->back_lock);
> +	}
>   }
>   EXPORT_SYMBOL_GPL(iscsi_put_task);
>   
> @@ -1453,8 +1460,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
>   {
>   	int rc;
>   
> -	spin_lock_bh(&conn->session->back_lock);
> -
>   	if (!conn->task) {
>   		/*
>   		 * Take a ref so we can access it after xmit_task().
> @@ -1463,7 +1468,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
>   		 * stopped the xmit thread. WARN on move on.
>   		 */
>   		if (!iscsi_get_task(task)) {
> -			spin_unlock_bh(&conn->session->back_lock);
>   			WARN_ON_ONCE(1);
>   			return 0;
>   		}
> @@ -1477,7 +1481,7 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
>   	 * case a bad target sends a cmd rsp before we have handled the task.
>   	 */
>   	if (was_requeue)
> -		__iscsi_put_task(task);
> +		iscsi_put_task(task);
>   
>   	/*
>   	 * Do this after dropping the extra ref because if this was a requeue
> @@ -1489,10 +1493,8 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
>   		 * task and get woken up again.
>   		 */
>   		conn->task = task;
> -		spin_unlock_bh(&conn->session->back_lock);
>   		return -ENODATA;
>   	}
> -	spin_unlock_bh(&conn->session->back_lock);
>   
>   	spin_unlock_bh(&conn->session->frwd_lock);
>   	rc = conn->session->tt->xmit_task(task);
> @@ -1500,10 +1502,7 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
>   	if (!rc) {
>   		/* done with this task */
>   		task->last_xfer = jiffies;
> -	}
> -	/* regular RX path uses back_lock */
> -	spin_lock(&conn->session->back_lock);
> -	if (rc) {
> +	} else {
>   		/*
>   		 * get an extra ref that is released next time we access it
>   		 * as conn->task above.
> @@ -1512,8 +1511,7 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
>   		conn->task = task;
>   	}
>   
> -	__iscsi_put_task(task);
> -	spin_unlock(&conn->session->back_lock);
> +	iscsi_put_task(task);
>   	return rc;
>   }
>   

Reviewed-by: Lee Duncan <lduncan@suse.com>


  reply	other threads:[~2022-03-18 17:37 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08  0:27 [[PATCH 00/12] misc iscsi patches Mike Christie
2022-03-08  0:27 ` [PATCH 01/12] scsi: iscsi: Merge suspend fields Mike Christie
2022-03-08 18:47   ` Lee Duncan
2022-03-08  0:27 ` [PATCH 02/12] scsi: iscsi: Rename iscsi_conn_queue_work Mike Christie
2022-03-08 18:49   ` Lee Duncan
2022-03-09  0:55   ` Wu Bo
2022-03-08  0:27 ` [PATCH 03/12] scsi: iscsi: Add recv workqueue helpers Mike Christie
2022-03-10 22:50   ` Lee Duncan
2022-03-08  0:27 ` [PATCH 04/12] scsi: iscsi: Allow a recv and xmit work to run Mike Christie
2022-03-08 19:00   ` Lee Duncan
2022-03-08  0:27 ` [PATCH 05/12] scsi: iscsi: Run recv path from workqueue Mike Christie
2022-03-18 16:45   ` Lee Duncan
2022-03-18 22:11     ` Mike Christie
2022-03-08  0:27 ` [PATCH 06/12] scsi: iscsi_tcp: Use sendpage for the PDU header Mike Christie
2022-03-12 19:42   ` Lee Duncan
2022-03-08  0:27 ` [PATCH 07/12] scsi: iscsi_tcp: Drop target_alloc use Mike Christie
2022-03-09  1:31   ` Wu Bo
2022-03-12 19:43   ` Lee Duncan
2022-03-08  0:27 ` [PATCH 08/12] scsi: iscsi: remove unneeded task state check Mike Christie
2022-03-09  1:33   ` Wu Bo
2022-03-14 17:13   ` Lee Duncan
2022-03-08  0:27 ` [PATCH 09/12] scsi: iscsi: Remove iscsi_get_task back_lock requirement Mike Christie
2022-03-14 17:44   ` Lee Duncan
2022-03-18 17:31   ` Lee Duncan
2022-03-08  0:27 ` [PATCH 10/12] scsi: iscsi: Try to avoid taking back_lock in xmit path Mike Christie
2022-03-18 17:37   ` Lee Duncan [this message]
2022-03-08  0:27 ` [PATCH 11/12] scsi: libiscsi: improve conn_send_pdu API Mike Christie
2022-03-18 16:49   ` Lee Duncan
2022-03-08  0:27 ` [PATCH 12/12] scsi: iscsi: Fix race between recovery and task xmit Mike Christie
2022-03-14 17:46   ` Lee Duncan

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=2e31342e-a8ac-3ece-98a1-9b103a0a2ec6@suse.com \
    --to=lduncan@suse.com \
    --cc=cleech@redhat.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michael.christie@oracle.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