diff options
Diffstat (limited to 'include/linux/slab_def.h')
-rw-r--r-- | include/linux/slab_def.h | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h index 6ca6a7b66d75..5ac9b0bcaf9a 100644 --- a/include/linux/slab_def.h +++ b/include/linux/slab_def.h | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */ | 14 | #include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */ |
15 | #include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */ | 15 | #include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */ |
16 | #include <linux/compiler.h> | 16 | #include <linux/compiler.h> |
17 | #include <trace/kmemtrace.h> | ||
17 | 18 | ||
18 | /* Size description struct for general caches. */ | 19 | /* Size description struct for general caches. */ |
19 | struct cache_sizes { | 20 | struct cache_sizes { |
@@ -28,8 +29,26 @@ extern struct cache_sizes malloc_sizes[]; | |||
28 | void *kmem_cache_alloc(struct kmem_cache *, gfp_t); | 29 | void *kmem_cache_alloc(struct kmem_cache *, gfp_t); |
29 | void *__kmalloc(size_t size, gfp_t flags); | 30 | void *__kmalloc(size_t size, gfp_t flags); |
30 | 31 | ||
31 | static inline void *kmalloc(size_t size, gfp_t flags) | 32 | #ifdef CONFIG_KMEMTRACE |
33 | extern void *kmem_cache_alloc_notrace(struct kmem_cache *cachep, gfp_t flags); | ||
34 | extern size_t slab_buffer_size(struct kmem_cache *cachep); | ||
35 | #else | ||
36 | static __always_inline void * | ||
37 | kmem_cache_alloc_notrace(struct kmem_cache *cachep, gfp_t flags) | ||
32 | { | 38 | { |
39 | return kmem_cache_alloc(cachep, flags); | ||
40 | } | ||
41 | static inline size_t slab_buffer_size(struct kmem_cache *cachep) | ||
42 | { | ||
43 | return 0; | ||
44 | } | ||
45 | #endif | ||
46 | |||
47 | static __always_inline void *kmalloc(size_t size, gfp_t flags) | ||
48 | { | ||
49 | struct kmem_cache *cachep; | ||
50 | void *ret; | ||
51 | |||
33 | if (__builtin_constant_p(size)) { | 52 | if (__builtin_constant_p(size)) { |
34 | int i = 0; | 53 | int i = 0; |
35 | 54 | ||
@@ -47,10 +66,17 @@ static inline void *kmalloc(size_t size, gfp_t flags) | |||
47 | found: | 66 | found: |
48 | #ifdef CONFIG_ZONE_DMA | 67 | #ifdef CONFIG_ZONE_DMA |
49 | if (flags & GFP_DMA) | 68 | if (flags & GFP_DMA) |
50 | return kmem_cache_alloc(malloc_sizes[i].cs_dmacachep, | 69 | cachep = malloc_sizes[i].cs_dmacachep; |
51 | flags); | 70 | else |
52 | #endif | 71 | #endif |
53 | return kmem_cache_alloc(malloc_sizes[i].cs_cachep, flags); | 72 | cachep = malloc_sizes[i].cs_cachep; |
73 | |||
74 | ret = kmem_cache_alloc_notrace(cachep, flags); | ||
75 | |||
76 | trace_kmalloc(_THIS_IP_, ret, | ||
77 | size, slab_buffer_size(cachep), flags); | ||
78 | |||
79 | return ret; | ||
54 | } | 80 | } |
55 | return __kmalloc(size, flags); | 81 | return __kmalloc(size, flags); |
56 | } | 82 | } |
@@ -59,8 +85,25 @@ found: | |||
59 | extern void *__kmalloc_node(size_t size, gfp_t flags, int node); | 85 | extern void *__kmalloc_node(size_t size, gfp_t flags, int node); |
60 | extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); | 86 | extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); |
61 | 87 | ||
62 | static inline void *kmalloc_node(size_t size, gfp_t flags, int node) | 88 | #ifdef CONFIG_KMEMTRACE |
89 | extern void *kmem_cache_alloc_node_notrace(struct kmem_cache *cachep, | ||
90 | gfp_t flags, | ||
91 | int nodeid); | ||
92 | #else | ||
93 | static __always_inline void * | ||
94 | kmem_cache_alloc_node_notrace(struct kmem_cache *cachep, | ||
95 | gfp_t flags, | ||
96 | int nodeid) | ||
97 | { | ||
98 | return kmem_cache_alloc_node(cachep, flags, nodeid); | ||
99 | } | ||
100 | #endif | ||
101 | |||
102 | static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) | ||
63 | { | 103 | { |
104 | struct kmem_cache *cachep; | ||
105 | void *ret; | ||
106 | |||
64 | if (__builtin_constant_p(size)) { | 107 | if (__builtin_constant_p(size)) { |
65 | int i = 0; | 108 | int i = 0; |
66 | 109 | ||
@@ -78,11 +121,18 @@ static inline void *kmalloc_node(size_t size, gfp_t flags, int node) | |||
78 | found: | 121 | found: |
79 | #ifdef CONFIG_ZONE_DMA | 122 | #ifdef CONFIG_ZONE_DMA |
80 | if (flags & GFP_DMA) | 123 | if (flags & GFP_DMA) |
81 | return kmem_cache_alloc_node(malloc_sizes[i].cs_dmacachep, | 124 | cachep = malloc_sizes[i].cs_dmacachep; |
82 | flags, node); | 125 | else |
83 | #endif | 126 | #endif |
84 | return kmem_cache_alloc_node(malloc_sizes[i].cs_cachep, | 127 | cachep = malloc_sizes[i].cs_cachep; |
85 | flags, node); | 128 | |
129 | ret = kmem_cache_alloc_node_notrace(cachep, flags, node); | ||
130 | |||
131 | trace_kmalloc_node(_THIS_IP_, ret, | ||
132 | size, slab_buffer_size(cachep), | ||
133 | flags, node); | ||
134 | |||
135 | return ret; | ||
86 | } | 136 | } |
87 | return __kmalloc_node(size, flags, node); | 137 | return __kmalloc_node(size, flags, node); |
88 | } | 138 | } |