public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option
@ 2026-03-23 11:12 Breno Leitao
  2026-03-24  0:49 ` SeongJae Park
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Breno Leitao @ 2026-03-23 11:12 UTC (permalink / raw)
  To: Andrew Morton, Catalin Marinas, David Hildenbrand
  Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	kernel-team, Breno Leitao

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.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 mm/Kconfig.debug | 11 +++++++++++
 mm/kmemleak.c    |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
index 7638d75b27db8..91b3e027b7535 100644
--- a/mm/Kconfig.debug
+++ b/mm/Kconfig.debug
@@ -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
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index fa8201e232221..2eff0d6b622b6 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -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);

---
base-commit: 785f0eb2f85decbe7c1ef9ae922931f0194ffc2e
change-id: 20260323-kmemleak_report-a9a103ee0c8c

Best regards,
--  
Breno Leitao <leitao@debian.org>



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option
  2026-03-23 11:12 [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option Breno Leitao
@ 2026-03-24  0:49 ` SeongJae Park
  2026-03-24  7:42 ` Vlastimil Babka (SUSE)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2026-03-24  0:49 UTC (permalink / raw)
  To: Breno Leitao
  Cc: SeongJae Park, Andrew Morton, Catalin Marinas, David Hildenbrand,
	Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	kernel-team

On Mon, 23 Mar 2026 04:12:13 -0700 Breno Leitao <leitao@debian.org> wrote:

> 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.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Acked-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option
  2026-03-23 11:12 [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option Breno Leitao
  2026-03-24  0:49 ` SeongJae Park
@ 2026-03-24  7:42 ` Vlastimil Babka (SUSE)
  2026-03-24 13:07 ` Lorenzo Stoakes (Oracle)
  2026-03-25 17:24 ` Catalin Marinas
  3 siblings, 0 replies; 5+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-03-24  7:42 UTC (permalink / raw)
  To: Breno Leitao, Andrew Morton, Catalin Marinas, David Hildenbrand
  Cc: Lorenzo Stoakes, Liam R. Howlett, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	kernel-team

On 3/23/26 12:12, Breno Leitao wrote:
> 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.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option
  2026-03-23 11:12 [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option Breno Leitao
  2026-03-24  0:49 ` SeongJae Park
  2026-03-24  7:42 ` Vlastimil Babka (SUSE)
@ 2026-03-24 13:07 ` Lorenzo Stoakes (Oracle)
  2026-03-25 17:24 ` Catalin Marinas
  3 siblings, 0 replies; 5+ messages in thread
From: Lorenzo Stoakes (Oracle) @ 2026-03-24 13:07 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Andrew Morton, Catalin Marinas, David Hildenbrand,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	kernel-team

On Mon, Mar 23, 2026 at 04:12:13AM -0700, Breno Leitao wrote:
> 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.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>

This seems reasonable, so:

Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>

Cheers, Lorenzo

> ---
>  mm/Kconfig.debug | 11 +++++++++++
>  mm/kmemleak.c    |  2 +-
>  2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
> index 7638d75b27db8..91b3e027b7535 100644
> --- a/mm/Kconfig.debug
> +++ b/mm/Kconfig.debug
> @@ -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
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index fa8201e232221..2eff0d6b622b6 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -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);
>
> ---
> base-commit: 785f0eb2f85decbe7c1ef9ae922931f0194ffc2e
> change-id: 20260323-kmemleak_report-a9a103ee0c8c
>
> Best regards,
> --
> Breno Leitao <leitao@debian.org>
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option
  2026-03-23 11:12 [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option Breno Leitao
                   ` (2 preceding siblings ...)
  2026-03-24 13:07 ` Lorenzo Stoakes (Oracle)
@ 2026-03-25 17:24 ` Catalin Marinas
  3 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2026-03-25 17:24 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	kernel-team

On Mon, Mar 23, 2026 at 04:12:13AM -0700, Breno Leitao wrote:
> 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.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-25 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-23 11:12 [PATCH] mm: kmemleak: add CONFIG_DEBUG_KMEMLEAK_VERBOSE build option Breno Leitao
2026-03-24  0:49 ` SeongJae Park
2026-03-24  7:42 ` Vlastimil Babka (SUSE)
2026-03-24 13:07 ` Lorenzo Stoakes (Oracle)
2026-03-25 17:24 ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox