Commit c5665868 authored by Catalin Marinas's avatar Catalin Marinas Committed by Linus Torvalds

mm: kmemleak: use the memory pool for early allocations

Currently kmemleak uses a static early_log buffer to trace all memory
allocation/freeing before the slab allocator is initialised.  Such early
log is replayed during kmemleak_init() to properly initialise the kmemleak
metadata for objects allocated up that point.  With a memory pool that
does not rely on the slab allocator, it is possible to skip this early log
entirely.

In order to remove the early logging, consider kmemleak_enabled == 1 by
default while the kmem_cache availability is checked directly on the
object_cache and scan_area_cache variables.  The RCU callback is only
invoked after object_cache has been initialised as we wouldn't have any
concurrent list traversal before this.

In order to reduce the number of callbacks before kmemleak is fully
initialised, move the kmemleak_init() call to mm_init().

[akpm@linux-foundation.org: coding-style fixes]
[akpm@linux-foundation.org: remove WARN_ON(), per Catalin]
Link: http://lkml.kernel.org/r/20190812160642.52134-4-catalin.marinas@arm.comSigned-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Qian Cai <cai@lca.pw>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0647398a
...@@ -556,6 +556,7 @@ static void __init mm_init(void) ...@@ -556,6 +556,7 @@ static void __init mm_init(void)
report_meminit(); report_meminit();
mem_init(); mem_init();
kmem_cache_init(); kmem_cache_init();
kmemleak_init();
pgtable_init(); pgtable_init();
debug_objects_mem_init(); debug_objects_mem_init();
vmalloc_init(); vmalloc_init();
...@@ -740,7 +741,6 @@ asmlinkage __visible void __init start_kernel(void) ...@@ -740,7 +741,6 @@ asmlinkage __visible void __init start_kernel(void)
initrd_start = 0; initrd_start = 0;
} }
#endif #endif
kmemleak_init();
setup_per_cpu_pageset(); setup_per_cpu_pageset();
numa_policy_init(); numa_policy_init();
acpi_early_init(); acpi_early_init();
......
...@@ -576,17 +576,18 @@ config DEBUG_KMEMLEAK ...@@ -576,17 +576,18 @@ config DEBUG_KMEMLEAK
In order to access the kmemleak file, debugfs needs to be In order to access the kmemleak file, debugfs needs to be
mounted (usually at /sys/kernel/debug). mounted (usually at /sys/kernel/debug).
config DEBUG_KMEMLEAK_EARLY_LOG_SIZE config DEBUG_KMEMLEAK_MEM_POOL_SIZE
int "Maximum kmemleak early log entries" int "Kmemleak memory pool size"
depends on DEBUG_KMEMLEAK depends on DEBUG_KMEMLEAK
range 200 40000 range 200 40000
default 16000 default 16000
help help
Kmemleak must track all the memory allocations to avoid Kmemleak must track all the memory allocations to avoid
reporting false positives. Since memory may be allocated or reporting false positives. Since memory may be allocated or
freed before kmemleak is initialised, an early log buffer is freed before kmemleak is fully initialised, use a static pool
used to store these actions. If kmemleak reports "early log of metadata objects to track such callbacks. After kmemleak is
buffer exceeded", please increase this value. fully initialised, this memory pool acts as an emergency one
if slab allocations fail.
config DEBUG_KMEMLEAK_TEST config DEBUG_KMEMLEAK_TEST
tristate "Simple test for the kernel memory leak detector" tristate "Simple test for the kernel memory leak detector"
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment