Re: [PATCH v2] mm/kmemleak: avoid soft lockup when scanning task stacks
From: Catalin Marinas
Date: Mon Jun 15 2026 - 07:16:17 EST
Hi Breno,
On Mon, Jun 15, 2026 at 02:27:13AM -0700, Breno Leitao wrote:
> On Fri, Jun 12, 2026 at 06:11:40PM +0100, Catalin Marinas wrote:
> > if (kmemleak_stack_scan) {
> > struct pid *pid;
> > int nr = 1;
> >
> > do {
> > struct task_struct *p = NULL;
> >
> > rcu_read_lock();
> > pid = find_ge_pid(nr, &init_pid_ns);
> > if (pid) {
> > nr = pid_nr(pid) + 1;
> > p = pid_task(pid, PIDTYPE_PID);
> > if (p)
> > get_task_struct(p);
> > }
> > rcu_read_unlock();
> >
> > if (p) {
> > void *stack = try_get_task_stack(p);
> >
> > if (stack) {
> > scan_block(stack, stack + THREAD_SIZE,
> > NULL);
> > put_task_stack(p);
> > }
> > put_task_struct(p);
> > }
>
> Should we add a scan_should_stop() check here to allow early
> termination?
Ah, yes, I think we should, maybe as 'while (pid && !scan_should_stop())'.
scan_block() already bails out early but it will still go quickly
through all the stacks which we don't need. As a later clean-up, I
wonder whether we should change scan_block() to return non-zero and use
that.
--
Catalin