Skip to content

Commit 533ab73

Browse files
Wenwen-Chenaxboe
authored andcommitted
io_uring: unlock sqd->lock before sq thread release CPU
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<[email protected]> Signed-off-by: Wenwen Chen<[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 293007b commit 533ab73

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

io_uring/sqpoll.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,13 @@ static int io_sq_thread(void *data)
255255
sqt_spin = true;
256256

257257
if (sqt_spin || !time_after(jiffies, timeout)) {
258-
cond_resched();
259258
if (sqt_spin)
260259
timeout = jiffies + sqd->sq_thread_idle;
260+
if (unlikely(need_resched())) {
261+
mutex_unlock(&sqd->lock);
262+
cond_resched();
263+
mutex_lock(&sqd->lock);
264+
}
261265
continue;
262266
}
263267

0 commit comments

Comments
 (0)