The sq thread actively releases CPU resources by calling the cond_resched() and schedule() interfaces when it is idle. Therefore, more resources are available for other threads to run. There exists a problem in sq thread: it does not unlock sqd->lock before releasing CPU resources every time. This makes other threads pending on sqd->lock for a long time. For example, the following interfaces all require sqd->lock: io_sq_offload_create(), io_register_iowq_max_workers() and io_ring_exit_work(). Before the sq thread releases CPU resources, unlocking sqd->lock will provide the user a better experience because it can respond quickly to user requests. Signed-off-by: Kanchan Joshi<joshi.k@xxxxxxxxxxx> Signed-off-by: Wenwen Chen<wenwen.chen@xxxxxxxxxxx> --- io_uring/sqpoll.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index 9db4bc1f521a..759c80fb4afa 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -255,7 +255,9 @@ static int io_sq_thread(void *data) sqt_spin = true; if (sqt_spin || !time_after(jiffies, timeout)) { + mutex_unlock(&sqd->lock); cond_resched(); + mutex_lock(&sqd->lock); if (sqt_spin) timeout = jiffies + sqd->sq_thread_idle; continue;