From d8c9b7dba262fbef1abd0f730cac52b7ee90ec8a Mon Sep 17 00:00:00 2001 From: Christoph Lameter Date: Mon, 7 Jan 2008 23:20:28 -0800 Subject: [PATCH] SLUB: Avoid NULL check in fastpath The fast path always results in a valid object. Move the check for the NULL pointer to the slow branch that calls __slab_alloc. Only __slab_alloc can return NULL if there is no memory available anymore and that case is exceedingly rare. Signed-off-by: Christoph Lameter Reviewed-by: Pekka Enberg Signed-off-by: Andrew Morton --- mm/slub.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) Index: linux-2.6/mm/slub.c =================================================================== --- linux-2.6.orig/mm/slub.c 2008-02-04 22:31:20.922345197 -0800 +++ linux-2.6/mm/slub.c 2008-02-04 22:33:54.451967081 -0800 @@ -1644,10 +1644,14 @@ static __always_inline void *slab_alloc( local_irq_save(flags); c = get_cpu_slab(s, smp_processor_id()); - if (unlikely(is_end(c->freelist) || !node_match(c, node))) + if (unlikely(is_end(c->freelist) || !node_match(c, node))) { object = __slab_alloc(s, gfpflags, node, addr, c); - + if (unlikely(!object)) + local_irq_restore(flags); + goto out; + } + } else { object = c->freelist; c->freelist = object[c->offset]; @@ -1656,7 +1660,7 @@ static __always_inline void *slab_alloc( local_irq_restore(flags); #endif - if (unlikely((gfpflags & __GFP_ZERO) && object)) + if (unlikely((gfpflags & __GFP_ZERO))) memset(object, 0, c->objsize); out: return object;