[PATCH] driver: block: release the lo_work_lock before queue_work

zhaoyang.huang posted 1 patch 1 year ago
drivers/block/loop.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] driver: block: release the lo_work_lock before queue_work
Posted by zhaoyang.huang 1 year ago
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

queue_work could spin on wq->cpu_pwq->pool->lock which could lead to
concurrent loop_process_work failed on lo_work_lock contention and
increase the request latency. Remove this combination by moving the
lock release ahead of queue_work.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 drivers/block/loop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 8f6761c27c68..33e31cd95953 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -890,8 +890,8 @@ static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd)
 		cmd_list = &lo->rootcg_cmd_list;
 	}
 	list_add_tail(&cmd->list_entry, cmd_list);
-	queue_work(lo->workqueue, work);
 	spin_unlock_irq(&lo->lo_work_lock);
+	queue_work(lo->workqueue, work);
 }
 
 static void loop_set_timer(struct loop_device *lo)
-- 
2.25.1
Re: [PATCH] driver: block: release the lo_work_lock before queue_work
Posted by Ming Lei 12 months ago
On Fri, Feb 7, 2025 at 5:20 PM zhaoyang.huang <zhaoyang.huang@unisoc.com> wrote:
>
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>
> queue_work could spin on wq->cpu_pwq->pool->lock which could lead to
> concurrent loop_process_work failed on lo_work_lock contention and
> increase the request latency. Remove this combination by moving the
> lock release ahead of queue_work.
>
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  drivers/block/loop.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 8f6761c27c68..33e31cd95953 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -890,8 +890,8 @@ static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd)
>                 cmd_list = &lo->rootcg_cmd_list;
>         }
>         list_add_tail(&cmd->list_entry, cmd_list);
> -       queue_work(lo->workqueue, work);
>         spin_unlock_irq(&lo->lo_work_lock);
> +       queue_work(lo->workqueue, work);
>  }

Reviewed-by: Ming Lei <ming.lei@redhat.com>
Re: [PATCH] driver: block: release the lo_work_lock before queue_work
Posted by Jens Axboe 12 months ago
On Fri, 07 Feb 2025 17:19:42 +0800, zhaoyang.huang wrote:
> queue_work could spin on wq->cpu_pwq->pool->lock which could lead to
> concurrent loop_process_work failed on lo_work_lock contention and
> increase the request latency. Remove this combination by moving the
> lock release ahead of queue_work.
> 
> 

Applied, thanks!

[1/1] driver: block: release the lo_work_lock before queue_work
      commit: 3bee991f2b68175c828dc3f9c26367fe1827319a

Best regards,
-- 
Jens Axboe