Skip to content

Commit d7462bf

Browse files
Dylan Yudakengregkh
authored andcommitted
io_uring: fix bug in slow unregistering of nodes
[ Upstream commit b36a205 ] 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 <dylany@fb.com> Link: https://lore.kernel.org/r/20220121123856.3557884-1-dylany@fb.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6ef46e1 commit d7462bf

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎fs/io_uring.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7761,10 +7761,15 @@ static __cold void io_rsrc_node_ref_zero(struct percpu_ref *ref)
77617761
struct io_ring_ctx *ctx = node->rsrc_data->ctx;
77627762
unsigned long flags;
77637763
bool first_add = false;
7764+
unsigned long delay = HZ;
77647765

77657766
spin_lock_irqsave(&ctx->rsrc_ref_lock, flags);
77667767
node->done = true;
77677768

7769+
/* if we are mid-quiesce then do not delay */
7770+
if (node->rsrc_data->quiesce)
7771+
delay = 0;
7772+
77687773
while (!list_empty(&ctx->rsrc_ref_list)) {
77697774
node = list_first_entry(&ctx->rsrc_ref_list,
77707775
struct io_rsrc_node, node);
@@ -7777,7 +7782,7 @@ static __cold void io_rsrc_node_ref_zero(struct percpu_ref *ref)
77777782
spin_unlock_irqrestore(&ctx->rsrc_ref_lock, flags);
77787783

77797784
if (first_add)
7780-
mod_delayed_work(system_wq, &ctx->rsrc_put_work, HZ);
7785+
mod_delayed_work(system_wq, &ctx->rsrc_put_work, delay);
77817786
}
77827787

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

0 commit comments

Comments
 (0)