Skip to content

Commit 9121466

Browse files
FirstLoveLifeaxboe
authored andcommitted
io_uring: allow io-wq workers to exit when unused
io_uring keeps a per-task io-wq around, even when the task no longer has any io_uring instances. If the task previously used io_uring for file I/O, this can leave an unrelated iou-wrk-* worker thread behind after the last io_uring instance is gone. When the last io_uring ctx is removed from the task context, mark the io-wq exit-on-idle so workers can go away. Clear the flag on subsequent io_uring usage. Signed-off-by: Li Chen <me@linux.beauty> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 38aa434 commit 9121466

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

io_uring/tctx.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx)
122122
return ret;
123123
}
124124
}
125+
126+
/*
127+
* Re-activate io-wq keepalive on any new io_uring usage. The wq may have
128+
* been marked for idle-exit when the task temporarily had no active
129+
* io_uring instances.
130+
*/
131+
if (tctx->io_wq)
132+
io_wq_set_exit_on_idle(tctx->io_wq, false);
125133
if (!xa_load(&tctx->xa, (unsigned long)ctx)) {
126134
node = kmalloc(sizeof(*node), GFP_KERNEL);
127135
if (!node)
@@ -183,6 +191,9 @@ __cold void io_uring_del_tctx_node(unsigned long index)
183191
if (tctx->last == node->ctx)
184192
tctx->last = NULL;
185193
kfree(node);
194+
195+
if (xa_empty(&tctx->xa) && tctx->io_wq)
196+
io_wq_set_exit_on_idle(tctx->io_wq, true);
186197
}
187198

188199
__cold void io_uring_clean_tctx(struct io_uring_task *tctx)

0 commit comments

Comments
 (0)