linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kmemleak: Add config to select auto scan
@ 2018-10-17  8:03 Prateek Patel
  2018-10-17 13:41 ` Catalin Marinas
  0 siblings, 1 reply; 2+ messages in thread
From: Prateek Patel @ 2018-10-17  8:03 UTC (permalink / raw)
  To: catalin.marinas
  Cc: linux-kernel, linux-mm, linux-tegra, snikam, vdumpa, talho,
	swarren, prpatel, Sri Krishna chowdary

From: Sri Krishna chowdary <schowdary@nvidia.com>

Kmemleak scan is cpu intensive and can stall user tasks at times.
To prevent this, add config DEBUG_KMEMLEAK_SCAN_ON to enable/disable
auto scan on boot up.
Also protect first_run with CONFIG_DEBUG_KMEMLEAK_SCAN_ON as this is
meant for only first automatic scan.

Signed-off-by: Sri Krishna chowdary <schowdary@nvidia.com>
Signed-off-by: Sachin Nikam <snikam@nvidia.com>
Signed-off-by: Prateek <prpatel@nvidia.com>
---
 lib/Kconfig.debug | 11 +++++++++++
 mm/kmemleak.c     |  6 ++++++
 2 files changed, 17 insertions(+)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index e5e7c03..9542852 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -593,6 +593,17 @@ config DEBUG_KMEMLEAK_DEFAULT_OFF
 	  Say Y here to disable kmemleak by default. It can then be enabled
 	  on the command line via kmemleak=on.
 
+config DEBUG_KMEMLEAK_SCAN_ON
+	bool "Enable kmemleak auto scan thread on boot up"
+	default y
+	depends on DEBUG_KMEMLEAK
+	help
+	  Kmemleak scan is cpu intensive and can stall user tasks at times.
+	  This option enables/disables automatic kmemleak scan at boot up.
+
+	  Say N here to disable kmemleak auto scan thread to stop automatic
+	  scanning.
+
 config DEBUG_STACK_USAGE
 	bool "Stack utilization instrumentation"
 	depends on DEBUG_KERNEL && !IA64
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 877de4f..ac53678 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -1647,11 +1647,14 @@ static void kmemleak_scan(void)
  */
 static int kmemleak_scan_thread(void *arg)
 {
+#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON
 	static int first_run = 1;
+#endif
 
 	pr_info("Automatic memory scanning thread started\n");
 	set_user_nice(current, 10);
 
+#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON
 	/*
 	 * Wait before the first scan to allow the system to fully initialize.
 	 */
@@ -1661,6 +1664,7 @@ static int kmemleak_scan_thread(void *arg)
 		while (timeout && !kthread_should_stop())
 			timeout = schedule_timeout_interruptible(timeout);
 	}
+#endif
 
 	while (!kthread_should_stop()) {
 		signed long timeout = jiffies_scan_wait;
@@ -2141,9 +2145,11 @@ static int __init kmemleak_late_init(void)
 		return -ENOMEM;
 	}
 
+#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON
 	mutex_lock(&scan_mutex);
 	start_scan_thread();
 	mutex_unlock(&scan_mutex);
+#endif
 
 	pr_info("Kernel memory leak detector initialized\n");
 
-- 
2.1.4


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

* Re: [PATCH] kmemleak: Add config to select auto scan
  2018-10-17  8:03 [PATCH] kmemleak: Add config to select auto scan Prateek Patel
@ 2018-10-17 13:41 ` Catalin Marinas
  0 siblings, 0 replies; 2+ messages in thread
From: Catalin Marinas @ 2018-10-17 13:41 UTC (permalink / raw)
  To: Prateek Patel
  Cc: linux-kernel, linux-mm, linux-tegra, snikam, vdumpa, talho,
	swarren, Sri Krishna chowdary

On Wed, Oct 17, 2018 at 01:33:28PM +0530, Prateek Patel wrote:
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index e5e7c03..9542852 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -593,6 +593,17 @@ config DEBUG_KMEMLEAK_DEFAULT_OFF
>  	  Say Y here to disable kmemleak by default. It can then be enabled
>  	  on the command line via kmemleak=on.
>  
> +config DEBUG_KMEMLEAK_SCAN_ON

Nitpick: DEBUG_KMEMLEAK_AUTO_SCAN may be a better name since you don't
aim to disable scanning altogether.

> +	bool "Enable kmemleak auto scan thread on boot up"
> +	default y
> +	depends on DEBUG_KMEMLEAK
> +	help
> +	  Kmemleak scan is cpu intensive and can stall user tasks at times.

I guess that depends on the CPU.

> +	  This option enables/disables automatic kmemleak scan at boot up.
> +
> +	  Say N here to disable kmemleak auto scan thread to stop automatic
> +	  scanning.

You should also mention that disabling this option also disables
automatic reporting of memory leaks. And I'd add a "if unsure, say Y".

> +
>  config DEBUG_STACK_USAGE
>  	bool "Stack utilization instrumentation"
>  	depends on DEBUG_KERNEL && !IA64
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 877de4f..ac53678 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -1647,11 +1647,14 @@ static void kmemleak_scan(void)
>   */
>  static int kmemleak_scan_thread(void *arg)
>  {
> +#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON
>  	static int first_run = 1;
> +#endif

	static int first_run = IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN);

>  
>  	pr_info("Automatic memory scanning thread started\n");
>  	set_user_nice(current, 10);
>  
> +#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON
>  	/*
>  	 * Wait before the first scan to allow the system to fully initialize.
>  	 */
> @@ -1661,6 +1664,7 @@ static int kmemleak_scan_thread(void *arg)
>  		while (timeout && !kthread_should_stop())
>  			timeout = schedule_timeout_interruptible(timeout);
>  	}
> +#endif

With the first_run change above, this #ifdef is no longer needed.

>  
>  	while (!kthread_should_stop()) {
>  		signed long timeout = jiffies_scan_wait;
> @@ -2141,9 +2145,11 @@ static int __init kmemleak_late_init(void)
>  		return -ENOMEM;
>  	}
>  
> +#ifdef CONFIG_DEBUG_KMEMLEAK_SCAN_ON
>  	mutex_lock(&scan_mutex);
>  	start_scan_thread();
>  	mutex_unlock(&scan_mutex);
> +#endif

Please use:

	if (IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN)) {
		...
	}

-- 
Catalin

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

end of thread, other threads:[~2018-10-17 13:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-17  8:03 [PATCH] kmemleak: Add config to select auto scan Prateek Patel
2018-10-17 13:41 ` 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).