|
8 | 8 | #include <linux/seq_buf.h>
|
9 | 9 | #include <linux/seq_file.h>
|
10 | 10 |
|
| 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 | + |
11 | 19 | static struct codetag_type *alloc_tag_cttype;
|
12 | 20 |
|
13 | 21 | 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
|
144 | 152 | return nr;
|
145 | 153 | }
|
146 | 154 |
|
| 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 | + |
147 | 166 | static void __init procfs_init(void)
|
148 | 167 | {
|
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 | + } |
150 | 175 | }
|
151 | 176 |
|
152 | 177 | static bool alloc_tag_module_unload(struct codetag_type *cttype,
|
@@ -174,12 +199,6 @@ static bool alloc_tag_module_unload(struct codetag_type *cttype,
|
174 | 199 | return module_unused;
|
175 | 200 | }
|
176 | 201 |
|
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 |
| - |
183 | 202 | static int __init setup_early_mem_profiling(char *str)
|
184 | 203 | {
|
185 | 204 | bool enable;
|
|
0 commit comments