From: Catalin Marinas <catalin.marinas@arm.com>
To: Breno Leitao <leitao@debian.org>
Cc: Matthew Wilcox <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
mm-commits@vger.kernel.org, kent.overstreet@linux.dev,
bigeasy@linutronix.de, arnd@arndb.de
Subject: Re: + radix-tree-fix-kmemleak-false-positives-on-tree-head-reassignment.patch added to mm-new branch
Date: Tue, 7 Jul 2026 15:01:32 +0100 [thread overview]
Message-ID: <ak0GvJEFPE5M43f5@arm.com> (raw)
In-Reply-To: <akzZSIN5ALd8iH52@gmail.com>
Hi Breno,
Thanks looking looking at this.
On Tue, Jul 07, 2026 at 04:26:43AM -0700, Breno Leitao wrote:
> On Tue, Jul 07, 2026 at 12:19:50AM +0100, Catalin Marinas wrote:
> > +static bool flag_suspects(void)
> > +{
> > + struct kmemleak_object *object;
> > + int suspects = 0;
> > +
> > + rcu_read_lock();
> > + list_for_each_entry_rcu(object, &object_list, object_list) {
>
> __kmemleak_scan() above alread iterated over these objects. Is it
> possible to piggy back on __kmemleak_scan() list_for_each_entry_rcu
> for the objects to flag SUSPECTS?
That list has another scan_gray_list() afterwords. We could fold it into
the same list - flag all white objects here as suspects and clear this
flag in update_refs() if the object becomes gray. We'll probably need a
counter of suspected leaks set during this loop and decrement it during
update_refs() when an object becomes gray. Only go for a second scan if
this number is positive.
Yet another option would be for __kmemleak_scan() to return true if it
found any new candidates in this loop (new white objects that could not
be added to the gray list). It does not remove the second loop but it
makes it less likely for a system that doesn't have new leaks.
BTW, I think the flag_suspects() loop was missing an early continue if
!colour_white(), saves from taking the object look. But it still does a
list walk and I can see both loops looking pretty similar that one
wonders why they shouldn't be merged.
> > + raw_spin_lock_irq(&object->lock);
> > + if (unreferenced_object(object) &&
> > + !(object->flags & OBJECT_REPORTED)) {
> > + object->flags |= OBJECT_SUSPECT;
> > + suspects++;
> > + } else {
> > + object->flags &= ~OBJECT_SUSPECT;
> > + }
> > + raw_spin_unlock_irq(&object->lock);
> > + if (need_resched())
> > + kmemleak_cond_resched(object);
> > + }
> > + rcu_read_unlock();
> > +
> > + return suspects != 0;
> > +}
> > +
> > +/*
> > + * Scan the memory and report the unreferenced objects as leaks. Must be
> > + * called with the scan_mutex held.
> > + */
> > +static void kmemleak_scan(void)
> > +{
> > + struct kmemleak_object *object;
> > + struct xarray dedup;
> > + int new_leaks = 0;
>
> It seems new_leaks and dedup are not used at all.
They are in kmemleak_scan() after the second __kmemleak_scan() call.
> reviewing this code, I found that unreferenced_object(object)) is always
> called/checked with (object->flags & OBJECT_REPORTED). Would it be ok to
> move (object->flags & OBJECT_REPORTED) to inside unreferenced_object()?
They are meant for different things. The flag is for reporting and
debugfs wants REPORTED, kmemleak_scan() checks for unreferenced and
!REPORTED,
--
Catalin
next prev parent reply other threads:[~2026-07-07 14:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-05 2:12 + radix-tree-fix-kmemleak-false-positives-on-tree-head-reassignment.patch added to mm-new branch Andrew Morton
2026-07-05 10:45 ` Matthew Wilcox
2026-07-05 18:15 ` Andrew Morton
2026-07-06 10:41 ` Breno Leitao
2026-07-06 11:39 ` Catalin Marinas
2026-07-06 14:53 ` Breno Leitao
2026-07-06 16:25 ` Catalin Marinas
2026-07-06 23:19 ` Catalin Marinas
2026-07-07 11:26 ` Breno Leitao
2026-07-07 14:01 ` Catalin Marinas [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-07-05 2:11 Andrew Morton
2026-07-02 22:42 Andrew Morton
2026-07-03 15:26 ` Breno Leitao
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=ak0GvJEFPE5M43f5@arm.com \
--to=catalin.marinas@arm.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bigeasy@linutronix.de \
--cc=kent.overstreet@linux.dev \
--cc=leitao@debian.org \
--cc=mm-commits@vger.kernel.org \
--cc=willy@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.