* [PATCH] mm: kmemleak: default min_unref_scans to 2 for verbose auto-scan
@ 2026-07-30 14:31 Breno Leitao
2026-08-03 13:41 ` Catalin Marinas
0 siblings, 1 reply; 3+ messages in thread
From: Breno Leitao @ 2026-07-30 14:31 UTC (permalink / raw)
To: Catalin Marinas, Andrew Morton
Cc: linux-mm, linux-kernel, kernel-team, Breno Leitao
min_unref_scans defers reporting an object as leaked until it has stayed
unreferenced for that many consecutive scans, filtering out objects that
are only transiently unreferenced during a scan.
It defaults to 1, which reports on the first unreferenced scan.
When CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN and CONFIG_DEBUG_KMEMLEAK_VERBOSE are
both enabled, the scan thread runs periodically and the user has opted into
detailed leak reporting, so a second confirming scan happens on its own.
Default min_unref_scans to 2 in that configuration to suppress transient
false positives.
Keep the default at 1 otherwise, where a manually triggered scan is
expected to report immediately. The value stays writable through the module
parameter.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
mm/kmemleak.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index f63dfacee7ca1..6c31e66915ec7 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -237,7 +237,13 @@ static struct task_struct *scan_thread;
/* used to avoid reporting of recently allocated objects */
static unsigned long jiffies_min_age;
/* consecutive scans an object must stay unreferenced before reporting */
-static unsigned int min_unref_scans = 1;
+#if IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_VERBOSE) && \
+ IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN)
+#define MIN_UNREF_SCANS_DEFAULT 2
+#else
+#define MIN_UNREF_SCANS_DEFAULT 1
+#endif
+static unsigned int min_unref_scans = MIN_UNREF_SCANS_DEFAULT;
module_param(min_unref_scans, uint, 0644);
static unsigned long jiffies_last_scan;
/* delay between automatic memory scannings */
---
base-commit: 78bc8af4affb9a732504eb22eeac7d1e50883853
change-id: 20260730-kmemleak_hardened-e80542d1152f
Best regards,
--
Breno Leitao <leitao@debian.org>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: kmemleak: default min_unref_scans to 2 for verbose auto-scan
2026-07-30 14:31 [PATCH] mm: kmemleak: default min_unref_scans to 2 for verbose auto-scan Breno Leitao
@ 2026-08-03 13:41 ` Catalin Marinas
2026-08-03 13:44 ` Catalin Marinas
0 siblings, 1 reply; 3+ messages in thread
From: Catalin Marinas @ 2026-08-03 13:41 UTC (permalink / raw)
To: Breno Leitao; +Cc: Andrew Morton, linux-mm, linux-kernel, kernel-team
On Thu, Jul 30, 2026 at 07:31:21AM -0700, Breno Leitao wrote:
> min_unref_scans defers reporting an object as leaked until it has stayed
> unreferenced for that many consecutive scans, filtering out objects that
> are only transiently unreferenced during a scan.
>
> It defaults to 1, which reports on the first unreferenced scan.
>
> When CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN and CONFIG_DEBUG_KMEMLEAK_VERBOSE are
> both enabled, the scan thread runs periodically and the user has opted into
> detailed leak reporting, so a second confirming scan happens on its own.
>
> Default min_unref_scans to 2 in that configuration to suppress transient
> false positives.
>
> Keep the default at 1 otherwise, where a manually triggered scan is
> expected to report immediately. The value stays writable through the module
> parameter.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: kmemleak: default min_unref_scans to 2 for verbose auto-scan
2026-08-03 13:41 ` Catalin Marinas
@ 2026-08-03 13:44 ` Catalin Marinas
0 siblings, 0 replies; 3+ messages in thread
From: Catalin Marinas @ 2026-08-03 13:44 UTC (permalink / raw)
To: Breno Leitao; +Cc: Andrew Morton, linux-mm, linux-kernel, kernel-team
On Mon, Aug 03, 2026 at 02:41:20PM +0100, Catalin Marinas wrote:
> On Thu, Jul 30, 2026 at 07:31:21AM -0700, Breno Leitao wrote:
> > min_unref_scans defers reporting an object as leaked until it has stayed
> > unreferenced for that many consecutive scans, filtering out objects that
> > are only transiently unreferenced during a scan.
> >
> > It defaults to 1, which reports on the first unreferenced scan.
> >
> > When CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN and CONFIG_DEBUG_KMEMLEAK_VERBOSE are
> > both enabled, the scan thread runs periodically and the user has opted into
> > detailed leak reporting, so a second confirming scan happens on its own.
> >
> > Default min_unref_scans to 2 in that configuration to suppress transient
> > false positives.
> >
> > Keep the default at 1 otherwise, where a manually triggered scan is
> > expected to report immediately. The value stays writable through the module
> > parameter.
> >
> > Signed-off-by: Breno Leitao <leitao@debian.org>
>
> Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Ah, I noticed there's a v2. Ignore this one.
--
Catalin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-03 13:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-30 14:31 [PATCH] mm: kmemleak: default min_unref_scans to 2 for verbose auto-scan Breno Leitao
2026-08-03 13:41 ` Catalin Marinas
2026-08-03 13:44 ` Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).