Commit a9d9058abab4ac17b79d500506e6c74bd16cecdc

Authored by Catalin Marinas
1 parent 28d0325ce6

kmemleak: Allow the early log buffer to be configurable.

(feature suggested by Sergey Senozhatsky)

Kmemleak needs to track all the memory allocations but some of these
happen before kmemleak is initialised. These are stored in an internal
buffer which may be exceeded in some kernel configurations. This patch
adds a configuration option with a default value of 400 and also removes
the stack dump when the early log buffer is exceeded.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@mail.by>

Showing 3 changed files with 19 additions and 2 deletions Side-by-side Diff

Documentation/kmemleak.txt
... ... @@ -41,6 +41,10 @@
41 41 Kmemleak can also be disabled at boot-time by passing "kmemleak=off" on
42 42 the kernel command line.
43 43  
  44 +Memory may be allocated or freed before kmemleak is initialised and
  45 +these actions are stored in an early log buffer. The size of this buffer
  46 +is configured via the CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE option.
  47 +
44 48 Basic Algorithm
45 49 ---------------
46 50  
... ... @@ -359,6 +359,18 @@
359 359 In order to access the kmemleak file, debugfs needs to be
360 360 mounted (usually at /sys/kernel/debug).
361 361  
  362 +config DEBUG_KMEMLEAK_EARLY_LOG_SIZE
  363 + int "Maximum kmemleak early log entries"
  364 + depends on DEBUG_KMEMLEAK
  365 + range 200 2000
  366 + default 400
  367 + help
  368 + Kmemleak must track all the memory allocations to avoid
  369 + reporting false positives. Since memory may be allocated or
  370 + freed before kmemleak is initialised, an early log buffer is
  371 + used to store these actions. If kmemleak reports "early log
  372 + buffer exceeded", please increase this value.
  373 +
362 374 config DEBUG_KMEMLEAK_TEST
363 375 tristate "Simple test for the kernel memory leak detector"
364 376 depends on DEBUG_KMEMLEAK
... ... @@ -235,7 +235,7 @@
235 235 };
236 236  
237 237 /* early logging buffer and current position */
238   -static struct early_log early_log[200];
  238 +static struct early_log early_log[CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE];
239 239 static int crt_early_log;
240 240  
241 241 static void kmemleak_disable(void);
... ... @@ -696,7 +696,8 @@
696 696 struct early_log *log;
697 697  
698 698 if (crt_early_log >= ARRAY_SIZE(early_log)) {
699   - kmemleak_stop("Early log buffer exceeded\n");
  699 + pr_warning("Early log buffer exceeded\n");
  700 + kmemleak_disable();
700 701 return;
701 702 }
702 703