[PATCH 6.12.y 1/2] lib/alloc_tag: introduce mem_alloc_profiling_permanently_disabled()
"Harry Yoo (Oracle)" <[email protected]>
| Newsgroups | org.kernel.vger.stable,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <20260806-kmalloc-no-objext-for-6-12-y-v1-1-036dfc3273fc@kernel.org> |
commit a37b0066a10aabf3c968b4566706fb866eaf9a85 upstream. mem_alloc_profiling_enabled() tells whether memalloc profiling is currently enabled. However, even when this function returns false, it can be enabled later. However, this is not enough. Some optimizations can be applied only when memalloc profiling is permanently disabled. For example, to skip the creation of KMALLOC_NO_OBJ_EXT caches at boot time, mem_profiling must be set to "never", "0" w/ debugging on, or have been shutdown so that it can no longer be enabled. Introduce mem_alloc_profiling_permanently_disabled() for this purpose. Signed-off-by: Harry Yoo (Oracle) <[email protected]> Acked-by: Suren Baghdasaryan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Vlastimil Babka (SUSE) <[email protected]> [ [email protected]: Move the definition of mem_alloc_profiling_permanently_disabled() after mem_profiling_support. Unlike 6.18 and later kernels, mem_profiling_support is marked __init and gets freed after boot. Since the function is needed only when creating kmalloc caches, mark it __init as well. ] Signed-off-by: Harry Yoo <[email protected]> --- include/linux/alloc_tag.h | 3 +++ lib/alloc_tag.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 6073a8f13c41..70025f8e2499 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -105,6 +105,8 @@ static inline bool mem_alloc_profiling_enabled(void) &mem_alloc_profiling_key); } +bool __init mem_alloc_profiling_permanently_disabled(void); + static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *tag) { struct alloc_tag_counters v = { 0, 0 }; @@ -198,6 +200,7 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) #define DEFINE_ALLOC_TAG(_alloc_tag) static inline bool mem_alloc_profiling_enabled(void) { return false; } +static inline bool mem_alloc_profiling_permanently_disabled(void) { return true; } static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, size_t bytes) {} static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {} diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index e76c40bf29d0..a0d11582029e 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -183,6 +183,15 @@ static bool mem_profiling_support __meminitdata = true; static bool mem_profiling_support __meminitdata; #endif +/* + * Memory allocation profiling is permanently disabled and cannot be enabled. + * Must be called after setup_early_mem_profiling(). + */ +bool __init mem_alloc_profiling_permanently_disabled(void) +{ + return !mem_profiling_support; +} + static int __init setup_early_mem_profiling(char *str) { bool enable; -- 2.53.0