Skip to content

Commit

Permalink
kmemleak: add config to select auto scan
Browse files Browse the repository at this point in the history
Kmemleak scan can be cpu intensive and can stall user tasks at times.  To
prevent this, add config DEBUG_KMEMLEAK_AUTO_SCAN to enable/disable auto
scan on boot up.  Also protect first_run with DEBUG_KMEMLEAK_AUTO_SCAN as
this is meant for only first automatic scan.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Sri Krishna chowdary <[email protected]>
Signed-off-by: Sachin Nikam <[email protected]>
Signed-off-by: Prateek <[email protected]>
Reviewed-by: Catalin Marinas <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Sri Krishna chowdary authored and torvalds committed Dec 28, 2018
1 parent 3c0c12c commit d53ce04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 15 additions & 0 deletions lib/Kconfig.debug
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,21 @@ 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_AUTO_SCAN
bool "Enable kmemleak auto scan thread on boot up"
default y
depends on DEBUG_KMEMLEAK
help
Depending on the cpu, kmemleak scan may be 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. Disabling this option disables automatic reporting of
memory leaks.

If unsure, say Y.

config DEBUG_STACK_USAGE
bool "Stack utilization instrumentation"
depends on DEBUG_KERNEL && !IA64
Expand Down
10 changes: 6 additions & 4 deletions mm/kmemleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ static void kmemleak_scan(void)
*/
static int kmemleak_scan_thread(void *arg)
{
static int first_run = 1;
static int first_run = IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN);

pr_info("Automatic memory scanning thread started\n");
set_user_nice(current, 10);
Expand Down Expand Up @@ -2144,9 +2144,11 @@ static int __init kmemleak_late_init(void)
return -ENOMEM;
}

mutex_lock(&scan_mutex);
start_scan_thread();
mutex_unlock(&scan_mutex);
if (IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN)) {
mutex_lock(&scan_mutex);
start_scan_thread();
mutex_unlock(&scan_mutex);
}

pr_info("Kernel memory leak detector initialized\n");

Expand Down

0 comments on commit d53ce04

Please sign in to comment.