Skip to content

Commit 88ae5fb

Browse files
Kent Overstreetakpm00
authored andcommitted
mm: vmalloc: enable memory allocation profiling
This wrapps all external vmalloc allocation functions with the alloc_hooks() wrapper, and switches internal allocations to _noprof variants where appropriate, for the new memory allocation profiling feature. [[email protected]: arch/um: fix forward declaration for vmalloc] Link: https://lkml.kernel.org/r/[email protected] [[email protected]: undo _noprof additions in the documentation] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kent Overstreet <[email protected]> Signed-off-by: Suren Baghdasaryan <[email protected]> Tested-by: Kees Cook <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Alex Gaynor <[email protected]> Cc: Alice Ryhl <[email protected]> Cc: Andreas Hindborg <[email protected]> Cc: Benno Lossin <[email protected]> Cc: "Björn Roy Baron" <[email protected]> Cc: Boqun Feng <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Gary Guo <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Wedson Almeida Filho <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 24e44cc commit 88ae5fb

File tree

7 files changed

+123
-92
lines changed

7 files changed

+123
-92
lines changed

arch/um/include/shared/um_malloc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
extern void *uml_kmalloc(int size, int flags);
1212
extern void kfree(const void *ptr);
1313

14-
extern void *vmalloc(unsigned long size);
14+
extern void *vmalloc_noprof(unsigned long size);
15+
#define vmalloc(...) vmalloc_noprof(__VA_ARGS__)
1516
extern void vfree(void *ptr);
1617

1718
#endif /* __UM_MALLOC_H__ */

drivers/staging/media/atomisp/pci/hmm/hmm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type,
205205
}
206206

207207
dev_dbg(atomisp_dev, "pages: 0x%08x (%zu bytes), type: %d, vmalloc %p\n",
208-
bo->start, bytes, type, vmalloc);
208+
bo->start, bytes, type, vmalloc_noprof);
209209

210210
return bo->start;
211211

include/linux/vmalloc.h

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#ifndef _LINUX_VMALLOC_H
33
#define _LINUX_VMALLOC_H
44

5+
#include <linux/alloc_tag.h>
6+
#include <linux/sched.h>
57
#include <linux/spinlock.h>
68
#include <linux/init.h>
79
#include <linux/list.h>
@@ -138,26 +140,54 @@ extern unsigned long vmalloc_nr_pages(void);
138140
static inline unsigned long vmalloc_nr_pages(void) { return 0; }
139141
#endif
140142

141-
extern void *vmalloc(unsigned long size) __alloc_size(1);
142-
extern void *vzalloc(unsigned long size) __alloc_size(1);
143-
extern void *vmalloc_user(unsigned long size) __alloc_size(1);
144-
extern void *vmalloc_node(unsigned long size, int node) __alloc_size(1);
145-
extern void *vzalloc_node(unsigned long size, int node) __alloc_size(1);
146-
extern void *vmalloc_32(unsigned long size) __alloc_size(1);
147-
extern void *vmalloc_32_user(unsigned long size) __alloc_size(1);
148-
extern void *__vmalloc(unsigned long size, gfp_t gfp_mask) __alloc_size(1);
149-
extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
143+
extern void *vmalloc_noprof(unsigned long size) __alloc_size(1);
144+
#define vmalloc(...) alloc_hooks(vmalloc_noprof(__VA_ARGS__))
145+
146+
extern void *vzalloc_noprof(unsigned long size) __alloc_size(1);
147+
#define vzalloc(...) alloc_hooks(vzalloc_noprof(__VA_ARGS__))
148+
149+
extern void *vmalloc_user_noprof(unsigned long size) __alloc_size(1);
150+
#define vmalloc_user(...) alloc_hooks(vmalloc_user_noprof(__VA_ARGS__))
151+
152+
extern void *vmalloc_node_noprof(unsigned long size, int node) __alloc_size(1);
153+
#define vmalloc_node(...) alloc_hooks(vmalloc_node_noprof(__VA_ARGS__))
154+
155+
extern void *vzalloc_node_noprof(unsigned long size, int node) __alloc_size(1);
156+
#define vzalloc_node(...) alloc_hooks(vzalloc_node_noprof(__VA_ARGS__))
157+
158+
extern void *vmalloc_32_noprof(unsigned long size) __alloc_size(1);
159+
#define vmalloc_32(...) alloc_hooks(vmalloc_32_noprof(__VA_ARGS__))
160+
161+
extern void *vmalloc_32_user_noprof(unsigned long size) __alloc_size(1);
162+
#define vmalloc_32_user(...) alloc_hooks(vmalloc_32_user_noprof(__VA_ARGS__))
163+
164+
extern void *__vmalloc_noprof(unsigned long size, gfp_t gfp_mask) __alloc_size(1);
165+
#define __vmalloc(...) alloc_hooks(__vmalloc_noprof(__VA_ARGS__))
166+
167+
extern void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
150168
unsigned long start, unsigned long end, gfp_t gfp_mask,
151169
pgprot_t prot, unsigned long vm_flags, int node,
152170
const void *caller) __alloc_size(1);
153-
void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
171+
#define __vmalloc_node_range(...) alloc_hooks(__vmalloc_node_range_noprof(__VA_ARGS__))
172+
173+
void *__vmalloc_node_noprof(unsigned long size, unsigned long align, gfp_t gfp_mask,
154174
int node, const void *caller) __alloc_size(1);
155-
void *vmalloc_huge(unsigned long size, gfp_t gfp_mask) __alloc_size(1);
175+
#define __vmalloc_node(...) alloc_hooks(__vmalloc_node_noprof(__VA_ARGS__))
176+
177+
void *vmalloc_huge_noprof(unsigned long size, gfp_t gfp_mask) __alloc_size(1);
178+
#define vmalloc_huge(...) alloc_hooks(vmalloc_huge_noprof(__VA_ARGS__))
179+
180+
extern void *__vmalloc_array_noprof(size_t n, size_t size, gfp_t flags) __alloc_size(1, 2);
181+
#define __vmalloc_array(...) alloc_hooks(__vmalloc_array_noprof(__VA_ARGS__))
182+
183+
extern void *vmalloc_array_noprof(size_t n, size_t size) __alloc_size(1, 2);
184+
#define vmalloc_array(...) alloc_hooks(vmalloc_array_noprof(__VA_ARGS__))
185+
186+
extern void *__vcalloc_noprof(size_t n, size_t size, gfp_t flags) __alloc_size(1, 2);
187+
#define __vcalloc(...) alloc_hooks(__vcalloc_noprof(__VA_ARGS__))
156188

157-
extern void *__vmalloc_array(size_t n, size_t size, gfp_t flags) __alloc_size(1, 2);
158-
extern void *vmalloc_array(size_t n, size_t size) __alloc_size(1, 2);
159-
extern void *__vcalloc(size_t n, size_t size, gfp_t flags) __alloc_size(1, 2);
160-
extern void *vcalloc(size_t n, size_t size) __alloc_size(1, 2);
189+
extern void *vcalloc_noprof(size_t n, size_t size) __alloc_size(1, 2);
190+
#define vcalloc(...) alloc_hooks(vcalloc_noprof(__VA_ARGS__))
161191

162192
extern void vfree(const void *addr);
163193
extern void vfree_atomic(const void *addr);

kernel/kallsyms_selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static struct test_item test_items[] = {
8282
ITEM_FUNC(kallsyms_test_func_static),
8383
ITEM_FUNC(kallsyms_test_func),
8484
ITEM_FUNC(kallsyms_test_func_weak),
85-
ITEM_FUNC(vmalloc),
85+
ITEM_FUNC(vmalloc_noprof),
8686
ITEM_FUNC(vfree),
8787
#ifdef CONFIG_KALLSYMS_ALL
8888
ITEM_DATA(kallsyms_test_var_bss_static),

mm/nommu.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,28 @@ void vfree(const void *addr)
137137
}
138138
EXPORT_SYMBOL(vfree);
139139

140-
void *__vmalloc(unsigned long size, gfp_t gfp_mask)
140+
void *__vmalloc_noprof(unsigned long size, gfp_t gfp_mask)
141141
{
142142
/*
143143
* You can't specify __GFP_HIGHMEM with kmalloc() since kmalloc()
144144
* returns only a logical address.
145145
*/
146-
return kmalloc(size, (gfp_mask | __GFP_COMP) & ~__GFP_HIGHMEM);
146+
return kmalloc_noprof(size, (gfp_mask | __GFP_COMP) & ~__GFP_HIGHMEM);
147147
}
148-
EXPORT_SYMBOL(__vmalloc);
148+
EXPORT_SYMBOL(__vmalloc_noprof);
149149

150-
void *__vmalloc_node_range(unsigned long size, unsigned long align,
150+
void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
151151
unsigned long start, unsigned long end, gfp_t gfp_mask,
152152
pgprot_t prot, unsigned long vm_flags, int node,
153153
const void *caller)
154154
{
155-
return __vmalloc(size, gfp_mask);
155+
return __vmalloc_noprof(size, gfp_mask);
156156
}
157157

158-
void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
158+
void *__vmalloc_node_noprof(unsigned long size, unsigned long align, gfp_t gfp_mask,
159159
int node, const void *caller)
160160
{
161-
return __vmalloc(size, gfp_mask);
161+
return __vmalloc_noprof(size, gfp_mask);
162162
}
163163

164164
static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)
@@ -179,11 +179,11 @@ static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)
179179
return ret;
180180
}
181181

182-
void *vmalloc_user(unsigned long size)
182+
void *vmalloc_user_noprof(unsigned long size)
183183
{
184184
return __vmalloc_user_flags(size, GFP_KERNEL | __GFP_ZERO);
185185
}
186-
EXPORT_SYMBOL(vmalloc_user);
186+
EXPORT_SYMBOL(vmalloc_user_noprof);
187187

188188
struct page *vmalloc_to_page(const void *addr)
189189
{
@@ -217,13 +217,13 @@ long vread_iter(struct iov_iter *iter, const char *addr, size_t count)
217217
* For tight control over page level allocator and protection flags
218218
* use __vmalloc() instead.
219219
*/
220-
void *vmalloc(unsigned long size)
220+
void *vmalloc_noprof(unsigned long size)
221221
{
222-
return __vmalloc(size, GFP_KERNEL);
222+
return __vmalloc_noprof(size, GFP_KERNEL);
223223
}
224-
EXPORT_SYMBOL(vmalloc);
224+
EXPORT_SYMBOL(vmalloc_noprof);
225225

226-
void *vmalloc_huge(unsigned long size, gfp_t gfp_mask) __weak __alias(__vmalloc);
226+
void *vmalloc_huge_noprof(unsigned long size, gfp_t gfp_mask) __weak __alias(__vmalloc_noprof);
227227

228228
/*
229229
* vzalloc - allocate virtually contiguous memory with zero fill
@@ -237,11 +237,11 @@ void *vmalloc_huge(unsigned long size, gfp_t gfp_mask) __weak __alias(__vmalloc)
237237
* For tight control over page level allocator and protection flags
238238
* use __vmalloc() instead.
239239
*/
240-
void *vzalloc(unsigned long size)
240+
void *vzalloc_noprof(unsigned long size)
241241
{
242-
return __vmalloc(size, GFP_KERNEL | __GFP_ZERO);
242+
return __vmalloc_noprof(size, GFP_KERNEL | __GFP_ZERO);
243243
}
244-
EXPORT_SYMBOL(vzalloc);
244+
EXPORT_SYMBOL(vzalloc_noprof);
245245

246246
/**
247247
* vmalloc_node - allocate memory on a specific node
@@ -254,11 +254,11 @@ EXPORT_SYMBOL(vzalloc);
254254
* For tight control over page level allocator and protection flags
255255
* use __vmalloc() instead.
256256
*/
257-
void *vmalloc_node(unsigned long size, int node)
257+
void *vmalloc_node_noprof(unsigned long size, int node)
258258
{
259-
return vmalloc(size);
259+
return vmalloc_noprof(size);
260260
}
261-
EXPORT_SYMBOL(vmalloc_node);
261+
EXPORT_SYMBOL(vmalloc_node_noprof);
262262

263263
/**
264264
* vzalloc_node - allocate memory on a specific node with zero fill
@@ -272,11 +272,11 @@ EXPORT_SYMBOL(vmalloc_node);
272272
* For tight control over page level allocator and protection flags
273273
* use __vmalloc() instead.
274274
*/
275-
void *vzalloc_node(unsigned long size, int node)
275+
void *vzalloc_node_noprof(unsigned long size, int node)
276276
{
277-
return vzalloc(size);
277+
return vzalloc_noprof(size);
278278
}
279-
EXPORT_SYMBOL(vzalloc_node);
279+
EXPORT_SYMBOL(vzalloc_node_noprof);
280280

281281
/**
282282
* vmalloc_32 - allocate virtually contiguous memory (32bit addressable)
@@ -285,11 +285,11 @@ EXPORT_SYMBOL(vzalloc_node);
285285
* Allocate enough 32bit PA addressable pages to cover @size from the
286286
* page level allocator and map them into contiguous kernel virtual space.
287287
*/
288-
void *vmalloc_32(unsigned long size)
288+
void *vmalloc_32_noprof(unsigned long size)
289289
{
290-
return __vmalloc(size, GFP_KERNEL);
290+
return __vmalloc_noprof(size, GFP_KERNEL);
291291
}
292-
EXPORT_SYMBOL(vmalloc_32);
292+
EXPORT_SYMBOL(vmalloc_32_noprof);
293293

294294
/**
295295
* vmalloc_32_user - allocate zeroed virtually contiguous 32bit memory
@@ -301,15 +301,15 @@ EXPORT_SYMBOL(vmalloc_32);
301301
* VM_USERMAP is set on the corresponding VMA so that subsequent calls to
302302
* remap_vmalloc_range() are permissible.
303303
*/
304-
void *vmalloc_32_user(unsigned long size)
304+
void *vmalloc_32_user_noprof(unsigned long size)
305305
{
306306
/*
307307
* We'll have to sort out the ZONE_DMA bits for 64-bit,
308308
* but for now this can simply use vmalloc_user() directly.
309309
*/
310-
return vmalloc_user(size);
310+
return vmalloc_user_noprof(size);
311311
}
312-
EXPORT_SYMBOL(vmalloc_32_user);
312+
EXPORT_SYMBOL(vmalloc_32_user_noprof);
313313

314314
void *vmap(struct page **pages, unsigned int count, unsigned long flags, pgprot_t prot)
315315
{

mm/util.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ void *kvmalloc_node_noprof(size_t size, gfp_t flags, int node)
656656
* about the resulting pointer, and cannot play
657657
* protection games.
658658
*/
659-
return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
659+
return __vmalloc_node_range_noprof(size, 1, VMALLOC_START, VMALLOC_END,
660660
flags, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP,
661661
node, __builtin_return_address(0));
662662
}
@@ -720,49 +720,49 @@ EXPORT_SYMBOL(kvrealloc_noprof);
720720
* @size: element size.
721721
* @flags: the type of memory to allocate (see kmalloc).
722722
*/
723-
void *__vmalloc_array(size_t n, size_t size, gfp_t flags)
723+
void *__vmalloc_array_noprof(size_t n, size_t size, gfp_t flags)
724724
{
725725
size_t bytes;
726726

727727
if (unlikely(check_mul_overflow(n, size, &bytes)))
728728
return NULL;
729729
return __vmalloc(bytes, flags);
730730
}
731-
EXPORT_SYMBOL(__vmalloc_array);
731+
EXPORT_SYMBOL(__vmalloc_array_noprof);
732732

733733
/**
734734
* vmalloc_array - allocate memory for a virtually contiguous array.
735735
* @n: number of elements.
736736
* @size: element size.
737737
*/
738-
void *vmalloc_array(size_t n, size_t size)
738+
void *vmalloc_array_noprof(size_t n, size_t size)
739739
{
740740
return __vmalloc_array(n, size, GFP_KERNEL);
741741
}
742-
EXPORT_SYMBOL(vmalloc_array);
742+
EXPORT_SYMBOL(vmalloc_array_noprof);
743743

744744
/**
745745
* __vcalloc - allocate and zero memory for a virtually contiguous array.
746746
* @n: number of elements.
747747
* @size: element size.
748748
* @flags: the type of memory to allocate (see kmalloc).
749749
*/
750-
void *__vcalloc(size_t n, size_t size, gfp_t flags)
750+
void *__vcalloc_noprof(size_t n, size_t size, gfp_t flags)
751751
{
752752
return __vmalloc_array(n, size, flags | __GFP_ZERO);
753753
}
754-
EXPORT_SYMBOL(__vcalloc);
754+
EXPORT_SYMBOL(__vcalloc_noprof);
755755

756756
/**
757757
* vcalloc - allocate and zero memory for a virtually contiguous array.
758758
* @n: number of elements.
759759
* @size: element size.
760760
*/
761-
void *vcalloc(size_t n, size_t size)
761+
void *vcalloc_noprof(size_t n, size_t size)
762762
{
763763
return __vmalloc_array(n, size, GFP_KERNEL | __GFP_ZERO);
764764
}
765-
EXPORT_SYMBOL(vcalloc);
765+
EXPORT_SYMBOL(vcalloc_noprof);
766766

767767
struct anon_vma *folio_anon_vma(struct folio *folio)
768768
{

0 commit comments

Comments
 (0)