]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option
authorBreno Leitao <leitao@debian.org>
Mon, 23 Mar 2026 11:12:13 +0000 (04:12 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 18 Apr 2026 07:10:48 +0000 (00:10 -0700)
Add a Kconfig option to default kmemleak verbose mode on at build time.
This option depends on DEBUG_KMEMLEAK_AUTO_SCAN since verbose reporting is
only meaningful when the automatic scanning thread is running.

When enabled, kmemleak prints full details (backtrace, hex dump, address)
of unreferenced objects to dmesg as they are detected during scanning,
removing the need to manually read /sys/kernel/debug/kmemleak.

Making this a compile-time option rather than a boot parameter allows
debug kernel flavors to enable verbose kmemleak reporting by default
without requiring changes to boot arguments.  A machine can simply swap to
a debug kernel and benefit from kmemleak reporting automatically.

By surfacing leak reports directly in dmesg, they are automatically
forwarded through any kernel logging infrastructure and can be easily
captured by log aggregation tooling, making it practical to monitor memory
leaks across large fleets.

The verbose setting can still be toggled at runtime via
/sys/module/kmemleak/parameters/verbose.

Link: https://lore.kernel.org/20260323-kmemleak_report-v1-1-ba2cdd9c11b9@debian.org
Signed-off-by: Breno Leitao <leitao@debian.org>
Acked-by: SeongJae Park <sj@kernel.org>
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/Kconfig.debug
mm/kmemleak.c

index 7638d75b27db8cf1153532f1fb6dc68814a2fb97..91b3e027b75357931dc8d064f9688a03cd0a7ea0 100644 (file)
@@ -297,6 +297,17 @@ config DEBUG_KMEMLEAK_AUTO_SCAN
 
          If unsure, say Y.
 
+config DEBUG_KMEMLEAK_VERBOSE
+       bool "Default kmemleak to verbose mode"
+       depends on DEBUG_KMEMLEAK_AUTO_SCAN
+       help
+         Say Y here to have kmemleak print unreferenced object details
+         (backtrace, hex dump, address) to dmesg when new memory leaks are
+         detected during automatic scanning. This can also be toggled at
+         runtime via /sys/module/kmemleak/parameters/verbose.
+
+         If unsure, say N.
+
 config PER_VMA_LOCK_STATS
        bool "Statistics for per-vma locks"
        depends on PER_VMA_LOCK
index fa8201e23222119dd5a239cb5caa9e1d1a631d68..2eff0d6b622b62eeeb1eb9c409d22459948746ab 100644 (file)
@@ -241,7 +241,7 @@ static int kmemleak_skip_disable;
 /* If there are leaks that can be reported */
 static bool kmemleak_found_leaks;
 
-static bool kmemleak_verbose;
+static bool kmemleak_verbose = IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_VERBOSE);
 module_param_named(verbose, kmemleak_verbose, bool, 0600);
 
 static void kmemleak_disable(void);