Commit ab0155a22ad5bda3a6dbfbbecc416cbe92619755

Authored by Jason Baron
Committed by Catalin Marinas
1 parent a7686a45c0

kmemleak: Introduce a default off mode for kmemleak

Introduce a new DEBUG_KMEMLEAK_DEFAULT_OFF config parameter that allows
kmemleak to be disabled by default, but enabled on the command line
via: kmemleak=on. Although a reboot is required to turn it on, its still
useful to not require a re-compile.

Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>

Showing 2 changed files with 20 additions and 1 deletions Side-by-side Diff

... ... @@ -400,6 +400,13 @@
400 400  
401 401 If unsure, say N.
402 402  
  403 +config DEBUG_KMEMLEAK_DEFAULT_OFF
  404 + bool "Default kmemleak to off"
  405 + depends on DEBUG_KMEMLEAK
  406 + help
  407 + Say Y here to disable kmemleak by default. It can then be enabled
  408 + on the command line via kmemleak=on.
  409 +
403 410 config DEBUG_PREEMPT
404 411 bool "Debug preemptible kernel"
405 412 depends on DEBUG_KERNEL && PREEMPT && TRACE_IRQFLAGS_SUPPORT
... ... @@ -211,7 +211,10 @@
211 211 static int kmemleak_stack_scan = 1;
212 212 /* protects the memory scanning, parameters and debug/kmemleak file access */
213 213 static DEFINE_MUTEX(scan_mutex);
  214 +/* setting kmemleak=on, will set this var, skipping the disable */
  215 +static int kmemleak_skip_disable;
214 216  
  217 +
215 218 /*
216 219 * Early object allocation/freeing logging. Kmemleak is initialized after the
217 220 * kernel allocator. However, both the kernel allocator and kmemleak may
... ... @@ -1604,7 +1607,9 @@
1604 1607 return -EINVAL;
1605 1608 if (strcmp(str, "off") == 0)
1606 1609 kmemleak_disable();
1607   - else if (strcmp(str, "on") != 0)
  1610 + else if (strcmp(str, "on") == 0)
  1611 + kmemleak_skip_disable = 1;
  1612 + else
1608 1613 return -EINVAL;
1609 1614 return 0;
1610 1615 }
... ... @@ -1617,6 +1622,13 @@
1617 1622 {
1618 1623 int i;
1619 1624 unsigned long flags;
  1625 +
  1626 +#ifdef CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF
  1627 + if (!kmemleak_skip_disable) {
  1628 + kmemleak_disable();
  1629 + return;
  1630 + }
  1631 +#endif
1620 1632  
1621 1633 jiffies_min_age = msecs_to_jiffies(MSECS_MIN_AGE);
1622 1634 jiffies_scan_wait = msecs_to_jiffies(SECS_SCAN_WAIT * 1000);