Re: [PATCH v1 1/2] io-wq: add exit-on-idle mode

From: Jens Axboe

Date: Mon Feb 02 2026 - 10:15:46 EST


On 2/2/26 7:37 AM, Li Chen wrote:
> diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
> index 5d0928f37471..97e7eb847c6e 100644
> --- a/io_uring/io-wq.c
> +++ b/io_uring/io-wq.c
> @@ -655,6 +656,18 @@ static int io_wq_worker(void *data)
> io_worker_handle_work(acct, worker);
>
> raw_spin_lock(&wq->lock);
> + /*
> + * If wq is marked idle-exit, drop this worker as soon as it
> + * becomes idle. This is used to avoid keeping io-wq worker
> + * threads around for tasks that no longer have any active
> + * io_uring instances.
> + */
> + if (test_bit(IO_WQ_BIT_EXIT_ON_IDLE, &wq->state)) {
> + acct->nr_workers--;
> + raw_spin_unlock(&wq->lock);
> + __set_current_state(TASK_RUNNING);
> + break;
> + }
> /*
> * Last sleep timed out. Exit if we're not the last worker,
> * or if someone modified our affinity.

One more note - just add this test_bit() to the check right below, then
you avoid duplicating all of that exit logic. They do the exact same
thing.

--
Jens Axboe