[PATCH] mm: kmemleak: default min_unref_scans to 2 for verbose auto-scan
From: Breno Leitao
Date: Thu Jul 30 2026 - 11:37:10 EST
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@xxxxxxxxxx>
---
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@xxxxxxxxxx>