slab: Make allocations with GFP_ZERO slightly more efficient
authorJoe Perches <joe@perches.com>
Wed, 11 Sep 2013 00:02:51 +0000 (17:02 -0700)
committerPekka Enberg <penberg@kernel.org>
Sat, 8 Feb 2014 10:19:02 +0000 (12:19 +0200)
Use the likely mechanism already around valid
pointer tests to better choose when to memset
to 0 allocations with __GFP_ZERO

Acked-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
mm/slab.c

index 54eba8a6537027405571ead6c4d3512240e27c7c..8347d803a23f4504fd5fa25774ca252c3ef668dd 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3278,11 +3278,11 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid,
        kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
                                 flags);
 
-       if (likely(ptr))
+       if (likely(ptr)) {
                kmemcheck_slab_alloc(cachep, flags, ptr, cachep->object_size);
-
-       if (unlikely((flags & __GFP_ZERO) && ptr))
-               memset(ptr, 0, cachep->object_size);
+               if (unlikely(flags & __GFP_ZERO))
+                       memset(ptr, 0, cachep->object_size);
+       }
 
        return ptr;
 }
@@ -3343,11 +3343,11 @@ slab_alloc(struct kmem_cache *cachep, gfp_t flags, unsigned long caller)
                                 flags);
        prefetchw(objp);
 
-       if (likely(objp))
+       if (likely(objp)) {
                kmemcheck_slab_alloc(cachep, flags, objp, cachep->object_size);
-
-       if (unlikely((flags & __GFP_ZERO) && objp))
-               memset(objp, 0, cachep->object_size);
+               if (unlikely(flags & __GFP_ZERO))
+                       memset(objp, 0, cachep->object_size);
+       }
 
        return objp;
 }