Skip to content

Commit

Permalink
lib: introduce early boot parameter to avoid page_ext memory overhead
Browse files Browse the repository at this point in the history
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 <surenb@google.com>
  • Loading branch information
surenbaghdasaryan committed Feb 25, 2024
1 parent 0a5fa44 commit 7ca367e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/alloc_tag.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 7ca367e

Please sign in to comment.