Skip to content

Commit 3e09c50

Browse files
surenbaghdasaryanakpm00
authored andcommitted
alloc_tag: introduce shutdown_mem_profiling helper function
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/[email protected] Signed-off-by: Suren Baghdasaryan <[email protected]> Reviewed-by: Pasha Tatashin <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Borislav Petkov (AMD) <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Daniel Gomez <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: David Rientjes <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: John Hubbard <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Kalesh Singh <[email protected]> Cc: Kees Cook <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Luis Chamberlain <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mike Rapoport (Microsoft) <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Petr Pavlu <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Sami Tolvanen <[email protected]> Cc: Sourav Panda <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Thomas Huth <[email protected]> Cc: Uladzislau Rezki (Sony) <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Xiongwei Song <[email protected]> Cc: Yu Zhao <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 7c8c76e commit 3e09c50

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)