From 7ca367e80232345f471b77b3ea71cf82faf50954 Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Sun, 25 Feb 2024 00:22:13 +0000 Subject: [PATCH] lib: introduce early boot parameter to avoid page_ext memory overhead The highest memory overhead from memory allocation profiling comes from page_ext objects. This overhead exists even if the feature is disabled but compiled-in. To avoid it, introduce an early boot parameter that prevents page_ext object creation. As a result we also lose ability to enable memory allocation profiling at runtime (because there is no space to store alloctag references). Runtime sysctrl becomes read-only if the feature got disabled via early boot parameter. We reuse sysctl.vm.mem_profiling boot parameter name in order to avoid introducing yet another control. This effectively turns it into an early boot parameter. Signed-off-by: Suren Baghdasaryan --- lib/alloc_tag.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index ec54f29482dc4a..d06e5224302749 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -154,9 +154,26 @@ static bool alloc_tag_module_unload(struct codetag_type *cttype, return module_unused; } +bool mem_profiling_enabled __meminitdata = true; + +static int __init setup_early_mem_profiling(char *str) +{ + int res = kstrtobool(str, &mem_profiling_enabled); + + if (!res && mem_profiling_enabled != static_key_enabled(&mem_alloc_profiling_key)) { + if (mem_profiling_enabled) + static_branch_enable(&mem_alloc_profiling_key); + else + static_branch_disable(&mem_alloc_profiling_key); + } + + return res; +} +early_param("sysctl.vm.mem_profiling", setup_early_mem_profiling); + static __init bool need_page_alloc_tagging(void) { - return true; + return mem_profiling_enabled; } static __init void init_page_alloc_tagging(void) @@ -196,6 +213,8 @@ static int __init alloc_tag_init(void) if (IS_ERR_OR_NULL(alloc_tag_cttype)) return PTR_ERR(alloc_tag_cttype); + if (!mem_profiling_enabled) + memory_allocation_profiling_sysctls[0].mode = 0444; register_sysctl_init("vm", memory_allocation_profiling_sysctls); procfs_init();