slab: Fixup CONFIG_PAGE_ALLOC/DEBUG_SLAB_LEAK sections
[platform/adaptation/renesas_rcar/renesas_kernel.git] / mm / slab.c
index 6d5c83c..910df63 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -87,7 +87,6 @@
  */
 
 #include       <linux/slab.h>
-#include       "slab.h"
 #include       <linux/mm.h>
 #include       <linux/poison.h>
 #include       <linux/swap.h>
 
 #include       "internal.h"
 
+#include       "slab.h"
+
 /*
  * DEBUG       - 1 for kmem_cache_create() to honour; SLAB_RED_ZONE & SLAB_POISON.
  *               0 for faster, smaller code (especially in the critical paths).
  */
 static bool pfmemalloc_active __read_mostly;
 
-/* Legal flag mask for kmem_cache_create(). */
-#if DEBUG
-# define CREATE_MASK   (SLAB_RED_ZONE | \
-                        SLAB_POISON | SLAB_HWCACHE_ALIGN | \
-                        SLAB_CACHE_DMA | \
-                        SLAB_STORE_USER | \
-                        SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
-                        SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
-                        SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
-#else
-# define CREATE_MASK   (SLAB_HWCACHE_ALIGN | \
-                        SLAB_CACHE_DMA | \
-                        SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
-                        SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
-                        SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
-#endif
-
 /*
  * kmem_bufctl_t:
  *
@@ -302,68 +286,27 @@ struct arraycache_init {
 };
 
 /*
- * The slab lists for all objects.
- */
-struct kmem_list3 {
-       struct list_head slabs_partial; /* partial list first, better asm code */
-       struct list_head slabs_full;
-       struct list_head slabs_free;
-       unsigned long free_objects;
-       unsigned int free_limit;
-       unsigned int colour_next;       /* Per-node cache coloring */
-       spinlock_t list_lock;
-       struct array_cache *shared;     /* shared per node */
-       struct array_cache **alien;     /* on other nodes */
-       unsigned long next_reap;        /* updated without locking */
-       int free_touched;               /* updated without locking */
-};
-
-/*
  * Need this for bootstrapping a per node allocator.
  */
 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
+static struct kmem_cache_node __initdata init_kmem_cache_node[NUM_INIT_LISTS];
 #define        CACHE_CACHE 0
 #define        SIZE_AC MAX_NUMNODES
-#define        SIZE_L3 (2 * MAX_NUMNODES)
+#define        SIZE_NODE (2 * MAX_NUMNODES)
 
 static int drain_freelist(struct kmem_cache *cache,
-                       struct kmem_list3 *l3, int tofree);
+                       struct kmem_cache_node *n, int tofree);
 static void free_block(struct kmem_cache *cachep, void **objpp, int len,
                        int node);
 static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp);
 static void cache_reap(struct work_struct *unused);
 
-/*
- * This function must be completely optimized away if a constant is passed to
- * it.  Mostly the same as what is in linux/slab.h except it returns an index.
- */
-static __always_inline int index_of(const size_t size)
-{
-       extern void __bad_size(void);
-
-       if (__builtin_constant_p(size)) {
-               int i = 0;
-
-#define CACHE(x) \
-       if (size <=x) \
-               return i; \
-       else \
-               i++;
-#include <linux/kmalloc_sizes.h>
-#undef CACHE
-               __bad_size();
-       } else
-               __bad_size();
-       return 0;
-}
-
 static int slab_early_init = 1;
 
-#define INDEX_AC index_of(sizeof(struct arraycache_init))
-#define INDEX_L3 index_of(sizeof(struct kmem_list3))
+#define INDEX_AC kmalloc_index(sizeof(struct arraycache_init))
+#define INDEX_NODE kmalloc_index(sizeof(struct kmem_cache_node))
 
-static void kmem_list3_init(struct kmem_list3 *parent)
+static void kmem_cache_node_init(struct kmem_cache_node *parent)
 {
        INIT_LIST_HEAD(&parent->slabs_full);
        INIT_LIST_HEAD(&parent->slabs_partial);
@@ -379,7 +322,7 @@ static void kmem_list3_init(struct kmem_list3 *parent)
 #define MAKE_LIST(cachep, listp, slab, nodeid)                         \
        do {                                                            \
                INIT_LIST_HEAD(listp);                                  \
-               list_splice(&(cachep->nodelists[nodeid]->slab), listp); \
+               list_splice(&(cachep->node[nodeid]->slab), listp);      \
        } while (0)
 
 #define        MAKE_ALL_LISTS(cachep, ptr, nodeid)                             \
@@ -540,39 +483,11 @@ static inline unsigned int obj_to_index(const struct kmem_cache *cache,
        return reciprocal_divide(offset, cache->reciprocal_buffer_size);
 }
 
-/*
- * These are the default caches for kmalloc. Custom caches can have other sizes.
- */
-struct cache_sizes malloc_sizes[] = {
-#define CACHE(x) { .cs_size = (x) },
-#include <linux/kmalloc_sizes.h>
-       CACHE(ULONG_MAX)
-#undef CACHE
-};
-EXPORT_SYMBOL(malloc_sizes);
-
-/* Must match cache_sizes above. Out of line to keep cache footprint low. */
-struct cache_names {
-       char *name;
-       char *name_dma;
-};
-
-static struct cache_names __initdata cache_names[] = {
-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
-#include <linux/kmalloc_sizes.h>
-       {NULL,}
-#undef CACHE
-};
-
-static struct arraycache_init initarray_cache __initdata =
-    { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
 static struct arraycache_init initarray_generic =
     { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
 
 /* internal cache of cache description objs */
-static struct kmem_list3 *kmem_cache_nodelists[MAX_NUMNODES];
 static struct kmem_cache kmem_cache_boot = {
-       .nodelists = kmem_cache_nodelists,
        .batchcount = 1,
        .limit = BOOT_CPUCACHE_ENTRIES,
        .shared = 1,
@@ -606,15 +521,15 @@ static void slab_set_lock_classes(struct kmem_cache *cachep,
                int q)
 {
        struct array_cache **alc;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        int r;
 
-       l3 = cachep->nodelists[q];
-       if (!l3)
+       n = cachep->node[q];
+       if (!n)
                return;
 
-       lockdep_set_class(&l3->list_lock, l3_key);
-       alc = l3->alien;
+       lockdep_set_class(&n->list_lock, l3_key);
+       alc = n->alien;
        /*
         * FIXME: This check for BAD_ALIEN_MAGIC
         * should go away when common slab code is taught to
@@ -645,23 +560,45 @@ static void slab_set_debugobj_lock_classes(struct kmem_cache *cachep)
 
 static void init_node_lock_keys(int q)
 {
-       struct cache_sizes *s = malloc_sizes;
+       int i;
 
        if (slab_state < UP)
                return;
 
-       for (s = malloc_sizes; s->cs_size != ULONG_MAX; s++) {
-               struct kmem_list3 *l3;
+       for (i = 1; i < PAGE_SHIFT + MAX_ORDER; i++) {
+               struct kmem_cache_node *n;
+               struct kmem_cache *cache = kmalloc_caches[i];
+
+               if (!cache)
+                       continue;
 
-               l3 = s->cs_cachep->nodelists[q];
-               if (!l3 || OFF_SLAB(s->cs_cachep))
+               n = cache->node[q];
+               if (!n || OFF_SLAB(cache))
                        continue;
 
-               slab_set_lock_classes(s->cs_cachep, &on_slab_l3_key,
+               slab_set_lock_classes(cache, &on_slab_l3_key,
                                &on_slab_alc_key, q);
        }
 }
 
+static void on_slab_lock_classes_node(struct kmem_cache *cachep, int q)
+{
+       if (!cachep->node[q])
+               return;
+
+       slab_set_lock_classes(cachep, &on_slab_l3_key,
+                       &on_slab_alc_key, q);
+}
+
+static inline void on_slab_lock_classes(struct kmem_cache *cachep)
+{
+       int node;
+
+       VM_BUG_ON(OFF_SLAB(cachep));
+       for_each_node(node)
+               on_slab_lock_classes_node(cachep, node);
+}
+
 static inline void init_lock_keys(void)
 {
        int node;
@@ -678,55 +615,28 @@ static inline void init_lock_keys(void)
 {
 }
 
-static void slab_set_debugobj_lock_classes_node(struct kmem_cache *cachep, int node)
+static inline void on_slab_lock_classes(struct kmem_cache *cachep)
 {
 }
 
-static void slab_set_debugobj_lock_classes(struct kmem_cache *cachep)
+static inline void on_slab_lock_classes_node(struct kmem_cache *cachep, int node)
 {
 }
-#endif
-
-static DEFINE_PER_CPU(struct delayed_work, slab_reap_work);
 
-static inline struct array_cache *cpu_cache_get(struct kmem_cache *cachep)
+static void slab_set_debugobj_lock_classes_node(struct kmem_cache *cachep, int node)
 {
-       return cachep->array[smp_processor_id()];
 }
 
-static inline struct kmem_cache *__find_general_cachep(size_t size,
-                                                       gfp_t gfpflags)
+static void slab_set_debugobj_lock_classes(struct kmem_cache *cachep)
 {
-       struct cache_sizes *csizep = malloc_sizes;
-
-#if DEBUG
-       /* This happens if someone tries to call
-        * kmem_cache_create(), or __kmalloc(), before
-        * the generic caches are initialized.
-        */
-       BUG_ON(malloc_sizes[INDEX_AC].cs_cachep == NULL);
+}
 #endif
-       if (!size)
-               return ZERO_SIZE_PTR;
 
-       while (size > csizep->cs_size)
-               csizep++;
-
-       /*
-        * Really subtle: The last entry with cs->cs_size==ULONG_MAX
-        * has cs_{dma,}cachep==NULL. Thus no special case
-        * for large kmalloc calls required.
-        */
-#ifdef CONFIG_ZONE_DMA
-       if (unlikely(gfpflags & GFP_DMA))
-               return csizep->cs_dmacachep;
-#endif
-       return csizep->cs_cachep;
-}
+static DEFINE_PER_CPU(struct delayed_work, slab_reap_work);
 
-static struct kmem_cache *kmem_find_general_cachep(size_t size, gfp_t gfpflags)
+static inline struct array_cache *cpu_cache_get(struct kmem_cache *cachep)
 {
-       return __find_general_cachep(size, gfpflags);
+       return cachep->array[smp_processor_id()];
 }
 
 static size_t slab_mgmt_size(size_t nr_objs, size_t align)
@@ -930,29 +840,29 @@ static inline bool is_slab_pfmemalloc(struct slab *slabp)
 static void recheck_pfmemalloc_active(struct kmem_cache *cachep,
                                                struct array_cache *ac)
 {
-       struct kmem_list3 *l3 = cachep->nodelists[numa_mem_id()];
+       struct kmem_cache_node *n = cachep->node[numa_mem_id()];
        struct slab *slabp;
        unsigned long flags;
 
        if (!pfmemalloc_active)
                return;
 
-       spin_lock_irqsave(&l3->list_lock, flags);
-       list_for_each_entry(slabp, &l3->slabs_full, list)
+       spin_lock_irqsave(&n->list_lock, flags);
+       list_for_each_entry(slabp, &n->slabs_full, list)
                if (is_slab_pfmemalloc(slabp))
                        goto out;
 
-       list_for_each_entry(slabp, &l3->slabs_partial, list)
+       list_for_each_entry(slabp, &n->slabs_partial, list)
                if (is_slab_pfmemalloc(slabp))
                        goto out;
 
-       list_for_each_entry(slabp, &l3->slabs_free, list)
+       list_for_each_entry(slabp, &n->slabs_free, list)
                if (is_slab_pfmemalloc(slabp))
                        goto out;
 
        pfmemalloc_active = false;
 out:
-       spin_unlock_irqrestore(&l3->list_lock, flags);
+       spin_unlock_irqrestore(&n->list_lock, flags);
 }
 
 static void *__ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac,
@@ -963,7 +873,7 @@ static void *__ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac,
 
        /* Ensure the caller is allowed to use objects from PFMEMALLOC slab */
        if (unlikely(is_obj_pfmemalloc(objp))) {
-               struct kmem_list3 *l3;
+               struct kmem_cache_node *n;
 
                if (gfp_pfmemalloc_allowed(flags)) {
                        clear_obj_pfmemalloc(&objp);
@@ -985,8 +895,8 @@ static void *__ac_get_obj(struct kmem_cache *cachep, struct array_cache *ac,
                 * If there are empty slabs on the slabs_free list and we are
                 * being forced to refill the cache, mark this one !pfmemalloc.
                 */
-               l3 = cachep->nodelists[numa_mem_id()];
-               if (!list_empty(&l3->slabs_free) && force_refill) {
+               n = cachep->node[numa_mem_id()];
+               if (!list_empty(&n->slabs_free) && force_refill) {
                        struct slab *slabp = virt_to_slab(objp);
                        ClearPageSlabPfmemalloc(virt_to_head_page(slabp->s_mem));
                        clear_obj_pfmemalloc(&objp);
@@ -1063,7 +973,7 @@ static int transfer_objects(struct array_cache *to,
 #ifndef CONFIG_NUMA
 
 #define drain_alien_cache(cachep, alien) do { } while (0)
-#define reap_alien(cachep, l3) do { } while (0)
+#define reap_alien(cachep, n) do { } while (0)
 
 static inline struct array_cache **alloc_alien_cache(int node, int limit, gfp_t gfp)
 {
@@ -1135,33 +1045,33 @@ static void free_alien_cache(struct array_cache **ac_ptr)
 static void __drain_alien_cache(struct kmem_cache *cachep,
                                struct array_cache *ac, int node)
 {
-       struct kmem_list3 *rl3 = cachep->nodelists[node];
+       struct kmem_cache_node *n = cachep->node[node];
 
        if (ac->avail) {
-               spin_lock(&rl3->list_lock);
+               spin_lock(&n->list_lock);
                /*
                 * Stuff objects into the remote nodes shared array first.
                 * That way we could avoid the overhead of putting the objects
                 * into the free lists and getting them back later.
                 */
-               if (rl3->shared)
-                       transfer_objects(rl3->shared, ac, ac->limit);
+               if (n->shared)
+                       transfer_objects(n->shared, ac, ac->limit);
 
                free_block(cachep, ac->entry, ac->avail, node);
                ac->avail = 0;
-               spin_unlock(&rl3->list_lock);
+               spin_unlock(&n->list_lock);
        }
 }
 
 /*
  * Called from cache_reap() to regularly drain alien caches round robin.
  */
-static void reap_alien(struct kmem_cache *cachep, struct kmem_list3 *l3)
+static void reap_alien(struct kmem_cache *cachep, struct kmem_cache_node *n)
 {
        int node = __this_cpu_read(slab_reap_node);
 
-       if (l3->alien) {
-               struct array_cache *ac = l3->alien[node];
+       if (n->alien) {
+               struct array_cache *ac = n->alien[node];
 
                if (ac && ac->avail && spin_trylock_irq(&ac->lock)) {
                        __drain_alien_cache(cachep, ac, node);
@@ -1191,7 +1101,7 @@ static inline int cache_free_alien(struct kmem_cache *cachep, void *objp)
 {
        struct slab *slabp = virt_to_slab(objp);
        int nodeid = slabp->nodeid;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        struct array_cache *alien = NULL;
        int node;
 
@@ -1204,10 +1114,10 @@ static inline int cache_free_alien(struct kmem_cache *cachep, void *objp)
        if (likely(slabp->nodeid == node))
                return 0;
 
-       l3 = cachep->nodelists[node];
+       n = cachep->node[node];
        STATS_INC_NODEFREES(cachep);
-       if (l3->alien && l3->alien[nodeid]) {
-               alien = l3->alien[nodeid];
+       if (n->alien && n->alien[nodeid]) {
+               alien = n->alien[nodeid];
                spin_lock(&alien->lock);
                if (unlikely(alien->avail == alien->limit)) {
                        STATS_INC_ACOVERFLOW(cachep);
@@ -1216,28 +1126,28 @@ static inline int cache_free_alien(struct kmem_cache *cachep, void *objp)
                ac_put_obj(cachep, alien, objp);
                spin_unlock(&alien->lock);
        } else {
-               spin_lock(&(cachep->nodelists[nodeid])->list_lock);
+               spin_lock(&(cachep->node[nodeid])->list_lock);
                free_block(cachep, &objp, 1, nodeid);
-               spin_unlock(&(cachep->nodelists[nodeid])->list_lock);
+               spin_unlock(&(cachep->node[nodeid])->list_lock);
        }
        return 1;
 }
 #endif
 
 /*
- * Allocates and initializes nodelists for a node on each slab cache, used for
- * either memory or cpu hotplug.  If memory is being hot-added, the kmem_list3
+ * Allocates and initializes node for a node on each slab cache, used for
+ * either memory or cpu hotplug.  If memory is being hot-added, the kmem_cache_node
  * will be allocated off-node since memory is not yet online for the new node.
- * When hotplugging memory or a cpu, existing nodelists are not replaced if
+ * When hotplugging memory or a cpu, existing node are not replaced if
  * already in use.
  *
  * Must hold slab_mutex.
  */
-static int init_cache_nodelists_node(int node)
+static int init_cache_node_node(int node)
 {
        struct kmem_cache *cachep;
-       struct kmem_list3 *l3;
-       const int memsize = sizeof(struct kmem_list3);
+       struct kmem_cache_node *n;
+       const int memsize = sizeof(struct kmem_cache_node);
 
        list_for_each_entry(cachep, &slab_caches, list) {
                /*
@@ -1245,12 +1155,12 @@ static int init_cache_nodelists_node(int node)
                 * begin anything. Make sure some other cpu on this
                 * node has not already allocated this
                 */
-               if (!cachep->nodelists[node]) {
-                       l3 = kmalloc_node(memsize, GFP_KERNEL, node);
-                       if (!l3)
+               if (!cachep->node[node]) {
+                       n = kmalloc_node(memsize, GFP_KERNEL, node);
+                       if (!n)
                                return -ENOMEM;
-                       kmem_list3_init(l3);
-                       l3->next_reap = jiffies + REAPTIMEOUT_LIST3 +
+                       kmem_cache_node_init(n);
+                       n->next_reap = jiffies + REAPTIMEOUT_LIST3 +
                            ((unsigned long)cachep) % REAPTIMEOUT_LIST3;
 
                        /*
@@ -1258,14 +1168,14 @@ static int init_cache_nodelists_node(int node)
                         * go.  slab_mutex is sufficient
                         * protection here.
                         */
-                       cachep->nodelists[node] = l3;
+                       cachep->node[node] = n;
                }
 
-               spin_lock_irq(&cachep->nodelists[node]->list_lock);
-               cachep->nodelists[node]->free_limit =
+               spin_lock_irq(&cachep->node[node]->list_lock);
+               cachep->node[node]->free_limit =
                        (1 + nr_cpus_node(node)) *
                        cachep->batchcount + cachep->num;
-               spin_unlock_irq(&cachep->nodelists[node]->list_lock);
+               spin_unlock_irq(&cachep->node[node]->list_lock);
        }
        return 0;
 }
@@ -1273,7 +1183,7 @@ static int init_cache_nodelists_node(int node)
 static void __cpuinit cpuup_canceled(long cpu)
 {
        struct kmem_cache *cachep;
-       struct kmem_list3 *l3 = NULL;
+       struct kmem_cache_node *n = NULL;
        int node = cpu_to_mem(cpu);
        const struct cpumask *mask = cpumask_of_node(node);
 
@@ -1285,34 +1195,34 @@ static void __cpuinit cpuup_canceled(long cpu)
                /* cpu is dead; no one can alloc from it. */
                nc = cachep->array[cpu];
                cachep->array[cpu] = NULL;
-               l3 = cachep->nodelists[node];
+               n = cachep->node[node];
 
-               if (!l3)
+               if (!n)
                        goto free_array_cache;
 
-               spin_lock_irq(&l3->list_lock);
+               spin_lock_irq(&n->list_lock);
 
-               /* Free limit for this kmem_list3 */
-               l3->free_limit -= cachep->batchcount;
+               /* Free limit for this kmem_cache_node */
+               n->free_limit -= cachep->batchcount;
                if (nc)
                        free_block(cachep, nc->entry, nc->avail, node);
 
                if (!cpumask_empty(mask)) {
-                       spin_unlock_irq(&l3->list_lock);
+                       spin_unlock_irq(&n->list_lock);
                        goto free_array_cache;
                }
 
-               shared = l3->shared;
+               shared = n->shared;
                if (shared) {
                        free_block(cachep, shared->entry,
                                   shared->avail, node);
-                       l3->shared = NULL;
+                       n->shared = NULL;
                }
 
-               alien = l3->alien;
-               l3->alien = NULL;
+               alien = n->alien;
+               n->alien = NULL;
 
-               spin_unlock_irq(&l3->list_lock);
+               spin_unlock_irq(&n->list_lock);
 
                kfree(shared);
                if (alien) {
@@ -1328,17 +1238,17 @@ free_array_cache:
         * shrink each nodelist to its limit.
         */
        list_for_each_entry(cachep, &slab_caches, list) {
-               l3 = cachep->nodelists[node];
-               if (!l3)
+               n = cachep->node[node];
+               if (!n)
                        continue;
-               drain_freelist(cachep, l3, l3->free_objects);
+               drain_freelist(cachep, n, n->free_objects);
        }
 }
 
 static int __cpuinit cpuup_prepare(long cpu)
 {
        struct kmem_cache *cachep;
-       struct kmem_list3 *l3 = NULL;
+       struct kmem_cache_node *n = NULL;
        int node = cpu_to_mem(cpu);
        int err;
 
@@ -1346,9 +1256,9 @@ static int __cpuinit cpuup_prepare(long cpu)
         * We need to do this right in the beginning since
         * alloc_arraycache's are going to use this list.
         * kmalloc_node allows us to add the slab to the right
-        * kmem_list3 and not this cpu's kmem_list3
+        * kmem_cache_node and not this cpu's kmem_cache_node
         */
-       err = init_cache_nodelists_node(node);
+       err = init_cache_node_node(node);
        if (err < 0)
                goto bad;
 
@@ -1383,29 +1293,32 @@ static int __cpuinit cpuup_prepare(long cpu)
                        }
                }
                cachep->array[cpu] = nc;
-               l3 = cachep->nodelists[node];
-               BUG_ON(!l3);
+               n = cachep->node[node];
+               BUG_ON(!n);
 
-               spin_lock_irq(&l3->list_lock);
-               if (!l3->shared) {
+               spin_lock_irq(&n->list_lock);
+               if (!n->shared) {
                        /*
                         * We are serialised from CPU_DEAD or
                         * CPU_UP_CANCELLED by the cpucontrol lock
                         */
-                       l3->shared = shared;
+                       n->shared = shared;
                        shared = NULL;
                }
 #ifdef CONFIG_NUMA
-               if (!l3->alien) {
-                       l3->alien = alien;
+               if (!n->alien) {
+                       n->alien = alien;
                        alien = NULL;
                }
 #endif
-               spin_unlock_irq(&l3->list_lock);
+               spin_unlock_irq(&n->list_lock);
                kfree(shared);
                free_alien_cache(alien);
                if (cachep->flags & SLAB_DEBUG_OBJECTS)
                        slab_set_debugobj_lock_classes_node(cachep, node);
+               else if (!OFF_SLAB(cachep) &&
+                        !(cachep->flags & SLAB_DESTROY_BY_RCU))
+                       on_slab_lock_classes_node(cachep, node);
        }
        init_node_lock_keys(node);
 
@@ -1453,9 +1366,9 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
        case CPU_DEAD_FROZEN:
                /*
                 * Even if all the cpus of a node are down, we don't free the
-                * kmem_list3 of any cache. This to avoid a race between
+                * kmem_cache_node of any cache. This to avoid a race between
                 * cpu_down, and a kmalloc allocation from another cpu for
-                * memory from the node of the cpu going down.  The list3
+                * memory from the node of the cpu going down.  The node
                 * structure is usually allocated from kmem_cache_create() and
                 * gets destroyed at kmem_cache_destroy().
                 */
@@ -1483,22 +1396,22 @@ static struct notifier_block __cpuinitdata cpucache_notifier = {
  *
  * Must hold slab_mutex.
  */
-static int __meminit drain_cache_nodelists_node(int node)
+static int __meminit drain_cache_node_node(int node)
 {
        struct kmem_cache *cachep;
        int ret = 0;
 
        list_for_each_entry(cachep, &slab_caches, list) {
-               struct kmem_list3 *l3;
+               struct kmem_cache_node *n;
 
-               l3 = cachep->nodelists[node];
-               if (!l3)
+               n = cachep->node[node];
+               if (!n)
                        continue;
 
-               drain_freelist(cachep, l3, l3->free_objects);
+               drain_freelist(cachep, n, n->free_objects);
 
-               if (!list_empty(&l3->slabs_full) ||
-                   !list_empty(&l3->slabs_partial)) {
+               if (!list_empty(&n->slabs_full) ||
+                   !list_empty(&n->slabs_partial)) {
                        ret = -EBUSY;
                        break;
                }
@@ -1520,12 +1433,12 @@ static int __meminit slab_memory_callback(struct notifier_block *self,
        switch (action) {
        case MEM_GOING_ONLINE:
                mutex_lock(&slab_mutex);
-               ret = init_cache_nodelists_node(nid);
+               ret = init_cache_node_node(nid);
                mutex_unlock(&slab_mutex);
                break;
        case MEM_GOING_OFFLINE:
                mutex_lock(&slab_mutex);
-               ret = drain_cache_nodelists_node(nid);
+               ret = drain_cache_node_node(nid);
                mutex_unlock(&slab_mutex);
                break;
        case MEM_ONLINE:
@@ -1540,66 +1453,69 @@ out:
 #endif /* CONFIG_NUMA && CONFIG_MEMORY_HOTPLUG */
 
 /*
- * swap the static kmem_list3 with kmalloced memory
+ * swap the static kmem_cache_node with kmalloced memory
  */
-static void __init init_list(struct kmem_cache *cachep, struct kmem_list3 *list,
+static void __init init_list(struct kmem_cache *cachep, struct kmem_cache_node *list,
                                int nodeid)
 {
-       struct kmem_list3 *ptr;
+       struct kmem_cache_node *ptr;
 
-       ptr = kmalloc_node(sizeof(struct kmem_list3), GFP_NOWAIT, nodeid);
+       ptr = kmalloc_node(sizeof(struct kmem_cache_node), GFP_NOWAIT, nodeid);
        BUG_ON(!ptr);
 
-       memcpy(ptr, list, sizeof(struct kmem_list3));
+       memcpy(ptr, list, sizeof(struct kmem_cache_node));
        /*
         * Do not assume that spinlocks can be initialized via memcpy:
         */
        spin_lock_init(&ptr->list_lock);
 
        MAKE_ALL_LISTS(cachep, ptr, nodeid);
-       cachep->nodelists[nodeid] = ptr;
+       cachep->node[nodeid] = ptr;
 }
 
 /*
- * For setting up all the kmem_list3s for cache whose buffer_size is same as
- * size of kmem_list3.
+ * For setting up all the kmem_cache_node for cache whose buffer_size is same as
+ * size of kmem_cache_node.
  */
-static void __init set_up_list3s(struct kmem_cache *cachep, int index)
+static void __init set_up_node(struct kmem_cache *cachep, int index)
 {
        int node;
 
        for_each_online_node(node) {
-               cachep->nodelists[node] = &initkmem_list3[index + node];
-               cachep->nodelists[node]->next_reap = jiffies +
+               cachep->node[node] = &init_kmem_cache_node[index + node];
+               cachep->node[node]->next_reap = jiffies +
                    REAPTIMEOUT_LIST3 +
                    ((unsigned long)cachep) % REAPTIMEOUT_LIST3;
        }
 }
 
 /*
+ * The memory after the last cpu cache pointer is used for the
+ * the node pointer.
+ */
+static void setup_node_pointer(struct kmem_cache *cachep)
+{
+       cachep->node = (struct kmem_cache_node **)&cachep->array[nr_cpu_ids];
+}
+
+/*
  * Initialisation.  Called after the page allocator have been initialised and
  * before smp_init().
  */
 void __init kmem_cache_init(void)
 {
-       size_t left_over;
-       struct cache_sizes *sizes;
-       struct cache_names *names;
        int i;
-       int order;
-       int node;
 
        kmem_cache = &kmem_cache_boot;
+       setup_node_pointer(kmem_cache);
 
        if (num_possible_nodes() == 1)
                use_alien_caches = 0;
 
-       for (i = 0; i < NUM_INIT_LISTS; i++) {
-               kmem_list3_init(&initkmem_list3[i]);
-               if (i < MAX_NUMNODES)
-                       kmem_cache->nodelists[i] = NULL;
-       }
-       set_up_list3s(kmem_cache, CACHE_CACHE);
+       for (i = 0; i < NUM_INIT_LISTS; i++)
+               kmem_cache_node_init(&init_kmem_cache_node[i]);
+
+       set_up_node(kmem_cache, CACHE_CACHE);
 
        /*
         * Fragmentation resistance on low memory - only use bigger
@@ -1615,7 +1531,7 @@ void __init kmem_cache_init(void)
         *    kmem_cache structures of all caches, except kmem_cache itself:
         *    kmem_cache is statically allocated.
         *    Initially an __init data area is used for the head array and the
-        *    kmem_list3 structures, it's replaced with a kmalloc allocated
+        *    kmem_cache_node structures, it's replaced with a kmalloc allocated
         *    array at the end of the bootstrap.
         * 2) Create the first kmalloc cache.
         *    The struct kmem_cache for the new cache is allocated normally.
@@ -1624,110 +1540,46 @@ void __init kmem_cache_init(void)
         *    head arrays.
         * 4) Replace the __init data head arrays for kmem_cache and the first
         *    kmalloc cache with kmalloc allocated arrays.
-        * 5) Replace the __init data for kmem_list3 for kmem_cache and
+        * 5) Replace the __init data for kmem_cache_node for kmem_cache and
         *    the other cache's with kmalloc allocated memory.
         * 6) Resize the head arrays of the kmalloc caches to their final sizes.
         */
 
-       node = numa_mem_id();
-
        /* 1) create the kmem_cache */
-       INIT_LIST_HEAD(&slab_caches);
-       list_add(&kmem_cache->list, &slab_caches);
-       kmem_cache->colour_off = cache_line_size();
-       kmem_cache->array[smp_processor_id()] = &initarray_cache.cache;
-       kmem_cache->nodelists[node] = &initkmem_list3[CACHE_CACHE + node];
 
        /*
         * struct kmem_cache size depends on nr_node_ids & nr_cpu_ids
         */
-       kmem_cache->size = offsetof(struct kmem_cache, array[nr_cpu_ids]) +
-                                 nr_node_ids * sizeof(struct kmem_list3 *);
-       kmem_cache->object_size = kmem_cache->size;
-       kmem_cache->size = ALIGN(kmem_cache->object_size,
-                                       cache_line_size());
-       kmem_cache->reciprocal_buffer_size =
-               reciprocal_value(kmem_cache->size);
-
-       for (order = 0; order < MAX_ORDER; order++) {
-               cache_estimate(order, kmem_cache->size,
-                       cache_line_size(), 0, &left_over, &kmem_cache->num);
-               if (kmem_cache->num)
-                       break;
-       }
-       BUG_ON(!kmem_cache->num);
-       kmem_cache->gfporder = order;
-       kmem_cache->colour = left_over / kmem_cache->colour_off;
-       kmem_cache->slab_size = ALIGN(kmem_cache->num * sizeof(kmem_bufctl_t) +
-                                     sizeof(struct slab), cache_line_size());
+       create_boot_cache(kmem_cache, "kmem_cache",
+               offsetof(struct kmem_cache, array[nr_cpu_ids]) +
+                                 nr_node_ids * sizeof(struct kmem_cache_node *),
+                                 SLAB_HWCACHE_ALIGN);
+       list_add(&kmem_cache->list, &slab_caches);
 
        /* 2+3) create the kmalloc caches */
-       sizes = malloc_sizes;
-       names = cache_names;
 
        /*
         * Initialize the caches that provide memory for the array cache and the
-        * kmem_list3 structures first.  Without this, further allocations will
+        * kmem_cache_node structures first.  Without this, further allocations will
         * bug.
         */
 
-       sizes[INDEX_AC].cs_cachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
-       sizes[INDEX_AC].cs_cachep->name = names[INDEX_AC].name;
-       sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
-       sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
-       sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
-       __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
-       list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
-
-       if (INDEX_AC != INDEX_L3) {
-               sizes[INDEX_L3].cs_cachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
-               sizes[INDEX_L3].cs_cachep->name = names[INDEX_L3].name;
-               sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
-               sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
-               sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
-               __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
-               list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
-       }
+       kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
+                                       kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
+
+       if (INDEX_AC != INDEX_NODE)
+               kmalloc_caches[INDEX_NODE] =
+                       create_kmalloc_cache("kmalloc-node",
+                               kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
 
        slab_early_init = 0;
 
-       while (sizes->cs_size != ULONG_MAX) {
-               /*
-                * For performance, all the general caches are L1 aligned.
-                * This should be particularly beneficial on SMP boxes, as it
-                * eliminates "false sharing".
-                * Note for systems short on memory removing the alignment will
-                * allow tighter packing of the smaller caches.
-                */
-               if (!sizes->cs_cachep) {
-                       sizes->cs_cachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
-                       sizes->cs_cachep->name = names->name;
-                       sizes->cs_cachep->size = sizes->cs_size;
-                       sizes->cs_cachep->object_size = sizes->cs_size;
-                       sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
-                       __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
-                       list_add(&sizes->cs_cachep->list, &slab_caches);
-               }
-#ifdef CONFIG_ZONE_DMA
-               sizes->cs_dmacachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
-               sizes->cs_dmacachep->name = names->name_dma;
-               sizes->cs_dmacachep->size = sizes->cs_size;
-               sizes->cs_dmacachep->object_size = sizes->cs_size;
-               sizes->cs_dmacachep->align = ARCH_KMALLOC_MINALIGN;
-               __kmem_cache_create(sizes->cs_dmacachep,
-                              ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
-               list_add(&sizes->cs_dmacachep->list, &slab_caches);
-#endif
-               sizes++;
-               names++;
-       }
        /* 4) Replace the bootstrap head arrays */
        {
                struct array_cache *ptr;
 
                ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT);
 
-               BUG_ON(cpu_cache_get(kmem_cache) != &initarray_cache.cache);
                memcpy(ptr, cpu_cache_get(kmem_cache),
                       sizeof(struct arraycache_init));
                /*
@@ -1739,36 +1591,35 @@ void __init kmem_cache_init(void)
 
                ptr = kmalloc(sizeof(struct arraycache_init), GFP_NOWAIT);
 
-               BUG_ON(cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep)
+               BUG_ON(cpu_cache_get(kmalloc_caches[INDEX_AC])
                       != &initarray_generic.cache);
-               memcpy(ptr, cpu_cache_get(malloc_sizes[INDEX_AC].cs_cachep),
+               memcpy(ptr, cpu_cache_get(kmalloc_caches[INDEX_AC]),
                       sizeof(struct arraycache_init));
                /*
                 * Do not assume that spinlocks can be initialized via memcpy:
                 */
                spin_lock_init(&ptr->lock);
 
-               malloc_sizes[INDEX_AC].cs_cachep->array[smp_processor_id()] =
-                   ptr;
+               kmalloc_caches[INDEX_AC]->array[smp_processor_id()] = ptr;
        }
-       /* 5) Replace the bootstrap kmem_list3's */
+       /* 5) Replace the bootstrap kmem_cache_node */
        {
                int nid;
 
                for_each_online_node(nid) {
-                       init_list(kmem_cache, &initkmem_list3[CACHE_CACHE + nid], nid);
+                       init_list(kmem_cache, &init_kmem_cache_node[CACHE_CACHE + nid], nid);
 
-                       init_list(malloc_sizes[INDEX_AC].cs_cachep,
-                                 &initkmem_list3[SIZE_AC + nid], nid);
+                       init_list(kmalloc_caches[INDEX_AC],
+                                 &init_kmem_cache_node[SIZE_AC + nid], nid);
 
-                       if (INDEX_AC != INDEX_L3) {
-                               init_list(malloc_sizes[INDEX_L3].cs_cachep,
-                                         &initkmem_list3[SIZE_L3 + nid], nid);
+                       if (INDEX_AC != INDEX_NODE) {
+                               init_list(kmalloc_caches[INDEX_NODE],
+                                         &init_kmem_cache_node[SIZE_NODE + nid], nid);
                        }
                }
        }
 
-       slab_state = UP;
+       create_kmalloc_caches(ARCH_KMALLOC_FLAGS);
 }
 
 void __init kmem_cache_init_late(void)
@@ -1799,7 +1650,7 @@ void __init kmem_cache_init_late(void)
 #ifdef CONFIG_NUMA
        /*
         * Register a memory hotplug callback that initializes and frees
-        * nodelists.
+        * node.
         */
        hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
 #endif
@@ -1829,7 +1680,7 @@ __initcall(cpucache_init);
 static noinline void
 slab_out_of_memory(struct kmem_cache *cachep, gfp_t gfpflags, int nodeid)
 {
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        struct slab *slabp;
        unsigned long flags;
        int node;
@@ -1844,24 +1695,24 @@ slab_out_of_memory(struct kmem_cache *cachep, gfp_t gfpflags, int nodeid)
                unsigned long active_objs = 0, num_objs = 0, free_objects = 0;
                unsigned long active_slabs = 0, num_slabs = 0;
 
-               l3 = cachep->nodelists[node];
-               if (!l3)
+               n = cachep->node[node];
+               if (!n)
                        continue;
 
-               spin_lock_irqsave(&l3->list_lock, flags);
-               list_for_each_entry(slabp, &l3->slabs_full, list) {
+               spin_lock_irqsave(&n->list_lock, flags);
+               list_for_each_entry(slabp, &n->slabs_full, list) {
                        active_objs += cachep->num;
                        active_slabs++;
                }
-               list_for_each_entry(slabp, &l3->slabs_partial, list) {
+               list_for_each_entry(slabp, &n->slabs_partial, list) {
                        active_objs += slabp->inuse;
                        active_slabs++;
                }
-               list_for_each_entry(slabp, &l3->slabs_free, list)
+               list_for_each_entry(slabp, &n->slabs_free, list)
                        num_slabs++;
 
-               free_objects += l3->free_objects;
-               spin_unlock_irqrestore(&l3->list_lock, flags);
+               free_objects += n->free_objects;
+               spin_unlock_irqrestore(&n->list_lock, flags);
 
                num_slabs += active_slabs;
                num_objs = num_slabs * cachep->num;
@@ -1921,6 +1772,7 @@ static void *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, int nodeid)
                if (page->pfmemalloc)
                        SetPageSlabPfmemalloc(page + i);
        }
+       memcg_bind_pages(cachep, cachep->gfporder);
 
        if (kmemcheck_enabled && !(cachep->flags & SLAB_NOTRACK)) {
                kmemcheck_alloc_shadow(page, cachep->gfporder, flags, nodeid);
@@ -1957,9 +1809,11 @@ static void kmem_freepages(struct kmem_cache *cachep, void *addr)
                __ClearPageSlab(page);
                page++;
        }
+
+       memcg_release_pages(cachep, cachep->gfporder);
        if (current->reclaim_state)
                current->reclaim_state->reclaimed_slab += nr_freed;
-       free_pages((unsigned long)addr, cachep->gfporder);
+       free_memcg_kmem_pages((unsigned long)addr, cachep->gfporder);
 }
 
 static void kmem_rcu_free(struct rcu_head *head)
@@ -2282,41 +2136,50 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp)
 
        if (slab_state == DOWN) {
                /*
-                * Note: the first kmem_cache_create must create the cache
+                * Note: Creation of first cache (kmem_cache).
+                * The setup_node is taken care
+                * of by the caller of __kmem_cache_create
+                */
+               cachep->array[smp_processor_id()] = &initarray_generic.cache;
+               slab_state = PARTIAL;
+       } else if (slab_state == PARTIAL) {
+               /*
+                * Note: the second kmem_cache_create must create the cache
                 * that's used by kmalloc(24), otherwise the creation of
                 * further caches will BUG().
                 */
                cachep->array[smp_processor_id()] = &initarray_generic.cache;
 
                /*
-                * If the cache that's used by kmalloc(sizeof(kmem_list3)) is
-                * the first cache, then we need to set up all its list3s,
+                * If the cache that's used by kmalloc(sizeof(kmem_cache_node)) is
+                * the second cache, then we need to set up all its node/,
                 * otherwise the creation of further caches will BUG().
                 */
-               set_up_list3s(cachep, SIZE_AC);
-               if (INDEX_AC == INDEX_L3)
-                       slab_state = PARTIAL_L3;
+               set_up_node(cachep, SIZE_AC);
+               if (INDEX_AC == INDEX_NODE)
+                       slab_state = PARTIAL_NODE;
                else
                        slab_state = PARTIAL_ARRAYCACHE;
        } else {
+               /* Remaining boot caches */
                cachep->array[smp_processor_id()] =
                        kmalloc(sizeof(struct arraycache_init), gfp);
 
                if (slab_state == PARTIAL_ARRAYCACHE) {
-                       set_up_list3s(cachep, SIZE_L3);
-                       slab_state = PARTIAL_L3;
+                       set_up_node(cachep, SIZE_NODE);
+                       slab_state = PARTIAL_NODE;
                } else {
                        int node;
                        for_each_online_node(node) {
-                               cachep->nodelists[node] =
-                                   kmalloc_node(sizeof(struct kmem_list3),
+                               cachep->node[node] =
+                                   kmalloc_node(sizeof(struct kmem_cache_node),
                                                gfp, node);
-                               BUG_ON(!cachep->nodelists[node]);
-                               kmem_list3_init(cachep->nodelists[node]);
+                               BUG_ON(!cachep->node[node]);
+                               kmem_cache_node_init(cachep->node[node]);
                        }
                }
        }
-       cachep->nodelists[numa_mem_id()]->next_reap =
+       cachep->node[numa_mem_id()]->next_reap =
                        jiffies + REAPTIMEOUT_LIST3 +
                        ((unsigned long)cachep) % REAPTIMEOUT_LIST3;
 
@@ -2331,11 +2194,8 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep, gfp_t gfp)
 
 /**
  * __kmem_cache_create - Create a cache.
- * @name: A string which is used in /proc/slabinfo to identify this cache.
- * @size: The size of objects to be created in this cache.
- * @align: The required alignment for the objects.
+ * @cachep: cache management descriptor
  * @flags: SLAB flags
- * @ctor: A constructor for the objects.
  *
  * Returns a ptr to the cache on success, NULL on failure.
  * Cannot be called within a int, but can be interrupted.
@@ -2378,11 +2238,6 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
        if (flags & SLAB_DESTROY_BY_RCU)
                BUG_ON(flags & SLAB_POISON);
 #endif
-       /*
-        * Always checks flags, a caller might be expecting debug support which
-        * isn't available.
-        */
-       BUG_ON(flags & ~CREATE_MASK);
 
        /*
         * Check that size is in terms of words.  This is needed to avoid
@@ -2394,22 +2249,6 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
                size &= ~(BYTES_PER_WORD - 1);
        }
 
-       /* calculate the final buffer alignment: */
-
-       /* 1) arch recommendation: can be overridden for debug */
-       if (flags & SLAB_HWCACHE_ALIGN) {
-               /*
-                * Default alignment: as specified by the arch code.  Except if
-                * an object is really small, then squeeze multiple objects into
-                * one cacheline.
-                */
-               ralign = cache_line_size();
-               while (size <= ralign / 2)
-                       ralign /= 2;
-       } else {
-               ralign = BYTES_PER_WORD;
-       }
-
        /*
         * Redzoning and user store require word alignment or possibly larger.
         * Note this will be overridden by architecture or caller mandated
@@ -2426,10 +2265,6 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
                size &= ~(REDZONE_ALIGN - 1);
        }
 
-       /* 2) arch mandated alignment */
-       if (ralign < ARCH_SLAB_MINALIGN) {
-               ralign = ARCH_SLAB_MINALIGN;
-       }
        /* 3) caller mandated alignment */
        if (ralign < cachep->align) {
                ralign = cachep->align;
@@ -2447,7 +2282,7 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
        else
                gfp = GFP_NOWAIT;
 
-       cachep->nodelists = (struct kmem_list3 **)&cachep->array[nr_cpu_ids];
+       setup_node_pointer(cachep);
 #if DEBUG
 
        /*
@@ -2470,7 +2305,7 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
                        size += BYTES_PER_WORD;
        }
 #if FORCED_DEBUG && defined(CONFIG_DEBUG_PAGEALLOC)
-       if (size >= malloc_sizes[INDEX_L3 + 1].cs_size
+       if (size >= kmalloc_size(INDEX_NODE + 1)
            && cachep->object_size > cache_line_size()
            && ALIGN(size, cachep->align) < PAGE_SIZE) {
                cachep->obj_offset += PAGE_SIZE - ALIGN(size, cachep->align);
@@ -2541,7 +2376,7 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
        cachep->reciprocal_buffer_size = reciprocal_value(size);
 
        if (flags & CFLGS_OFF_SLAB) {
-               cachep->slabp_cache = kmem_find_general_cachep(slab_size, 0u);
+               cachep->slabp_cache = kmalloc_slab(slab_size, 0u);
                /*
                 * This is a possibility for one of the malloc_sizes caches.
                 * But since we go off slab only for object size greater than
@@ -2566,7 +2401,8 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
                WARN_ON_ONCE(flags & SLAB_DESTROY_BY_RCU);
 
                slab_set_debugobj_lock_classes(cachep);
-       }
+       } else if (!OFF_SLAB(cachep) && !(flags & SLAB_DESTROY_BY_RCU))
+               on_slab_lock_classes(cachep);
 
        return 0;
 }
@@ -2586,7 +2422,7 @@ static void check_spinlock_acquired(struct kmem_cache *cachep)
 {
 #ifdef CONFIG_SMP
        check_irq_off();
-       assert_spin_locked(&cachep->nodelists[numa_mem_id()]->list_lock);
+       assert_spin_locked(&cachep->node[numa_mem_id()]->list_lock);
 #endif
 }
 
@@ -2594,7 +2430,7 @@ static void check_spinlock_acquired_node(struct kmem_cache *cachep, int node)
 {
 #ifdef CONFIG_SMP
        check_irq_off();
-       assert_spin_locked(&cachep->nodelists[node]->list_lock);
+       assert_spin_locked(&cachep->node[node]->list_lock);
 #endif
 }
 
@@ -2605,7 +2441,7 @@ static void check_spinlock_acquired_node(struct kmem_cache *cachep, int node)
 #define check_spinlock_acquired_node(x, y) do { } while(0)
 #endif
 
-static void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3,
+static void drain_array(struct kmem_cache *cachep, struct kmem_cache_node *n,
                        struct array_cache *ac,
                        int force, int node);
 
@@ -2617,29 +2453,29 @@ static void do_drain(void *arg)
 
        check_irq_off();
        ac = cpu_cache_get(cachep);
-       spin_lock(&cachep->nodelists[node]->list_lock);
+       spin_lock(&cachep->node[node]->list_lock);
        free_block(cachep, ac->entry, ac->avail, node);
-       spin_unlock(&cachep->nodelists[node]->list_lock);
+       spin_unlock(&cachep->node[node]->list_lock);
        ac->avail = 0;
 }
 
 static void drain_cpu_caches(struct kmem_cache *cachep)
 {
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        int node;
 
        on_each_cpu(do_drain, cachep, 1);
        check_irq_on();
        for_each_online_node(node) {
-               l3 = cachep->nodelists[node];
-               if (l3 && l3->alien)
-                       drain_alien_cache(cachep, l3->alien);
+               n = cachep->node[node];
+               if (n && n->alien)
+                       drain_alien_cache(cachep, n->alien);
        }
 
        for_each_online_node(node) {
-               l3 = cachep->nodelists[node];
-               if (l3)
-                       drain_array(cachep, l3, l3->shared, 1, node);
+               n = cachep->node[node];
+               if (n)
+                       drain_array(cachep, n, n->shared, 1, node);
        }
 }
 
@@ -2650,19 +2486,19 @@ static void drain_cpu_caches(struct kmem_cache *cachep)
  * Returns the actual number of slabs released.
  */
 static int drain_freelist(struct kmem_cache *cache,
-                       struct kmem_list3 *l3, int tofree)
+                       struct kmem_cache_node *n, int tofree)
 {
        struct list_head *p;
        int nr_freed;
        struct slab *slabp;
 
        nr_freed = 0;
-       while (nr_freed < tofree && !list_empty(&l3->slabs_free)) {
+       while (nr_freed < tofree && !list_empty(&n->slabs_free)) {
 
-               spin_lock_irq(&l3->list_lock);
-               p = l3->slabs_free.prev;
-               if (p == &l3->slabs_free) {
-                       spin_unlock_irq(&l3->list_lock);
+               spin_lock_irq(&n->list_lock);
+               p = n->slabs_free.prev;
+               if (p == &n->slabs_free) {
+                       spin_unlock_irq(&n->list_lock);
                        goto out;
                }
 
@@ -2675,8 +2511,8 @@ static int drain_freelist(struct kmem_cache *cache,
                 * Safe to drop the lock. The slab is no longer linked
                 * to the cache.
                 */
-               l3->free_objects -= cache->num;
-               spin_unlock_irq(&l3->list_lock);
+               n->free_objects -= cache->num;
+               spin_unlock_irq(&n->list_lock);
                slab_destroy(cache, slabp);
                nr_freed++;
        }
@@ -2688,20 +2524,20 @@ out:
 static int __cache_shrink(struct kmem_cache *cachep)
 {
        int ret = 0, i = 0;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
 
        drain_cpu_caches(cachep);
 
        check_irq_on();
        for_each_online_node(i) {
-               l3 = cachep->nodelists[i];
-               if (!l3)
+               n = cachep->node[i];
+               if (!n)
                        continue;
 
-               drain_freelist(cachep, l3, l3->free_objects);
+               drain_freelist(cachep, n, n->free_objects);
 
-               ret += !list_empty(&l3->slabs_full) ||
-                       !list_empty(&l3->slabs_partial);
+               ret += !list_empty(&n->slabs_full) ||
+                       !list_empty(&n->slabs_partial);
        }
        return (ret ? 1 : 0);
 }
@@ -2730,7 +2566,7 @@ EXPORT_SYMBOL(kmem_cache_shrink);
 int __kmem_cache_shutdown(struct kmem_cache *cachep)
 {
        int i;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        int rc = __cache_shrink(cachep);
 
        if (rc)
@@ -2739,13 +2575,13 @@ int __kmem_cache_shutdown(struct kmem_cache *cachep)
        for_each_online_cpu(i)
            kfree(cachep->array[i]);
 
-       /* NUMA: free the list3 structures */
+       /* NUMA: free the node structures */
        for_each_online_node(i) {
-               l3 = cachep->nodelists[i];
-               if (l3) {
-                       kfree(l3->shared);
-                       free_alien_cache(l3->alien);
-                       kfree(l3);
+               n = cachep->node[i];
+               if (n) {
+                       kfree(n->shared);
+                       free_alien_cache(n->alien);
+                       kfree(n);
                }
        }
        return 0;
@@ -2927,7 +2763,7 @@ static int cache_grow(struct kmem_cache *cachep,
        struct slab *slabp;
        size_t offset;
        gfp_t local_flags;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
 
        /*
         * Be lazy and only check for valid flags here,  keeping it out of the
@@ -2936,17 +2772,17 @@ static int cache_grow(struct kmem_cache *cachep,
        BUG_ON(flags & GFP_SLAB_BUG_MASK);
        local_flags = flags & (GFP_CONSTRAINT_MASK|GFP_RECLAIM_MASK);
 
-       /* Take the l3 list lock to change the colour_next on this node */
+       /* Take the node list lock to change the colour_next on this node */
        check_irq_off();
-       l3 = cachep->nodelists[nodeid];
-       spin_lock(&l3->list_lock);
+       n = cachep->node[nodeid];
+       spin_lock(&n->list_lock);
 
        /* Get colour for the slab, and cal the next value. */
-       offset = l3->colour_next;
-       l3->colour_next++;
-       if (l3->colour_next >= cachep->colour)
-               l3->colour_next = 0;
-       spin_unlock(&l3->list_lock);
+       offset = n->colour_next;
+       n->colour_next++;
+       if (n->colour_next >= cachep->colour)
+               n->colour_next = 0;
+       spin_unlock(&n->list_lock);
 
        offset *= cachep->colour_off;
 
@@ -2983,13 +2819,13 @@ static int cache_grow(struct kmem_cache *cachep,
        if (local_flags & __GFP_WAIT)
                local_irq_disable();
        check_irq_off();
-       spin_lock(&l3->list_lock);
+       spin_lock(&n->list_lock);
 
        /* Make slab active. */
-       list_add_tail(&slabp->list, &(l3->slabs_free));
+       list_add_tail(&slabp->list, &(n->slabs_free));
        STATS_INC_GROWN(cachep);
-       l3->free_objects += cachep->num;
-       spin_unlock(&l3->list_lock);
+       n->free_objects += cachep->num;
+       spin_unlock(&n->list_lock);
        return 1;
 opps1:
        kmem_freepages(cachep, objp);
@@ -3117,7 +2953,7 @@ static void *cache_alloc_refill(struct kmem_cache *cachep, gfp_t flags,
                                                        bool force_refill)
 {
        int batchcount;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        struct array_cache *ac;
        int node;
 
@@ -3136,14 +2972,14 @@ retry:
                 */
                batchcount = BATCHREFILL_LIMIT;
        }
-       l3 = cachep->nodelists[node];
+       n = cachep->node[node];
 
-       BUG_ON(ac->avail > 0 || !l3);
-       spin_lock(&l3->list_lock);
+       BUG_ON(ac->avail > 0 || !n);
+       spin_lock(&n->list_lock);
 
        /* See if we can refill from the shared array */
-       if (l3->shared && transfer_objects(ac, l3->shared, batchcount)) {
-               l3->shared->touched = 1;
+       if (n->shared && transfer_objects(ac, n->shared, batchcount)) {
+               n->shared->touched = 1;
                goto alloc_done;
        }
 
@@ -3151,11 +2987,11 @@ retry:
                struct list_head *entry;
                struct slab *slabp;
                /* Get slab alloc is to come from. */
-               entry = l3->slabs_partial.next;
-               if (entry == &l3->slabs_partial) {
-                       l3->free_touched = 1;
-                       entry = l3->slabs_free.next;
-                       if (entry == &l3->slabs_free)
+               entry = n->slabs_partial.next;
+               if (entry == &n->slabs_partial) {
+                       n->free_touched = 1;
+                       entry = n->slabs_free.next;
+                       if (entry == &n->slabs_free)
                                goto must_grow;
                }
 
@@ -3183,15 +3019,15 @@ retry:
                /* move slabp to correct slabp list: */
                list_del(&slabp->list);
                if (slabp->free == BUFCTL_END)
-                       list_add(&slabp->list, &l3->slabs_full);
+                       list_add(&slabp->list, &n->slabs_full);
                else
-                       list_add(&slabp->list, &l3->slabs_partial);
+                       list_add(&slabp->list, &n->slabs_partial);
        }
 
 must_grow:
-       l3->free_objects -= ac->avail;
+       n->free_objects -= ac->avail;
 alloc_done:
-       spin_unlock(&l3->list_lock);
+       spin_unlock(&n->list_lock);
 
        if (unlikely(!ac->avail)) {
                int x;
@@ -3358,7 +3194,7 @@ static void *alternate_node_alloc(struct kmem_cache *cachep, gfp_t flags)
 /*
  * Fallback function if there was no memory available and no objects on a
  * certain node and fall back is permitted. First we scan all the
- * available nodelists for available objects. If that fails then we
+ * available node for available objects. If that fails then we
  * perform an allocation without specifying a node. This allows the page
  * allocator to do its reclaim / fallback magic. We then insert the
  * slab into the proper nodelist and then allocate from it.
@@ -3392,8 +3228,8 @@ retry:
                nid = zone_to_nid(zone);
 
                if (cpuset_zone_allowed_hardwall(zone, flags) &&
-                       cache->nodelists[nid] &&
-                       cache->nodelists[nid]->free_objects) {
+                       cache->node[nid] &&
+                       cache->node[nid]->free_objects) {
                                obj = ____cache_alloc_node(cache,
                                        flags | GFP_THISNODE, nid);
                                if (obj)
@@ -3449,21 +3285,21 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
 {
        struct list_head *entry;
        struct slab *slabp;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        void *obj;
        int x;
 
-       l3 = cachep->nodelists[nodeid];
-       BUG_ON(!l3);
+       n = cachep->node[nodeid];
+       BUG_ON(!n);
 
 retry:
        check_irq_off();
-       spin_lock(&l3->list_lock);
-       entry = l3->slabs_partial.next;
-       if (entry == &l3->slabs_partial) {
-               l3->free_touched = 1;
-               entry = l3->slabs_free.next;
-               if (entry == &l3->slabs_free)
+       spin_lock(&n->list_lock);
+       entry = n->slabs_partial.next;
+       if (entry == &n->slabs_partial) {
+               n->free_touched = 1;
+               entry = n->slabs_free.next;
+               if (entry == &n->slabs_free)
                        goto must_grow;
        }
 
@@ -3479,20 +3315,20 @@ retry:
 
        obj = slab_get_obj(cachep, slabp, nodeid);
        check_slabp(cachep, slabp);
-       l3->free_objects--;
+       n->free_objects--;
        /* move slabp to correct slabp list: */
        list_del(&slabp->list);
 
        if (slabp->free == BUFCTL_END)
-               list_add(&slabp->list, &l3->slabs_full);
+               list_add(&slabp->list, &n->slabs_full);
        else
-               list_add(&slabp->list, &l3->slabs_partial);
+               list_add(&slabp->list, &n->slabs_partial);
 
-       spin_unlock(&l3->list_lock);
+       spin_unlock(&n->list_lock);
        goto done;
 
 must_grow:
-       spin_unlock(&l3->list_lock);
+       spin_unlock(&n->list_lock);
        x = cache_grow(cachep, flags | GFP_THISNODE, nodeid, NULL);
        if (x)
                goto retry;
@@ -3530,13 +3366,15 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid,
        if (slab_should_failslab(cachep, flags))
                return NULL;
 
+       cachep = memcg_kmem_get_cache(cachep, flags);
+
        cache_alloc_debugcheck_before(cachep, flags);
        local_irq_save(save_flags);
 
        if (nodeid == NUMA_NO_NODE)
                nodeid = slab_node;
 
-       if (unlikely(!cachep->nodelists[nodeid])) {
+       if (unlikely(!cachep->node[nodeid])) {
                /* Node not bootstrapped yet */
                ptr = fallback_alloc(cachep, flags);
                goto out;
@@ -3615,6 +3453,8 @@ slab_alloc(struct kmem_cache *cachep, gfp_t flags, unsigned long caller)
        if (slab_should_failslab(cachep, flags))
                return NULL;
 
+       cachep = memcg_kmem_get_cache(cachep, flags);
+
        cache_alloc_debugcheck_before(cachep, flags);
        local_irq_save(save_flags);
        objp = __do_cache_alloc(cachep, flags);
@@ -3640,7 +3480,7 @@ static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects,
                       int node)
 {
        int i;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
 
        for (i = 0; i < nr_objects; i++) {
                void *objp;
@@ -3650,19 +3490,19 @@ static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects,
                objp = objpp[i];
 
                slabp = virt_to_slab(objp);
-               l3 = cachep->nodelists[node];
+               n = cachep->node[node];
                list_del(&slabp->list);
                check_spinlock_acquired_node(cachep, node);
                check_slabp(cachep, slabp);
                slab_put_obj(cachep, slabp, objp, node);
                STATS_DEC_ACTIVE(cachep);
-               l3->free_objects++;
+               n->free_objects++;
                check_slabp(cachep, slabp);
 
                /* fixup slab chains */
                if (slabp->inuse == 0) {
-                       if (l3->free_objects > l3->free_limit) {
-                               l3->free_objects -= cachep->num;
+                       if (n->free_objects > n->free_limit) {
+                               n->free_objects -= cachep->num;
                                /* No need to drop any previously held
                                 * lock here, even if we have a off-slab slab
                                 * descriptor it is guaranteed to come from
@@ -3671,14 +3511,14 @@ static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects,
                                 */
                                slab_destroy(cachep, slabp);
                        } else {
-                               list_add(&slabp->list, &l3->slabs_free);
+                               list_add(&slabp->list, &n->slabs_free);
                        }
                } else {
                        /* Unconditionally move a slab to the end of the
                         * partial list on free - maximum time for the
                         * other objects to be freed, too.
                         */
-                       list_add_tail(&slabp->list, &l3->slabs_partial);
+                       list_add_tail(&slabp->list, &n->slabs_partial);
                }
        }
 }
@@ -3686,7 +3526,7 @@ static void free_block(struct kmem_cache *cachep, void **objpp, int nr_objects,
 static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac)
 {
        int batchcount;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        int node = numa_mem_id();
 
        batchcount = ac->batchcount;
@@ -3694,10 +3534,10 @@ static void cache_flusharray(struct kmem_cache *cachep, struct array_cache *ac)
        BUG_ON(!batchcount || batchcount > ac->avail);
 #endif
        check_irq_off();
-       l3 = cachep->nodelists[node];
-       spin_lock(&l3->list_lock);
-       if (l3->shared) {
-               struct array_cache *shared_array = l3->shared;
+       n = cachep->node[node];
+       spin_lock(&n->list_lock);
+       if (n->shared) {
+               struct array_cache *shared_array = n->shared;
                int max = shared_array->limit - shared_array->avail;
                if (max) {
                        if (batchcount > max)
@@ -3716,8 +3556,8 @@ free_done:
                int i = 0;
                struct list_head *p;
 
-               p = l3->slabs_free.next;
-               while (p != &(l3->slabs_free)) {
+               p = n->slabs_free.next;
+               while (p != &(n->slabs_free)) {
                        struct slab *slabp;
 
                        slabp = list_entry(p, struct slab, list);
@@ -3729,7 +3569,7 @@ free_done:
                STATS_SET_FREEABLE(cachep, i);
        }
 #endif
-       spin_unlock(&l3->list_lock);
+       spin_unlock(&n->list_lock);
        ac->avail -= batchcount;
        memmove(ac->entry, &(ac->entry[batchcount]), sizeof(void *)*ac->avail);
 }
@@ -3839,7 +3679,7 @@ __do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller)
 {
        struct kmem_cache *cachep;
 
-       cachep = kmem_find_general_cachep(size, flags);
+       cachep = kmalloc_slab(size, flags);
        if (unlikely(ZERO_OR_NULL_PTR(cachep)))
                return cachep;
        return kmem_cache_alloc_node_trace(cachep, flags, node, size);
@@ -3884,7 +3724,7 @@ static __always_inline void *__do_kmalloc(size_t size, gfp_t flags,
         * Then kmalloc uses the uninlined functions instead of the inline
         * functions.
         */
-       cachep = __find_general_cachep(size, flags);
+       cachep = kmalloc_slab(size, flags);
        if (unlikely(ZERO_OR_NULL_PTR(cachep)))
                return cachep;
        ret = slab_alloc(cachep, flags, caller);
@@ -3928,6 +3768,9 @@ EXPORT_SYMBOL(__kmalloc);
 void kmem_cache_free(struct kmem_cache *cachep, void *objp)
 {
        unsigned long flags;
+       cachep = cache_from_obj(cachep, objp);
+       if (!cachep)
+               return;
 
        local_irq_save(flags);
        debug_check_no_locks_freed(objp, cachep->object_size);
@@ -3969,19 +3812,13 @@ void kfree(const void *objp)
 }
 EXPORT_SYMBOL(kfree);
 
-unsigned int kmem_cache_size(struct kmem_cache *cachep)
-{
-       return cachep->object_size;
-}
-EXPORT_SYMBOL(kmem_cache_size);
-
 /*
- * This initializes kmem_list3 or resizes various caches for all nodes.
+ * This initializes kmem_cache_node or resizes various caches for all nodes.
  */
 static int alloc_kmemlist(struct kmem_cache *cachep, gfp_t gfp)
 {
        int node;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        struct array_cache *new_shared;
        struct array_cache **new_alien = NULL;
 
@@ -4004,43 +3841,43 @@ static int alloc_kmemlist(struct kmem_cache *cachep, gfp_t gfp)
                        }
                }
 
-               l3 = cachep->nodelists[node];
-               if (l3) {
-                       struct array_cache *shared = l3->shared;
+               n = cachep->node[node];
+               if (n) {
+                       struct array_cache *shared = n->shared;
 
-                       spin_lock_irq(&l3->list_lock);
+                       spin_lock_irq(&n->list_lock);
 
                        if (shared)
                                free_block(cachep, shared->entry,
                                                shared->avail, node);
 
-                       l3->shared = new_shared;
-                       if (!l3->alien) {
-                               l3->alien = new_alien;
+                       n->shared = new_shared;
+                       if (!n->alien) {
+                               n->alien = new_alien;
                                new_alien = NULL;
                        }
-                       l3->free_limit = (1 + nr_cpus_node(node)) *
+                       n->free_limit = (1 + nr_cpus_node(node)) *
                                        cachep->batchcount + cachep->num;
-                       spin_unlock_irq(&l3->list_lock);
+                       spin_unlock_irq(&n->list_lock);
                        kfree(shared);
                        free_alien_cache(new_alien);
                        continue;
                }
-               l3 = kmalloc_node(sizeof(struct kmem_list3), gfp, node);
-               if (!l3) {
+               n = kmalloc_node(sizeof(struct kmem_cache_node), gfp, node);
+               if (!n) {
                        free_alien_cache(new_alien);
                        kfree(new_shared);
                        goto fail;
                }
 
-               kmem_list3_init(l3);
-               l3->next_reap = jiffies + REAPTIMEOUT_LIST3 +
+               kmem_cache_node_init(n);
+               n->next_reap = jiffies + REAPTIMEOUT_LIST3 +
                                ((unsigned long)cachep) % REAPTIMEOUT_LIST3;
-               l3->shared = new_shared;
-               l3->alien = new_alien;
-               l3->free_limit = (1 + nr_cpus_node(node)) *
+               n->shared = new_shared;
+               n->alien = new_alien;
+               n->free_limit = (1 + nr_cpus_node(node)) *
                                        cachep->batchcount + cachep->num;
-               cachep->nodelists[node] = l3;
+               cachep->node[node] = n;
        }
        return 0;
 
@@ -4049,13 +3886,13 @@ fail:
                /* Cache is not active yet. Roll back what we did */
                node--;
                while (node >= 0) {
-                       if (cachep->nodelists[node]) {
-                               l3 = cachep->nodelists[node];
+                       if (cachep->node[node]) {
+                               n = cachep->node[node];
 
-                               kfree(l3->shared);
-                               free_alien_cache(l3->alien);
-                               kfree(l3);
-                               cachep->nodelists[node] = NULL;
+                               kfree(n->shared);
+                               free_alien_cache(n->alien);
+                               kfree(n);
+                               cachep->node[node] = NULL;
                        }
                        node--;
                }
@@ -4081,7 +3918,7 @@ static void do_ccupdate_local(void *info)
 }
 
 /* Always called with the slab_mutex held */
-static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
+static int __do_tune_cpucache(struct kmem_cache *cachep, int limit,
                                int batchcount, int shared, gfp_t gfp)
 {
        struct ccupdate_struct *new;
@@ -4115,21 +3952,58 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
                struct array_cache *ccold = new->new[i];
                if (!ccold)
                        continue;
-               spin_lock_irq(&cachep->nodelists[cpu_to_mem(i)]->list_lock);
+               spin_lock_irq(&cachep->node[cpu_to_mem(i)]->list_lock);
                free_block(cachep, ccold->entry, ccold->avail, cpu_to_mem(i));
-               spin_unlock_irq(&cachep->nodelists[cpu_to_mem(i)]->list_lock);
+               spin_unlock_irq(&cachep->node[cpu_to_mem(i)]->list_lock);
                kfree(ccold);
        }
        kfree(new);
        return alloc_kmemlist(cachep, gfp);
 }
 
+static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
+                               int batchcount, int shared, gfp_t gfp)
+{
+       int ret;
+       struct kmem_cache *c = NULL;
+       int i = 0;
+
+       ret = __do_tune_cpucache(cachep, limit, batchcount, shared, gfp);
+
+       if (slab_state < FULL)
+               return ret;
+
+       if ((ret < 0) || !is_root_cache(cachep))
+               return ret;
+
+       VM_BUG_ON(!mutex_is_locked(&slab_mutex));
+       for_each_memcg_cache_index(i) {
+               c = cache_from_memcg(cachep, i);
+               if (c)
+                       /* return value determined by the parent cache only */
+                       __do_tune_cpucache(c, limit, batchcount, shared, gfp);
+       }
+
+       return ret;
+}
+
 /* Called with slab_mutex held always */
 static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp)
 {
        int err;
-       int limit, shared;
+       int limit = 0;
+       int shared = 0;
+       int batchcount = 0;
+
+       if (!is_root_cache(cachep)) {
+               struct kmem_cache *root = memcg_root_cache(cachep);
+               limit = root->limit;
+               shared = root->shared;
+               batchcount = root->batchcount;
+       }
 
+       if (limit && shared && batchcount)
+               goto skip_setup;
        /*
         * The head array serves three purposes:
         * - create a LIFO ordering, i.e. return objects that are cache-warm
@@ -4171,7 +4045,9 @@ static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp)
        if (limit > 32)
                limit = 32;
 #endif
-       err = do_tune_cpucache(cachep, limit, (limit + 1) / 2, shared, gfp);
+       batchcount = (limit + 1) / 2;
+skip_setup:
+       err = do_tune_cpucache(cachep, limit, batchcount, shared, gfp);
        if (err)
                printk(KERN_ERR "enable_cpucache failed for %s, error %d.\n",
                       cachep->name, -err);
@@ -4179,11 +4055,11 @@ static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp)
 }
 
 /*
- * Drain an array if it contains any elements taking the l3 lock only if
- * necessary. Note that the l3 listlock also protects the array_cache
+ * Drain an array if it contains any elements taking the node lock only if
+ * necessary. Note that the node listlock also protects the array_cache
  * if drain_array() is used on the shared array.
  */
-static void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3,
+static void drain_array(struct kmem_cache *cachep, struct kmem_cache_node *n,
                         struct array_cache *ac, int force, int node)
 {
        int tofree;
@@ -4193,7 +4069,7 @@ static void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3,
        if (ac->touched && !force) {
                ac->touched = 0;
        } else {
-               spin_lock_irq(&l3->list_lock);
+               spin_lock_irq(&n->list_lock);
                if (ac->avail) {
                        tofree = force ? ac->avail : (ac->limit + 4) / 5;
                        if (tofree > ac->avail)
@@ -4203,7 +4079,7 @@ static void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3,
                        memmove(ac->entry, &(ac->entry[tofree]),
                                sizeof(void *) * ac->avail);
                }
-               spin_unlock_irq(&l3->list_lock);
+               spin_unlock_irq(&n->list_lock);
        }
 }
 
@@ -4222,7 +4098,7 @@ static void drain_array(struct kmem_cache *cachep, struct kmem_list3 *l3,
 static void cache_reap(struct work_struct *w)
 {
        struct kmem_cache *searchp;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        int node = numa_mem_id();
        struct delayed_work *work = to_delayed_work(w);
 
@@ -4234,33 +4110,33 @@ static void cache_reap(struct work_struct *w)
                check_irq_on();
 
                /*
-                * We only take the l3 lock if absolutely necessary and we
+                * We only take the node lock if absolutely necessary and we
                 * have established with reasonable certainty that
                 * we can do some work if the lock was obtained.
                 */
-               l3 = searchp->nodelists[node];
+               n = searchp->node[node];
 
-               reap_alien(searchp, l3);
+               reap_alien(searchp, n);
 
-               drain_array(searchp, l3, cpu_cache_get(searchp), 0, node);
+               drain_array(searchp, n, cpu_cache_get(searchp), 0, node);
 
                /*
                 * These are racy checks but it does not matter
                 * if we skip one check or scan twice.
                 */
-               if (time_after(l3->next_reap, jiffies))
+               if (time_after(n->next_reap, jiffies))
                        goto next;
 
-               l3->next_reap = jiffies + REAPTIMEOUT_LIST3;
+               n->next_reap = jiffies + REAPTIMEOUT_LIST3;
 
-               drain_array(searchp, l3, l3->shared, 0, node);
+               drain_array(searchp, n, n->shared, 0, node);
 
-               if (l3->free_touched)
-                       l3->free_touched = 0;
+               if (n->free_touched)
+                       n->free_touched = 0;
                else {
                        int freed;
 
-                       freed = drain_freelist(searchp, l3, (l3->free_limit +
+                       freed = drain_freelist(searchp, n, (n->free_limit +
                                5 * searchp->num - 1) / (5 * searchp->num));
                        STATS_ADD_REAPED(searchp, freed);
                }
@@ -4286,25 +4162,25 @@ void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
        const char *name;
        char *error = NULL;
        int node;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
 
        active_objs = 0;
        num_slabs = 0;
        for_each_online_node(node) {
-               l3 = cachep->nodelists[node];
-               if (!l3)
+               n = cachep->node[node];
+               if (!n)
                        continue;
 
                check_irq_on();
-               spin_lock_irq(&l3->list_lock);
+               spin_lock_irq(&n->list_lock);
 
-               list_for_each_entry(slabp, &l3->slabs_full, list) {
+               list_for_each_entry(slabp, &n->slabs_full, list) {
                        if (slabp->inuse != cachep->num && !error)
                                error = "slabs_full accounting error";
                        active_objs += cachep->num;
                        active_slabs++;
                }
-               list_for_each_entry(slabp, &l3->slabs_partial, list) {
+               list_for_each_entry(slabp, &n->slabs_partial, list) {
                        if (slabp->inuse == cachep->num && !error)
                                error = "slabs_partial inuse accounting error";
                        if (!slabp->inuse && !error)
@@ -4312,16 +4188,16 @@ void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
                        active_objs += slabp->inuse;
                        active_slabs++;
                }
-               list_for_each_entry(slabp, &l3->slabs_free, list) {
+               list_for_each_entry(slabp, &n->slabs_free, list) {
                        if (slabp->inuse && !error)
                                error = "slabs_free/inuse accounting error";
                        num_slabs++;
                }
-               free_objects += l3->free_objects;
-               if (l3->shared)
-                       shared_avail += l3->shared->avail;
+               free_objects += n->free_objects;
+               if (n->shared)
+                       shared_avail += n->shared->avail;
 
-               spin_unlock_irq(&l3->list_lock);
+               spin_unlock_irq(&n->list_lock);
        }
        num_slabs += active_slabs;
        num_objs = num_slabs * cachep->num;
@@ -4347,7 +4223,7 @@ void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
 void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
 {
 #if STATS
-       {                       /* list3 stats */
+       {                       /* node stats */
                unsigned long high = cachep->high_mark;
                unsigned long allocs = cachep->num_allocations;
                unsigned long grown = cachep->grown;
@@ -4500,9 +4376,9 @@ static int leaks_show(struct seq_file *m, void *p)
 {
        struct kmem_cache *cachep = list_entry(p, struct kmem_cache, list);
        struct slab *slabp;
-       struct kmem_list3 *l3;
+       struct kmem_cache_node *n;
        const char *name;
-       unsigned long *n = m->private;
+       unsigned long *x = m->private;
        int node;
        int i;
 
@@ -4513,43 +4389,43 @@ static int leaks_show(struct seq_file *m, void *p)
 
        /* OK, we can do it */
 
-       n[1] = 0;
+       x[1] = 0;
 
        for_each_online_node(node) {
-               l3 = cachep->nodelists[node];
-               if (!l3)
+               n = cachep->node[node];
+               if (!n)
                        continue;
 
                check_irq_on();
-               spin_lock_irq(&l3->list_lock);
+               spin_lock_irq(&n->list_lock);
 
-               list_for_each_entry(slabp, &l3->slabs_full, list)
-                       handle_slab(n, cachep, slabp);
-               list_for_each_entry(slabp, &l3->slabs_partial, list)
-                       handle_slab(n, cachep, slabp);
-               spin_unlock_irq(&l3->list_lock);
+               list_for_each_entry(slabp, &n->slabs_full, list)
+                       handle_slab(x, cachep, slabp);
+               list_for_each_entry(slabp, &n->slabs_partial, list)
+                       handle_slab(x, cachep, slabp);
+               spin_unlock_irq(&n->list_lock);
        }
        name = cachep->name;
-       if (n[0] == n[1]) {
+       if (x[0] == x[1]) {
                /* Increase the buffer size */
                mutex_unlock(&slab_mutex);
-               m->private = kzalloc(n[0] * 4 * sizeof(unsigned long), GFP_KERNEL);
+               m->private = kzalloc(x[0] * 4 * sizeof(unsigned long), GFP_KERNEL);
                if (!m->private) {
                        /* Too bad, we are really out */
-                       m->private = n;
+                       m->private = x;
                        mutex_lock(&slab_mutex);
                        return -ENOMEM;
                }
-               *(unsigned long *)m->private = n[0] * 2;
-               kfree(n);
+               *(unsigned long *)m->private = x[0] * 2;
+               kfree(x);
                mutex_lock(&slab_mutex);
                /* Now make sure this entry will be retried */
                m->count = m->size;
                return 0;
        }
-       for (i = 0; i < n[1]; i++) {
-               seq_printf(m, "%s: %lu ", name, n[2*i+3]);
-               show_symbol(m, n[2*i+2]);
+       for (i = 0; i < x[1]; i++) {
+               seq_printf(m, "%s: %lu ", name, x[2*i+3]);
+               show_symbol(m, x[2*i+2]);
                seq_putc(m, '\n');
        }