slab: extract alloc_node_cache
PATCH 2/3 slab: extract alloc_node_cache
From: Pekka Enberg <[email protected]>
This patch removes duplicate code by extracting node_cache allocation to alloc_node_cache function.
Signed-off-by Pekka Enberg <[email protected]>
---
mm/slab.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
mm/slab.c +15 -14
@@ -347,6 +347,16 @@ static void node_cache_init(struct node_ parent->free_touched =0 ; } +static struct node_cache *alloc_node_cache (int node) +{ +struct node_cache *node_cache; + + node_cache =kmalloc_node (sizeof (*node_cache),GFP_KERNEL , node); +if (node_cache) +node_cache_init (node_cache); +return node_cache; +} +#define MAKE_LIST (cachep, listp, slab, nodeid) \ do { \ INIT_LIST_HEAD(listp); \
@@ -907,7 +917,6 @@ static int __devinit cpuup_callback(strustruct kmem_cache *cachep;struct node_cache *node_cache =NULL ;int node =cpu_to_node (cpu); -int memsize =sizeof (struct node_cache );switch (action) {case CPU_UP_PREPARE :
@@ -924,10 +933,9 @@ static int __devinit cpuup_callback(stru* node has not already allocated this */ if (!cachep->nodelists[node]) { -if (!(node_cache =kmalloc_node (memsize, -GFP_KERNEL , node))) + node_cache =alloc_node_cache (node); +if (!node_cache) goto bad; -node_cache_init (node_cache); node_cache->next_reap = jiffies +REAPTIMEOUT_LIST3 + ((unsigned long )cachep) %REAPTIMEOUT_LIST3 ;
@@ -1891,14 +1899,9 @@ kmem_cache_create (const char *name, siz }else {int node;for_each_online_node (node) { - cachep->nodelists[node] = -kmalloc_node (sizeof - (struct node_cache ), -GFP_KERNEL , node); +alloc_node_cache (node);BUG_ON (!cachep->nodelists[node]); -node_cache_init (cachep-> - nodelists[node]); } } }
@@ -3211,11 +3214,9 @@ static int alloc_node_caches(struct kmemfree_alien_cache (new_alien);continue ; } -if (!(node_cache =kmalloc_node (sizeof (struct node_cache ), -GFP_KERNEL , node))) + node_cache =alloc_node_cache (node); +if (!node_cache) goto fail; - -node_cache_init (node_cache); node_cache->next_reap = jiffies +REAPTIMEOUT_LIST3 + ((unsigned long )cachep) %REAPTIMEOUT_LIST3 ; node_cache->shared = new;