Revert "SLUB: remove useless masking of GFP_ZERO"
[sfrench/cifs-2.6.git] / mm / slub.c
index ecacacdce9d7050faa2598e49d1e2992dc70507d..84ed734b96b3ee83861b7499edd55d7aa479e61a 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1368,7 +1368,7 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
        struct page *page = c->page;
        int tail = 1;
 
-       if (c->freelist)
+       if (page->freelist)
                stat(c, DEACTIVATE_REMOTE_FREES);
        /*
         * Merge cpu freelist into slab freelist. Typically we get here
@@ -1470,6 +1470,9 @@ static void *__slab_alloc(struct kmem_cache *s,
        void **object;
        struct page *new;
 
+       /* We handle __GFP_ZERO in the caller */
+       gfpflags &= ~__GFP_ZERO;
+
        if (!c->page)
                goto new_slab;
 
@@ -1536,9 +1539,15 @@ new_slab:
         * That is only possible if certain conditions are met that are being
         * checked when a slab is created.
         */
-       if (!(gfpflags & __GFP_NORETRY) && (s->flags & __PAGE_ALLOC_FALLBACK))
-               return kmalloc_large(s->objsize, gfpflags);
-
+       if (!(gfpflags & __GFP_NORETRY) &&
+                               (s->flags & __PAGE_ALLOC_FALLBACK)) {
+               if (gfpflags & __GFP_WAIT)
+                       local_irq_enable();
+               object = kmalloc_large(s->objsize, gfpflags);
+               if (gfpflags & __GFP_WAIT)
+                       local_irq_disable();
+               return object;
+       }
        return NULL;
 debug:
        if (!alloc_debug_processing(s, c->page, object, addr))
@@ -1856,12 +1865,15 @@ static unsigned long calculate_alignment(unsigned long flags,
         * The hardware cache alignment cannot override the specified
         * alignment though. If that is greater then use it.
         */
-       if ((flags & SLAB_HWCACHE_ALIGN) &&
-                       size > cache_line_size() / 2)
-               return max_t(unsigned long, align, cache_line_size());
+       if (flags & SLAB_HWCACHE_ALIGN) {
+               unsigned long ralign = cache_line_size();
+               while (size <= ralign / 2)
+                       ralign /= 2;
+               align = max(align, ralign);
+       }
 
        if (align < ARCH_SLAB_MINALIGN)
-               return ARCH_SLAB_MINALIGN;
+               align = ARCH_SLAB_MINALIGN;
 
        return ALIGN(align, sizeof(void *));
 }
@@ -2676,6 +2688,7 @@ void kfree(const void *x)
 }
 EXPORT_SYMBOL(kfree);
 
+#if defined(SLUB_DEBUG) || defined(CONFIG_SLABINFO)
 static unsigned long count_partial(struct kmem_cache_node *n)
 {
        unsigned long flags;
@@ -2688,6 +2701,7 @@ static unsigned long count_partial(struct kmem_cache_node *n)
        spin_unlock_irqrestore(&n->list_lock, flags);
        return x;
 }
+#endif
 
 /*
  * kmem_cache_shrink removes empty slabs from the partial lists and sorts
@@ -3564,8 +3578,8 @@ enum slab_stat_type {
 #define SO_CPU         (1 << SL_CPU)
 #define SO_OBJECTS     (1 << SL_OBJECTS)
 
-static unsigned long show_slab_objects(struct kmem_cache *s,
-                       char *buf, unsigned long flags)
+static ssize_t show_slab_objects(struct kmem_cache *s,
+                           char *buf, unsigned long flags)
 {
        unsigned long total = 0;
        int cpu;
@@ -3575,6 +3589,8 @@ static unsigned long show_slab_objects(struct kmem_cache *s,
        unsigned long *per_cpu;
 
        nodes = kzalloc(2 * sizeof(unsigned long) * nr_node_ids, GFP_KERNEL);
+       if (!nodes)
+               return -ENOMEM;
        per_cpu = nodes + nr_node_ids;
 
        for_each_possible_cpu(cpu) {