Skip to content

Commit d53ce04

Browse files
Sri Krishna chowdarytorvalds
authored andcommitted
kmemleak: add config to select auto scan
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/1540231723-7087-1-git-send-email-prpatel@nvidia.com Signed-off-by: Sri Krishna chowdary <schowdary@nvidia.com> Signed-off-by: Sachin Nikam <snikam@nvidia.com> Signed-off-by: Prateek <prpatel@nvidia.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3c0c12c commit d53ce04

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/Kconfig.debug

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,21 @@ config DEBUG_KMEMLEAK_DEFAULT_OFF
593593
Say Y here to disable kmemleak by default. It can then be enabled
594594
on the command line via kmemleak=on.
595595

596+
config DEBUG_KMEMLEAK_AUTO_SCAN
597+
bool "Enable kmemleak auto scan thread on boot up"
598+
default y
599+
depends on DEBUG_KMEMLEAK
600+
help
601+
Depending on the cpu, kmemleak scan may be cpu intensive and can
602+
stall user tasks at times. This option enables/disables automatic
603+
kmemleak scan at boot up.
604+
605+
Say N here to disable kmemleak auto scan thread to stop automatic
606+
scanning. Disabling this option disables automatic reporting of
607+
memory leaks.
608+
609+
If unsure, say Y.
610+
596611
config DEBUG_STACK_USAGE
597612
bool "Stack utilization instrumentation"
598613
depends on DEBUG_KERNEL && !IA64

mm/kmemleak.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ static void kmemleak_scan(void)
16501650
*/
16511651
static int kmemleak_scan_thread(void *arg)
16521652
{
1653-
static int first_run = 1;
1653+
static int first_run = IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN);
16541654

16551655
pr_info("Automatic memory scanning thread started\n");
16561656
set_user_nice(current, 10);
@@ -2144,9 +2144,11 @@ static int __init kmemleak_late_init(void)
21442144
return -ENOMEM;
21452145
}
21462146

2147-
mutex_lock(&scan_mutex);
2148-
start_scan_thread();
2149-
mutex_unlock(&scan_mutex);
2147+
if (IS_ENABLED(CONFIG_DEBUG_KMEMLEAK_AUTO_SCAN)) {
2148+
mutex_lock(&scan_mutex);
2149+
start_scan_thread();
2150+
mutex_unlock(&scan_mutex);
2151+
}
21502152

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

0 commit comments

Comments
 (0)