mm/sparse: optimize sparse_index_alloc
authorGavin Shan <shangw@linux.vnet.ibm.com>
Tue, 31 Jul 2012 23:46:02 +0000 (16:46 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 1 Aug 2012 01:42:49 +0000 (18:42 -0700)
With CONFIG_SPARSEMEM_EXTREME, the two levels of memory section
descriptors are allocated from slab or bootmem.  When allocating from
slab, let slab/bootmem allocator clear the memory chunk.  We needn't clear
it explicitly.

Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/sparse.c

index 950981fd07c5f2686b08cb864c2e0f3d548d4d95..fa933f43b2c92b7308e307fb429fff4090aa9ab0 100644 (file)
@@ -65,14 +65,12 @@ static struct mem_section noinline __init_refok *sparse_index_alloc(int nid)
 
        if (slab_is_available()) {
                if (node_state(nid, N_HIGH_MEMORY))
-                       section = kmalloc_node(array_size, GFP_KERNEL, nid);
+                       section = kzalloc_node(array_size, GFP_KERNEL, nid);
                else
-                       section = kmalloc(array_size, GFP_KERNEL);
-       } else
+                       section = kzalloc(array_size, GFP_KERNEL);
+       } else {
                section = alloc_bootmem_node(NODE_DATA(nid), array_size);
-
-       if (section)
-               memset(section, 0, array_size);
+       }
 
        return section;
 }