mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 2/2] io_uring: add a schedule point in __io_req_caches_free()
Date: Tue, 20 Oct 2026 14:44:52 +0800	[thread overview]
Message-ID: <20261020064452.3633250-3-xiangzao@linux.alibaba.com> (raw)
In-Reply-To: <20261020064452.3633250-1-xiangzao@linux.alibaba.com>

The request cache can grow to the workload's in-flight high-water
mark.  __io_req_caches_free() drains it with one
kmem_cache_free() per request under ctx->uring_lock, with no
scheduling point in between.  With debug features like KASAN or
kmemleak enabled, each free gets expensive, and draining a large
cache can hold the CPU well beyond the soft lockup threshold.

Reproduced on mainline v7.3-rc7 on a 192-CPU debug kernel
(preempt=none), with a test that submits 32K requests per
ring and then kills the rings.  Killing 48 rings at once made one
drain take up to 13 seconds with no scheduling point, with 8
kworkers each stuck for over 12 seconds; a separate run with 96
rings produced 97 soft lockup warnings during teardown, of the
form:

  watchdog: BUG: soft lockup - CPU#2 stuck for 12s! [kworker/u769:5]
  Workqueue: iou_exit io_ring_exit_work
  Call Trace:
    stack_trace_save
    kasan_save_stack
    kmem_cache_free+0x3cf/0x6a0
    __io_req_caches_free+0x196/0x4f0
    io_ring_exit_work+0x287/0x880
    process_one_work

Regardless of the per-free cost, the loop has no bound other than
the workload's in-flight high-water mark, so it belongs with the
other potentially long io_uring loops.

Insert a cond_resched() in the drain loop.  The function is __cold;
all callers run in process context and hold only ctx->uring_lock,
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 26cd91a91aa2..dffce8ce55d5 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2142,6 +2142,7 @@ static __cold void __io_req_caches_free(struct io_ring_ctx *ctx)
 		io_poison_req(req);
 		kmem_cache_free(req_cachep, req);
 		nr++;
+		cond_resched();
 	}
 	if (nr) {
 		ctx->nr_req_allocated -= nr;
-- 
2.43.7


      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 ` [PATCH 1/2] io_uring: add a schedule point in io_free_batch_list() Yuanhe Shu
2026-10-20  6:44 ` Yuanhe Shu [this message]

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-3-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®