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/slab_common.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/slab_common.c')
-rw-r--r-- | mm/slab_common.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/mm/slab_common.c b/mm/slab_common.c index d31c4bacc6a2..d319502b2403 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c | |||
@@ -19,6 +19,8 @@ | |||
19 | #include <asm/tlbflush.h> | 19 | #include <asm/tlbflush.h> |
20 | #include <asm/page.h> | 20 | #include <asm/page.h> |
21 | #include <linux/memcontrol.h> | 21 | #include <linux/memcontrol.h> |
22 | |||
23 | #define CREATE_TRACE_POINTS | ||
22 | #include <trace/events/kmem.h> | 24 | #include <trace/events/kmem.h> |
23 | 25 | ||
24 | #include "slab.h" | 26 | #include "slab.h" |
@@ -787,3 +789,102 @@ static int __init slab_proc_init(void) | |||
787 | } | 789 | } |
788 | module_init(slab_proc_init); | 790 | module_init(slab_proc_init); |
789 | #endif /* CONFIG_SLABINFO */ | 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); | ||