diff options
author | Andrey Ryabinin <a.ryabinin@samsung.com> | 2014-08-06 19:04:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 21:01:15 -0400 |
commit | 928cec9cd6db53a68f54bc9ef1c54c674ba1c6bb (patch) | |
tree | 109222d5f88dda34aafe9e2946b426da5331c368 /mm/util.c | |
parent | 54266640709a24c9844245d0d9f36b9cb1f31326 (diff) |
mm: move slab related stuff from util.c to slab_common.c
Functions krealloc(), __krealloc(), kzfree() belongs to slab API, so
should be placed in slab_common.c
Also move slab allocator's tracepoints defenitions to slab_common.c No
functional changes here.
Signed-off-by: Andrey Ryabinin <a.ryabinin@samsung.com>
Acked-by: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/util.c')
-rw-r--r-- | mm/util.c | 102 |
1 files changed, 0 insertions, 102 deletions
@@ -16,9 +16,6 @@ | |||
16 | 16 | ||
17 | #include "internal.h" | 17 | #include "internal.h" |
18 | 18 | ||
19 | #define CREATE_TRACE_POINTS | ||
20 | #include <trace/events/kmem.h> | ||
21 | |||
22 | /** | 19 | /** |
23 | * kstrdup - allocate space for and copy an existing string | 20 | * kstrdup - allocate space for and copy an existing string |
24 | * @s: the string to duplicate | 21 | * @s: the string to duplicate |
@@ -112,97 +109,6 @@ void *memdup_user(const void __user *src, size_t len) | |||
112 | } | 109 | } |
113 | EXPORT_SYMBOL(memdup_user); | 110 | EXPORT_SYMBOL(memdup_user); |
114 | 111 | ||
115 | static __always_inline void *__do_krealloc(const void *p, size_t new_size, | ||
116 | gfp_t flags) | ||
117 | { | ||
118 | void *ret; | ||
119 | size_t ks = 0; | ||
120 | |||
121 | if (p) | ||
122 | ks = ksize(p); | ||
123 | |||
124 | if (ks >= new_size) | ||
125 | return (void *)p; | ||
126 | |||
127 | ret = kmalloc_track_caller(new_size, flags); | ||
128 | if (ret && p) | ||
129 | memcpy(ret, p, ks); | ||
130 | |||
131 | return ret; | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * __krealloc - like krealloc() but don't free @p. | ||
136 | * @p: object to reallocate memory for. | ||
137 | * @new_size: how many bytes of memory are required. | ||
138 | * @flags: the type of memory to allocate. | ||
139 | * | ||
140 | * This function is like krealloc() except it never frees the originally | ||
141 | * allocated buffer. Use this if you don't want to free the buffer immediately | ||
142 | * like, for example, with RCU. | ||
143 | */ | ||
144 | void *__krealloc(const void *p, size_t new_size, gfp_t flags) | ||
145 | { | ||
146 | if (unlikely(!new_size)) | ||
147 | return ZERO_SIZE_PTR; | ||
148 | |||
149 | return __do_krealloc(p, new_size, flags); | ||
150 | |||
151 | } | ||
152 | EXPORT_SYMBOL(__krealloc); | ||
153 | |||
154 | /** | ||
155 | * krealloc - reallocate memory. The contents will remain unchanged. | ||
156 | * @p: object to reallocate memory for. | ||
157 | * @new_size: how many bytes of memory are required. | ||
158 | * @flags: the type of memory to allocate. | ||
159 | * | ||
160 | * The contents of the object pointed to are preserved up to the | ||
161 | * lesser of the new and old sizes. If @p is %NULL, krealloc() | ||
162 | * behaves exactly like kmalloc(). If @new_size is 0 and @p is not a | ||
163 | * %NULL pointer, the object pointed to is freed. | ||
164 | */ | ||
165 | void *krealloc(const void *p, size_t new_size, gfp_t flags) | ||
166 | { | ||
167 | void *ret; | ||
168 | |||
169 | if (unlikely(!new_size)) { | ||
170 | kfree(p); | ||
171 | return ZERO_SIZE_PTR; | ||
172 | } | ||
173 | |||
174 | ret = __do_krealloc(p, new_size, flags); | ||
175 | if (ret && p != ret) | ||
176 | kfree(p); | ||
177 | |||
178 | return ret; | ||
179 | } | ||
180 | EXPORT_SYMBOL(krealloc); | ||
181 | |||
182 | /** | ||
183 | * kzfree - like kfree but zero memory | ||
184 | * @p: object to free memory of | ||
185 | * | ||
186 | * The memory of the object @p points to is zeroed before freed. | ||
187 | * If @p is %NULL, kzfree() does nothing. | ||
188 | * | ||
189 | * Note: this function zeroes the whole allocated buffer which can be a good | ||
190 | * deal bigger than the requested buffer size passed to kmalloc(). So be | ||
191 | * careful when using this function in performance sensitive code. | ||
192 | */ | ||
193 | void kzfree(const void *p) | ||
194 | { | ||
195 | size_t ks; | ||
196 | void *mem = (void *)p; | ||
197 | |||
198 | if (unlikely(ZERO_OR_NULL_PTR(mem))) | ||
199 | return; | ||
200 | ks = ksize(mem); | ||
201 | memset(mem, 0, ks); | ||
202 | kfree(mem); | ||
203 | } | ||
204 | EXPORT_SYMBOL(kzfree); | ||
205 | |||
206 | /* | 112 | /* |
207 | * strndup_user - duplicate an existing string from user space | 113 | * strndup_user - duplicate an existing string from user space |
208 | * @s: The string to duplicate | 114 | * @s: The string to duplicate |
@@ -504,11 +410,3 @@ out_mm: | |||
504 | out: | 410 | out: |
505 | return res; | 411 | return res; |
506 | } | 412 | } |
507 | |||
508 | /* Tracepoints definitions. */ | ||
509 | EXPORT_TRACEPOINT_SYMBOL(kmalloc); | ||
510 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); | ||
511 | EXPORT_TRACEPOINT_SYMBOL(kmalloc_node); | ||
512 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc_node); | ||
513 | EXPORT_TRACEPOINT_SYMBOL(kfree); | ||
514 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free); | ||