diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-05-13 02:39:24 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-05-29 20:22:25 -0400 |
commit | ffb8da3c0bd7f22050c39a3114286e01ead8b671 (patch) | |
tree | e2715077b3a31fe65575ef9f598c5b7f8efdb3ea | |
parent | 2ab06f4209552fd2de50a74804ad866181c9e641 (diff) |
mem profiling: Runtime switchmemalloc_prof_v1
This converts the boot switch to a sysctl, which can be changed at
runtime when CONFIG_MEM_ALLOC_PROFILING_DEBUG=n
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | include/linux/alloc_tag.h | 6 | ||||
-rw-r--r-- | lib/alloc_tag.c | 29 | ||||
-rw-r--r-- | mm/slab.h | 3 |
3 files changed, 16 insertions, 22 deletions
diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index be51f3b35e9e..7356ca7dbd34 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -79,9 +79,6 @@ static inline void __alloc_tag_sub(union codetag_ref *ref, size_t bytes, struct alloc_tag *tag; #ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG - /* The switch should be checked before this */ - BUG_ON(!mem_alloc_profiling_enabled()); - WARN_ONCE(ref && !ref->ct, "alloc_tag was not set\n"); #endif if (!ref || !ref->ct) @@ -117,9 +114,6 @@ static inline void alloc_tag_sub_noalloc(union codetag_ref *ref, size_t bytes) static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, size_t bytes) { #ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG - /* The switch should be checked before this */ - BUG_ON(!mem_alloc_profiling_enabled()); - WARN_ONCE(ref && ref->ct, "alloc_tag was not cleared (got tag for %s:%u)\n",\ ref->ct->filename, ref->ct->lineno); diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 9648f59e7f3c..b0713df8f270 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -17,19 +17,6 @@ static struct codetag_type *alloc_tag_cttype; DEFINE_STATIC_KEY_TRUE(mem_alloc_profiling_key); -/* - * Won't need to be exported once page allocation accounting is moved to the - * correct place: - */ -EXPORT_SYMBOL(mem_alloc_profiling_key); - -static int __init mem_alloc_profiling_disable(char *s) -{ - static_branch_disable(&mem_alloc_profiling_key); - return 1; -} -__setup("nomem_profiling", mem_alloc_profiling_disable); - struct alloc_call_ctx { struct codetag_ctx ctx; size_t size; @@ -447,6 +434,20 @@ struct page_ext_operations page_alloc_tagging_ops = { }; EXPORT_SYMBOL(page_alloc_tagging_ops); +static struct ctl_table memory_allocation_profiling_sysctls[] = { + { + .procname = "mem_profiling", + .data = &mem_alloc_profiling_key, +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + .mode = 0444, +#else + .mode = 0644, +#endif + .proc_handler = proc_do_static_key, + }, + { } +}; + static int __init alloc_tag_init(void) { const struct codetag_type_desc desc = { @@ -456,6 +457,8 @@ static int __init alloc_tag_init(void) .free_ctx = alloc_tag_ops_free_ctx, }; + register_sysctl_init("vm", memory_allocation_profiling_sysctls); + alloc_tag_cttype = codetag_register_type(&desc); if (IS_ERR_OR_NULL(alloc_tag_cttype)) return PTR_ERR(alloc_tag_cttype); diff --git a/mm/slab.h b/mm/slab.h index 50d86008a86a..511086b1364c 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -535,9 +535,6 @@ static inline void alloc_tagging_slab_free_hook(struct kmem_cache *s, struct sla struct slabobj_ext *obj_exts; int i; - if (!mem_alloc_profiling_enabled()) - return; - obj_exts = slab_obj_exts(slab); if (!obj_exts) return; |