Skip to content

Commit 66e3e16

Browse files
committed
alloc_tag: introduce shutdown_mem_profiling helper function
jira LE-4694 Rebuild_History Non-Buildable kernel-6.12.0-55.43.1.el10_0 commit-author Suren Baghdasaryan <surenb@google.com> commit 3e09c50 Implement a helper function to disable memory allocation profiling and use it when creation of /proc/allocinfo fails. Ensure /proc/allocinfo does not get created when memory allocation profiling is disabled. Link: https://lkml.kernel.org/r/20241023170759.999909-3-surenb@google.com Signed-off-by: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Petkov (AMD) <bp@alien8.de> Cc: Christoph Hellwig <hch@infradead.org> Cc: Daniel Gomez <da.gomez@samsung.com> Cc: David Hildenbrand <david@redhat.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: David Rientjes <rientjes@google.com> Cc: Dennis Zhou <dennis@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Kalesh Singh <kaleshsingh@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Liam R. Howlett <Liam.Howlett@Oracle.com> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Matthew Wilcox <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Minchan Kim <minchan@google.com> Cc: Paul E. McKenney <paulmck@kernel.org> Cc: Petr Pavlu <petr.pavlu@suse.com> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Sami Tolvanen <samitolvanen@google.com> Cc: Sourav Panda <souravpanda@google.com> Cc: Steven Rostedt (Google) <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Thomas Huth <thuth@redhat.com> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Xiongwei Song <xiongwei.song@windriver.com> Cc: Yu Zhao <yuzhao@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit 3e09c50) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 17fc400 commit 66e3e16

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

lib/alloc_tag.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
#include <linux/seq_buf.h>
99
#include <linux/seq_file.h>
1010

11+
#define ALLOCINFO_FILE_NAME "allocinfo"
12+
13+
#ifdef CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT
14+
static bool mem_profiling_support __meminitdata = true;
15+
#else
16+
static bool mem_profiling_support __meminitdata;
17+
#endif
18+
1119
static struct codetag_type *alloc_tag_cttype;
1220

1321
DEFINE_PER_CPU(struct alloc_tag_counters, _shared_alloc_tag);
@@ -144,9 +152,26 @@ size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_sl
144152
return nr;
145153
}
146154

155+
static void __init shutdown_mem_profiling(void)
156+
{
157+
if (mem_alloc_profiling_enabled())
158+
static_branch_disable(&mem_alloc_profiling_key);
159+
160+
if (!mem_profiling_support)
161+
return;
162+
163+
mem_profiling_support = false;
164+
}
165+
147166
static void __init procfs_init(void)
148167
{
149-
proc_create_seq("allocinfo", 0400, NULL, &allocinfo_seq_op);
168+
if (!mem_profiling_support)
169+
return;
170+
171+
if (!proc_create_seq(ALLOCINFO_FILE_NAME, 0400, NULL, &allocinfo_seq_op)) {
172+
pr_err("Failed to create %s file\n", ALLOCINFO_FILE_NAME);
173+
shutdown_mem_profiling();
174+
}
150175
}
151176

152177
static bool alloc_tag_module_unload(struct codetag_type *cttype,
@@ -174,12 +199,6 @@ static bool alloc_tag_module_unload(struct codetag_type *cttype,
174199
return module_unused;
175200
}
176201

177-
#ifdef CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT
178-
static bool mem_profiling_support __meminitdata = true;
179-
#else
180-
static bool mem_profiling_support __meminitdata;
181-
#endif
182-
183202
static int __init setup_early_mem_profiling(char *str)
184203
{
185204
bool enable;

0 commit comments

Comments
 (0)