C1 [1/2] Move kmalloc_node functions to common code
Subsystems (2)
The kmalloc_node functions of all slab allcoators are similar now so lets move them into slab.h. This requires some function naming changes in slob.
include/linux/slab.h +61 -0
@@ -289,6 +289,50 @@ static __always_inline int kmalloc_index }#endif /* !CONFIG_SLOB */ +void *__kmalloc (size_t size,gfp_t flags); +void *kmem_cache_alloc (struct kmem_cache *,gfp_t flags); + +#ifdef CONFIG_NUMA +void *__kmalloc_node (size_t size,gfp_t flags,int node); +void *kmem_cache_alloc_node (struct kmem_cache *,gfp_t flags,int node); +#else +static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node) +{ +return __kmalloc (size, flags); +} + +static __always_inline void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t flags, int node) +{ +return kmem_cache_alloc (s, flags); +} +#endif + +#ifdef CONFIG_TRACING + +#ifdef CONFIG_NUMA +extern void *kmem_cache_alloc_node_trace (struct kmem_cache *s, +gfp_t gfpflags, +int node,size_t size); +#else +static __always_inline void * +kmem_cache_alloc_node_trace (struct kmem_cache *s, +gfp_t gfpflags, +int node,size_t size) +{ +return kmem_cache_alloc_trace (s, gfpflags, size); +} +#endif /* CONFIG_NUMA */ + +#else +static __always_inline void * +kmem_cache_alloc_node_trace (struct kmem_cache *s, +gfp_t gfpflags, +int node,size_t size) +{ +return kmem_cache_alloc_node (s, gfpflags, node); +} +#endif /* CONFIG_TRACING */ +#ifdef CONFIG_SLAB #include <linux/slab_def.h> #endif
@@ -321,6 +365,23 @@ static __always_inline int kmalloc_size(return 0 ; } +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) +{ +#ifndef CONFIG_SLOB +if (__builtin_constant_p (size) && + size <=KMALLOC_MAX_CACHE_SIZE && !(flags &SLAB_CACHE_DMA )) { +int i =kmalloc_index (size); + +if (!i) +return ZERO_SIZE_PTR ; + +return kmem_cache_alloc_node_trace (kmalloc_caches[i], + flags, node, size); + } +#endif +return __kmalloc_node (size, flags, node); +} +/* * Setting ARCH_SLAB_MINALIGN in arch headers allows a different alignment. * Intended for arches that get misalignment faults even for 64 bit integer
include/linux/slub_def.h +0 -37
@@ -104,9 +104,6 @@ struct kmem_cache {struct kmem_cache_node *node[MAX_NUMNODES ]; }; -void *kmem_cache_alloc (struct kmem_cache *,gfp_t ); -void *__kmalloc (size_t size,gfp_t flags); - static __always_inline void *kmalloc_order (size_t size,gfp_t flags,unsigned int order) {
@@ -174,38 +171,4 @@ static __always_inline void *kmalloc(siz return __kmalloc(size, flags); } -#ifdef CONFIG_NUMA -void *__kmalloc_node (size_t size,gfp_t flags,int node); -void *kmem_cache_alloc_node (struct kmem_cache *,gfp_t flags,int node); - -#ifdef CONFIG_TRACING -extern void *kmem_cache_alloc_node_trace (struct kmem_cache *s, -gfp_t gfpflags, -int node,size_t size); -#else -static __always_inline void * -kmem_cache_alloc_node_trace (struct kmem_cache *s, -gfp_t gfpflags, -int node,size_t size) -{ -return kmem_cache_alloc_node (s, gfpflags, node); -} -#endif - -static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) -{ -if (__builtin_constant_p (size) && - size <=KMALLOC_MAX_CACHE_SIZE && !(flags &GFP_DMA )) { -int index =kmalloc_index (size); - -if (!index) -return ZERO_SIZE_PTR ; - -return kmem_cache_alloc_node_trace (kmalloc_caches[index], - flags, node, size); - } -return __kmalloc_node (size, flags, node); -} -#endif -#endif /* _LINUX_SLUB_DEF_H */
include/linux/slab_def.h +0 -52
62 lines not on this page · raw message
include/linux/slob_def.h +0 -22
@@ -1,31 +1,9 @@#ifndef __LINUX_SLOB_DEF_H#define __LINUX_SLOB_DEF_H -#include <linux/numa.h> - -void *kmem_cache_alloc_node (struct kmem_cache *,gfp_t flags,int node); - -static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep, -gfp_t flags) -{ -return kmem_cache_alloc_node (cachep, flags,NUMA_NO_NODE ); -} - -void *__kmalloc_node (size_t size,gfp_t flags,int node); - -static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) -{ -return __kmalloc_node (size, flags, node); -} - static __always_inline void *kmalloc(size_t size, gfp_t flags) {return __kmalloc_node (size, flags,NUMA_NO_NODE ); } -static __always_inline void *__kmalloc(size_t size, gfp_t flags) -{ -return kmalloc (size, flags); -} -#endif /* __LINUX_SLOB_DEF_H */
mm/slob.c +24 -4
@@ -462,11 +462,11 @@ __do_kmalloc_node(size_t size, gfp_t gfpreturn ret; } -void *__kmalloc_node (size_t size,gfp_t gfp,int node) +void *__kmalloc (size_t size,gfp_t gfp) { -return __do_kmalloc_node (size, gfp, node, _RET_IP_); +return __do_kmalloc_node (size, gfp,NUMA_NO_NODE , _RET_IP_); } -EXPORT_SYMBOL (__kmalloc_node); +EXPORT_SYMBOL (__kmalloc);#ifdef CONFIG_TRACING void *__kmalloc_track_caller (size_t size,gfp_t gfp,unsigned long caller)
@@ -534,7 +534,7 @@ int __kmem_cache_create(struct kmem_cachreturn 0 ; } -void *kmem_cache_alloc_node (struct kmem_cache *c,gfp_t flags,int node) +void *slob_alloc_node (struct kmem_cache *c,gfp_t flags,int node) {void *b;
@@ -560,7 +560,27 @@ void *kmem_cache_alloc_node(struct kmem_kmemleak_alloc_recursive (b, c->size,1 , c->flags, flags);return b; } +EXPORT_SYMBOL (slob_alloc_node); + +void *kmem_cache_alloc (struct kmem_cache *cachep,gfp_t flags) +{ +return slob_alloc_node (cachep, flags,NUMA_NO_NODE ); +} +EXPORT_SYMBOL (kmem_cache_alloc); + +#ifdef CONFIG_NUMA +void *__kmalloc_node (size_t size,gfp_t gfp,int node) +{ +return __do_kmalloc_node (size, gfp, node, _RET_IP_); +} +EXPORT_SYMBOL (__kmalloc_node); + +void *kmem_cache_alloc_node (struct kmem_cache *cachep,gfp_t gfp,int node) +{ +return slob_alloc_node (cachep, gfp, node); +}EXPORT_SYMBOL (kmem_cache_alloc_node); +#endif static void __kmem_cache_free (void *b,int size) {
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
C1 [2/2] Move kmalloc definitions to slab.h
In reply to a message not in the archiveAll the kmallocs are mostly doing the same. Unify them.
slob_def.h becomes empty. So remove it.
include/linux/slab.h +66 -5
@@ -4,6 +4,8 @@* (C) SGI 2006, Christoph Lameter * Cleaned up and restructured to ease the addition of alternative * implementations of SLAB allocators. +* (C) Linux Foundation 2008-2013 +* Unified interface for all slab allocators */ #ifndef _LINUX_SLAB_H
@@ -94,6 +96,7 @@#define ZERO_OR_NULL_PTR (x) ((unsigned long)(x) <= \ (unsigned long)ZERO_SIZE_PTR) +#include <linux/kmemleak.h> struct mem_cgroup ;/*
@@ -308,6 +311,7 @@ static __always_inline void *kmem_cache_#endif #ifdef CONFIG_TRACING +extern void *kmem_cache_alloc_trace (struct kmem_cache *,gfp_t ,size_t );#ifdef CONFIG_NUMA extern void *kmem_cache_alloc_node_trace(struct kmem_cache *s,
@@ -316,14 +320,20 @@ extern void *kmem_cache_alloc_node_trace#else static __always_inline void *kmem_cache_alloc_node_trace (struct kmem_cache *s, -gfp_t gfpflags, -int node,size_t size) +gfp_t gfpflags, +int node,size_t size) {return kmem_cache_alloc_trace (s, gfpflags, size); }#endif /* CONFIG_NUMA */ -#else +#else /* CONFIG_TRACING */ +static __always_inline void *kmem_cache_alloc_trace(struct kmem_cache *s, +gfp_t flags,size_t size) +{ +return kmem_cache_alloc (s, flags); +} + static __always_inline void * kmem_cache_alloc_node_trace(struct kmem_cache *s, gfp_t gfpflags,
@@ -341,10 +351,61 @@ kmem_cache_alloc_node_trace(struct kmem_#include <linux/slub_def.h> #endif -#ifdef CONFIG_SLOB -#include <linux/slob_def.h> +static __always_inline void * +kmalloc_order (size_t size,gfp_t flags,unsigned int order) +{ +void *ret; + + flags |= (__GFP_COMP | __GFP_KMEMCG); + ret = (void *)__get_free_pages (flags, order); +kmemleak_alloc (ret, size,1 , flags); +return ret; +} + +#ifdef CONFIG_TRACING +extern void *kmalloc_order_trace (size_t size,gfp_t flags,unsigned int order); +#else +static __always_inline void * +kmalloc_order_trace (size_t size,gfp_t flags,unsigned int order) +{ +return kmalloc_order (size, flags, order); +}#endif +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) +{ +unsigned int order =get_order (size); +return kmalloc_order_trace (size, flags, order); +} + +/** +* kmalloc - allocate memory +* @size: how many bytes of memory are required. +* @flags: the type of memory to allocate (see kcalloc). +* +* kmalloc is the normal method of allocating memory +* for objects smaller than page size in the kernel. +*/ +static __always_inline void *kmalloc(size_t size, gfp_t flags) +{ +if (__builtin_constant_p (size)) { +if (size >KMALLOC_MAX_CACHE_SIZE ) +return kmalloc_large (size, flags); +#ifndef CONFIG_SLOB +if (!(flags &GFP_DMA )) { +int index =kmalloc_index (size); + +if (!index) +return ZERO_SIZE_PTR ; + +return kmem_cache_alloc_trace (kmalloc_caches[index], + flags, size); + } +#endif + } +return __kmalloc (size, flags); +} +/* * Determine size used for the nth kmalloc cache. * return size or 0 if a kmalloc cache for that
include/linux/slab_def.h +0 -40
@@ -102,44 +102,4 @@ struct kmem_cache { */ }; -#ifdef CONFIG_TRACING -extern void *kmem_cache_alloc_trace (struct kmem_cache *,gfp_t ,size_t ); -#else -static __always_inline void * -kmem_cache_alloc_trace (struct kmem_cache *cachep,gfp_t flags,size_t size) -{ -return kmem_cache_alloc (cachep, flags); -} -#endif - -static __always_inline void *kmalloc(size_t size, gfp_t flags) -{ -struct kmem_cache *cachep; -void *ret; - -if (__builtin_constant_p (size)) { -int i; - -if (!size) -return ZERO_SIZE_PTR ; - -if (WARN_ON_ONCE (size >KMALLOC_MAX_SIZE )) -return NULL ; - - i =kmalloc_index (size); - -#ifdef CONFIG_ZONE_DMA -if (flags &GFP_DMA ) - cachep = kmalloc_dma_caches[i]; - else -#endif - cachep = kmalloc_caches[i]; - - ret =kmem_cache_alloc_trace (cachep, flags, size); - -return ret; - } -return __kmalloc (size, flags); -} -#endif /* _LINUX_SLAB_DEF_H */
include/linux/slub_def.h +0 -56
72 lines not on this page · raw message
include/linux/slob_def.h deleted +0 -9
@@ -1,9 +0,0 @@ -#ifndef __LINUX_SLOB_DEF_H -#define __LINUX_SLOB_DEF_H - -static __always_inline void *kmalloc(size_t size, gfp_t flags) -{ -return __kmalloc_node (size, flags,NUMA_NO_NODE ); -} - -#endif /* __LINUX_SLOB_DEF_H */
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>