scsi: iscsi: Try to avoid taking back_lock in xmit path

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.

Link: https://lore.kernel.org/r/20220616224557.115234-9-michael.christie@oracle.com
Reviewed-by: Lee Duncan <lduncan@suse.com>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Mike Christie 2022-06-16 17:45:56 -05:00 committed by Martin K. Petersen
parent e1c6a7ec14
commit 6d626150d6

View File

@ -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);
@ -1454,8 +1461,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().
@ -1464,7 +1469,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
* stopped the xmit thread.
*/
if (!iscsi_get_task(task)) {
spin_unlock_bh(&conn->session->back_lock);
WARN_ON_ONCE(1);
return 0;
}
@ -1478,7 +1482,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
@ -1490,10 +1494,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);
@ -1501,10 +1503,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.
@ -1513,8 +1512,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;
}