Commit 928cec9cd6db53a68f54bc9ef1c54c674ba1c6bb
Committed by
Linus Torvalds
1 parent
5426664070
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
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>
Showing 2 changed files with 101 additions and 102 deletions Side-by-side Diff
mm/slab_common.c
... | ... | @@ -19,6 +19,8 @@ |
19 | 19 | #include <asm/tlbflush.h> |
20 | 20 | #include <asm/page.h> |
21 | 21 | #include <linux/memcontrol.h> |
22 | + | |
23 | +#define CREATE_TRACE_POINTS | |
22 | 24 | #include <trace/events/kmem.h> |
23 | 25 | |
24 | 26 | #include "slab.h" |
... | ... | @@ -787,4 +789,103 @@ |
787 | 789 | } |
788 | 790 | module_init(slab_proc_init); |
789 | 791 | #endif /* CONFIG_SLABINFO */ |
792 | + | |
793 | +static __always_inline void *__do_krealloc(const void *p, size_t new_size, | |
794 | + gfp_t flags) | |
795 | +{ | |
796 | + void *ret; | |
797 | + size_t ks = 0; | |
798 | + | |
799 | + if (p) | |
800 | + ks = ksize(p); | |
801 | + | |
802 | + if (ks >= new_size) | |
803 | + return (void *)p; | |
804 | + | |
805 | + ret = kmalloc_track_caller(new_size, flags); | |
806 | + if (ret && p) | |
807 | + memcpy(ret, p, ks); | |
808 | + | |
809 | + return ret; | |
810 | +} | |
811 | + | |
812 | +/** | |
813 | + * __krealloc - like krealloc() but don't free @p. | |
814 | + * @p: object to reallocate memory for. | |
815 | + * @new_size: how many bytes of memory are required. | |
816 | + * @flags: the type of memory to allocate. | |
817 | + * | |
818 | + * This function is like krealloc() except it never frees the originally | |
819 | + * allocated buffer. Use this if you don't want to free the buffer immediately | |
820 | + * like, for example, with RCU. | |
821 | + */ | |
822 | +void *__krealloc(const void *p, size_t new_size, gfp_t flags) | |
823 | +{ | |
824 | + if (unlikely(!new_size)) | |
825 | + return ZERO_SIZE_PTR; | |
826 | + | |
827 | + return __do_krealloc(p, new_size, flags); | |
828 | + | |
829 | +} | |
830 | +EXPORT_SYMBOL(__krealloc); | |
831 | + | |
832 | +/** | |
833 | + * krealloc - reallocate memory. The contents will remain unchanged. | |
834 | + * @p: object to reallocate memory for. | |
835 | + * @new_size: how many bytes of memory are required. | |
836 | + * @flags: the type of memory to allocate. | |
837 | + * | |
838 | + * The contents of the object pointed to are preserved up to the | |
839 | + * lesser of the new and old sizes. If @p is %NULL, krealloc() | |
840 | + * behaves exactly like kmalloc(). If @new_size is 0 and @p is not a | |
841 | + * %NULL pointer, the object pointed to is freed. | |
842 | + */ | |
843 | +void *krealloc(const void *p, size_t new_size, gfp_t flags) | |
844 | +{ | |
845 | + void *ret; | |
846 | + | |
847 | + if (unlikely(!new_size)) { | |
848 | + kfree(p); | |
849 | + return ZERO_SIZE_PTR; | |
850 | + } | |
851 | + | |
852 | + ret = __do_krealloc(p, new_size, flags); | |
853 | + if (ret && p != ret) | |
854 | + kfree(p); | |
855 | + | |
856 | + return ret; | |
857 | +} | |
858 | +EXPORT_SYMBOL(krealloc); | |
859 | + | |
860 | +/** | |
861 | + * kzfree - like kfree but zero memory | |
862 | + * @p: object to free memory of | |
863 | + * | |
864 | + * The memory of the object @p points to is zeroed before freed. | |
865 | + * If @p is %NULL, kzfree() does nothing. | |
866 | + * | |
867 | + * Note: this function zeroes the whole allocated buffer which can be a good | |
868 | + * deal bigger than the requested buffer size passed to kmalloc(). So be | |
869 | + * careful when using this function in performance sensitive code. | |
870 | + */ | |
871 | +void kzfree(const void *p) | |
872 | +{ | |
873 | + size_t ks; | |
874 | + void *mem = (void *)p; | |
875 | + | |
876 | + if (unlikely(ZERO_OR_NULL_PTR(mem))) | |
877 | + return; | |
878 | + ks = ksize(mem); | |
879 | + memset(mem, 0, ks); | |
880 | + kfree(mem); | |
881 | +} | |
882 | +EXPORT_SYMBOL(kzfree); | |
883 | + | |
884 | +/* Tracepoints definitions. */ | |
885 | +EXPORT_TRACEPOINT_SYMBOL(kmalloc); | |
886 | +EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); | |
887 | +EXPORT_TRACEPOINT_SYMBOL(kmalloc_node); | |
888 | +EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc_node); | |
889 | +EXPORT_TRACEPOINT_SYMBOL(kfree); | |
890 | +EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free); |
mm/util.c
... | ... | @@ -16,9 +16,6 @@ |
16 | 16 | |
17 | 17 | #include "internal.h" |
18 | 18 | |
19 | -#define CREATE_TRACE_POINTS | |
20 | -#include <trace/events/kmem.h> | |
21 | - | |
22 | 19 | /** |
23 | 20 | * kstrdup - allocate space for and copy an existing string |
24 | 21 | * @s: the string to duplicate |
... | ... | @@ -112,97 +109,6 @@ |
112 | 109 | } |
113 | 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 | 113 | * strndup_user - duplicate an existing string from user space |
208 | 114 | * @s: The string to duplicate |
... | ... | @@ -504,12 +410,4 @@ |
504 | 410 | out: |
505 | 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); |