]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/alloc_tag: introduce mem_alloc_profiling_permanently_disabled()
authorHarry Yoo (Oracle) <harry@kernel.org>
Mon, 13 Jul 2026 14:28:51 +0000 (23:28 +0900)
committerVlastimil Babka (SUSE) <vbabka@kernel.org>
Tue, 14 Jul 2026 14:44:40 +0000 (16:44 +0200)
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) <harry@kernel.org>
Acked-by: Suren Baghdasaryan <surenb@google.com>
Link: https://patch.msgid.link/20260713-kmalloc-no-objext-v3-3-47c7bd138de7@kernel.org
Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
include/linux/alloc_tag.h
lib/alloc_tag.c

index 068ba2e77c5d65a362826c5f5a848bb470f1bbbf..6ed9f82e639f3e9f6e256dd9e428784790a0fae6 100644 (file)
@@ -134,6 +134,8 @@ static inline bool mem_alloc_profiling_enabled(void)
                                   &mem_alloc_profiling_key);
 }
 
+bool 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 };
@@ -239,6 +241,7 @@ static inline bool alloc_tag_is_inaccurate(struct alloc_tag *tag)
 
 #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) {}
index d9be1cf5187d97e01ffd6c4d0e448d5ccaed1d22..e5b218176c5afe73198e030c07bfa0ebce30dc0d 100644 (file)
@@ -26,6 +26,15 @@ static bool mem_profiling_support = true;
 static bool mem_profiling_support;
 #endif
 
+/*
+ * Memory allocation profiling is permanently disabled and cannot be enabled.
+ * Must be called after setup_early_mem_profiling().
+ */
+bool mem_alloc_profiling_permanently_disabled(void)
+{
+       return !mem_profiling_support;
+}
+
 static struct codetag_type *alloc_tag_cttype;
 
 #ifdef CONFIG_ARCH_MODULE_NEEDS_WEAK_PER_CPU