Re: [PATCH v3 3/3] mm: kmemleak: Use the memory pool for early allocations
From: Qian Cai
Date: Tue Aug 13 2019 - 08:36:00 EST
On Mon, 2019-08-12 at 17:06 +0100, Catalin Marinas wrote:
> 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().
>
> Signed-off-by: Catalin Marinas <catalin.marinas@xxxxxxx>
> ---
> Âinit/main.cÂÂÂÂÂÂÂ|ÂÂÂ2 +-
> Âlib/Kconfig.debug |ÂÂ11 +-
> Âmm/kmemleak.cÂÂÂÂÂ| 267 +++++-----------------------------------------
> Â3 files changed, 35 insertions(+), 245 deletions(-)
>
> diff --git a/init/main.c b/init/main.c
> index 96f8d5af52d6..ca05e3cd7ef7 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -556,6 +556,7 @@ static void __init mm_init(void)
> Â report_meminit();
> Â mem_init();
> Â kmem_cache_init();
> + kmemleak_init();
> Â pgtable_init();
> Â debug_objects_mem_init();
> Â vmalloc_init();
> @@ -740,7 +741,6 @@ asmlinkage __visible void __init start_kernel(void)
> Â initrd_start = 0;
> Â }
> Â#endif
> - kmemleak_init();
> Â setup_per_cpu_pageset();
> Â numa_policy_init();
> Â acpi_early_init();
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 4d39540011e2..39df06ffd9f4 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -592,17 +592,18 @@ config DEBUG_KMEMLEAK
> Â ÂÂIn order to access the kmemleak file, debugfs needs to be
> Â ÂÂmounted (usually at /sys/kernel/debug).
> Â
> -config DEBUG_KMEMLEAK_EARLY_LOG_SIZE
> - int "Maximum kmemleak early log entries"
> +config DEBUG_KMEMLEAK_MEM_POOL_SIZE
> + int "Kmemleak memory pool size"
> Â depends on DEBUG_KMEMLEAK
> Â range 200 40000
> Â default 16000
Hmm, this seems way too small. My previous round of testing with
kmemleak.mempool=524288 works quite well on all architectures.