From: Weilin Tong <tongweilin@linux.alibaba.com>
To: catalin.marinas@arm.com, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] mm: kmemleak: reschedule while reading reports
Date: Thu, 5 Nov 2026 17:52:50 +0800 [thread overview]
Message-ID: <70139bdb8c7a61913d5081671fcc2af37348fffd.1793871596.git.tongweilin@linux.alibaba.com> (raw)
In-Reply-To: <cover.1793871596.git.tongweilin@linux.alibaba.com>
Reading a kmemleak report walks all tracked objects under RCU, even
when the report is empty. On large debug kernels this can stall RCU.
Use kmemleak_cond_resched() in both seq traversal loops. Request a break
when need_resched() is set and periodically every 256 positions, since
preemption can clear need_resched() without ending the RCU read-side
critical section.
The helper pins a linked cursor and defers its removal across RCU breaks.
Already removed cursors remain under RCU to protect their forward links.
This allows RCU grace periods to progress during long report reads.
Fixes: f5886c7f96f2 ("kmemleak: Protect the seq start/next/stop sequence by rcu_read_lock()")
Assisted-by: LLM
Signed-off-by: Weilin Tong <tongweilin@linux.alibaba.com>
---
mm/kmemleak.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index d959d11f6..0fe7d336c 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -2216,6 +2216,9 @@ static void stop_scan_thread(void)
}
}
+/* Also break RCU periodically when preemption clears need_resched(). */
+#define KMEMLEAK_SEQ_RESCHED_INTERVAL 256
+
/*
* Iterate over the object_list and return the first valid object at or after
* the required position with its use_count incremented. The function triggers
@@ -2233,6 +2236,9 @@ static void *kmemleak_seq_start(struct seq_file *seq, loff_t *pos)
rcu_read_lock();
list_for_each_entry_rcu(object, &object_list, object_list) {
+ if (need_resched() || !(n % KMEMLEAK_SEQ_RESCHED_INTERVAL))
+ kmemleak_cond_resched(object);
+
if (n-- > 0)
continue;
if (get_object(object))
@@ -2256,6 +2262,9 @@ static void *kmemleak_seq_next(struct seq_file *seq, void *v, loff_t *pos)
++(*pos);
list_for_each_entry_continue_rcu(obj, &object_list, object_list) {
+ if (need_resched() || !(*pos % KMEMLEAK_SEQ_RESCHED_INTERVAL))
+ kmemleak_cond_resched(obj);
+
if (get_object(obj)) {
next_obj = obj;
break;
prev parent reply other threads:[~2026-11-05 9:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 9:52 [PATCH 0/2] mm: kmemleak: avoid long RCU read-side sections in reports Weilin Tong
2026-11-05 9:52 ` [PATCH 1/2] mm: kmemleak: serialize disable-time cleanup Weilin Tong
2026-11-05 9:52 ` Weilin Tong [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=70139bdb8c7a61913d5081671fcc2af37348fffd.1793871596.git.tongweilin@linux.alibaba.com \
--to=tongweilin@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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®