From: Yuanhe Shu <xiangzao@linux.alibaba.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Pavel Begunkov <asml.silence@gmail.com>,
io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
xiangzao@linux.alibaba.com
Subject: [PATCH 1/2] io_uring: add a schedule point in io_free_batch_list()
Date: Tue, 20 Oct 2026 14:44:51 +0800 [thread overview]
Message-ID: <20261020064452.3633250-2-xiangzao@linux.alibaba.com> (raw)
In-Reply-To: <20261020064452.3633250-1-xiangzao@linux.alibaba.com>
Completed requests accumulate in submit_state.compl_reqs - deferred
completions queued by task_work handlers via io_req_complete_defer(),
plus everything io_do_iopoll() reaps - and are then all freed in one
io_free_batch_list() pass under ctx->uring_lock. The loop has no
scheduling point.
Each iteration does real work: io_clean_op() freeing request
payloads, file, task and rsrc puts. With debug features like KASAN
or kmemleak enabled, that work gets expensive enough that a large
batch can hold the CPU well beyond the soft lockup threshold.
Caught by io stress testing (stress-ng -a 1 --class io -t 7h) on a
384 CPU machine running a v6.6-based debug kernel (KASAN, kmemleak,
lockdep; CONFIG_PREEMPT_NONE=y): a stress-ng worker was looping
here past the watchdog threshold, entered from exit-time task_work,
until the machine panicked on "softlockup: hung tasks". Frames
from the dump:
io_clean_op
io_free_batch_list
__io_submit_flush_completions
ctx_flush_and_put
tctx_task_work
task_work_run
get_signal
The same test later caught a completion fallback work item holding
uring_lock for 671 seconds in this same loop ("BUG: soft lockup -
CPU#61 stuck for 671s").
Also measured on mainline v7.3-rc7 (192-CPU debug kernel with the
same debug features): a single pass freeing a 32K completion batch
took 443ms with no scheduling point in between.
Insert a cond_resched() in the loop, like other potentially long
io_uring loops already have. The loop runs in process context with
ctx->uring_lock held, which is a mutex, so scheduling is allowed.
Assisted-by: LLM
Signed-off-by: Yuanhe Shu <xiangzao@linux.alibaba.com>
---
io_uring/io_uring.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index cf5218d100d9..26cd91a91aa2 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1123,6 +1123,7 @@ static void io_free_batch_list(struct io_ring_ctx *ctx,
node = req->comp_list.next;
io_req_add_to_cache(req, ctx);
+ cond_resched();
} while (node);
}
--
2.43.7
next prev parent reply other threads:[~2026-10-20 6:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 6:44 [PATCH 0/2] io_uring: add schedule points to request freeing loops Yuanhe Shu
2026-10-20 6:44 ` Yuanhe Shu [this message]
2026-10-20 6:44 ` [PATCH 2/2] io_uring: add a schedule point in __io_req_caches_free() Yuanhe Shu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261020064452.3633250-2-xiangzao@linux.alibaba.com \
--to=xiangzao@linux.alibaba.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®