Skip to content

Commit b36a205

Browse files
Dylan Yudakenaxboe
authored andcommitted
io_uring: fix bug in slow unregistering of nodes
In some cases io_rsrc_ref_quiesce will call io_rsrc_node_switch_start, and then immediately flush the delayed work queue &ctx->rsrc_put_work. However the percpu_ref_put does not immediately destroy the node, it will be called asynchronously via RCU. That ends up with io_rsrc_node_ref_zero only being called after rsrc_put_work has been flushed, and so the process ends up sleeping for 1 second unnecessarily. This patch executes the put code immediately if we are busy quiescing. Fixes: 4a38aed ("io_uring: batch reap of dead file registrations") Signed-off-by: Dylan Yudaken <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent dd81e1c commit b36a205

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/io_uring.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7822,10 +7822,15 @@ static __cold void io_rsrc_node_ref_zero(struct percpu_ref *ref)
78227822
struct io_ring_ctx *ctx = node->rsrc_data->ctx;
78237823
unsigned long flags;
78247824
bool first_add = false;
7825+
unsigned long delay = HZ;
78257826

78267827
spin_lock_irqsave(&ctx->rsrc_ref_lock, flags);
78277828
node->done = true;
78287829

7830+
/* if we are mid-quiesce then do not delay */
7831+
if (node->rsrc_data->quiesce)
7832+
delay = 0;
7833+
78297834
while (!list_empty(&ctx->rsrc_ref_list)) {
78307835
node = list_first_entry(&ctx->rsrc_ref_list,
78317836
struct io_rsrc_node, node);
@@ -7838,7 +7843,7 @@ static __cold void io_rsrc_node_ref_zero(struct percpu_ref *ref)
78387843
spin_unlock_irqrestore(&ctx->rsrc_ref_lock, flags);
78397844

78407845
if (first_add)
7841-
mod_delayed_work(system_wq, &ctx->rsrc_put_work, HZ);
7846+
mod_delayed_work(system_wq, &ctx->rsrc_put_work, delay);
78427847
}
78437848

78447849
static struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx)

0 commit comments

Comments
 (0)