Merge tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / mm / slab.c
index de91d6f..a467b30 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -191,7 +191,6 @@ struct array_cache {
        unsigned int limit;
        unsigned int batchcount;
        unsigned int touched;
-       spinlock_t lock;
        void *entry[];  /*
                         * Must have this definition in here for the proper
                         * alignment of array_cache. Also simplifies accessing
@@ -473,139 +472,6 @@ static struct kmem_cache kmem_cache_boot = {
 
 #define BAD_ALIEN_MAGIC 0x01020304ul
 
-#ifdef CONFIG_LOCKDEP
-
-/*
- * Slab sometimes uses the kmalloc slabs to store the slab headers
- * for other slabs "off slab".
- * The locking for this is tricky in that it nests within the locks
- * of all other slabs in a few places; to deal with this special
- * locking we put on-slab caches into a separate lock-class.
- *
- * We set lock class for alien array caches which are up during init.
- * The lock annotation will be lost if all cpus of a node goes down and
- * then comes back up during hotplug
- */
-static struct lock_class_key on_slab_l3_key;
-static struct lock_class_key on_slab_alc_key;
-
-static struct lock_class_key debugobj_l3_key;
-static struct lock_class_key debugobj_alc_key;
-
-static void slab_set_lock_classes(struct kmem_cache *cachep,
-               struct lock_class_key *l3_key, struct lock_class_key *alc_key,
-               struct kmem_cache_node *n)
-{
-       struct alien_cache **alc;
-       int r;
-
-       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
-        * work even without alien caches.
-        * Currently, non NUMA code returns BAD_ALIEN_MAGIC
-        * for alloc_alien_cache,
-        */
-       if (!alc || (unsigned long)alc == BAD_ALIEN_MAGIC)
-               return;
-       for_each_node(r) {
-               if (alc[r])
-                       lockdep_set_class(&(alc[r]->ac.lock), alc_key);
-       }
-}
-
-static void slab_set_debugobj_lock_classes_node(struct kmem_cache *cachep,
-       struct kmem_cache_node *n)
-{
-       slab_set_lock_classes(cachep, &debugobj_l3_key, &debugobj_alc_key, n);
-}
-
-static void slab_set_debugobj_lock_classes(struct kmem_cache *cachep)
-{
-       int node;
-       struct kmem_cache_node *n;
-
-       for_each_kmem_cache_node(cachep, node, n)
-               slab_set_debugobj_lock_classes_node(cachep, n);
-}
-
-static void init_node_lock_keys(int q)
-{
-       int i;
-
-       if (slab_state < UP)
-               return;
-
-       for (i = 1; i <= KMALLOC_SHIFT_HIGH; i++) {
-               struct kmem_cache_node *n;
-               struct kmem_cache *cache = kmalloc_caches[i];
-
-               if (!cache)
-                       continue;
-
-               n = get_node(cache, q);
-               if (!n || OFF_SLAB(cache))
-                       continue;
-
-               slab_set_lock_classes(cache, &on_slab_l3_key,
-                               &on_slab_alc_key, n);
-       }
-}
-
-static void on_slab_lock_classes_node(struct kmem_cache *cachep,
-       struct kmem_cache_node *n)
-{
-       slab_set_lock_classes(cachep, &on_slab_l3_key,
-                       &on_slab_alc_key, n);
-}
-
-static inline void on_slab_lock_classes(struct kmem_cache *cachep)
-{
-       int node;
-       struct kmem_cache_node *n;
-
-       VM_BUG_ON(OFF_SLAB(cachep));
-       for_each_kmem_cache_node(cachep, node, n)
-               on_slab_lock_classes_node(cachep, n);
-}
-
-static inline void __init init_lock_keys(void)
-{
-       int node;
-
-       for_each_node(node)
-               init_node_lock_keys(node);
-}
-#else
-static void __init init_node_lock_keys(int q)
-{
-}
-
-static inline void init_lock_keys(void)
-{
-}
-
-static inline void on_slab_lock_classes(struct kmem_cache *cachep)
-{
-}
-
-static inline void on_slab_lock_classes_node(struct kmem_cache *cachep,
-       struct kmem_cache_node *n)
-{
-}
-
-static void slab_set_debugobj_lock_classes_node(struct kmem_cache *cachep,
-       struct kmem_cache_node *n)
-{
-}
-
-static void slab_set_debugobj_lock_classes(struct kmem_cache *cachep)
-{
-}
-#endif
-
 static DEFINE_PER_CPU(struct delayed_work, slab_reap_work);
 
 static inline struct array_cache *cpu_cache_get(struct kmem_cache *cachep)
@@ -811,14 +677,13 @@ static void init_arraycache(struct array_cache *ac, int limit, int batch)
                ac->limit = limit;
                ac->batchcount = batch;
                ac->touched = 0;
-               spin_lock_init(&ac->lock);
        }
 }
 
 static struct array_cache *alloc_arraycache(int node, int entries,
                                            int batchcount, gfp_t gfp)
 {
-       int memsize = sizeof(void *) * entries + sizeof(struct array_cache);
+       size_t memsize = sizeof(void *) * entries + sizeof(struct array_cache);
        struct array_cache *ac = NULL;
 
        ac = kmalloc_node(memsize, gfp, node);
@@ -1005,18 +870,19 @@ static void *alternate_node_alloc(struct kmem_cache *, gfp_t);
 static struct alien_cache *__alloc_alien_cache(int node, int entries,
                                                int batch, gfp_t gfp)
 {
-       int memsize = sizeof(void *) * entries + sizeof(struct alien_cache);
+       size_t memsize = sizeof(void *) * entries + sizeof(struct alien_cache);
        struct alien_cache *alc = NULL;
 
        alc = kmalloc_node(memsize, gfp, node);
        init_arraycache(&alc->ac, entries, batch);
+       spin_lock_init(&alc->lock);
        return alc;
 }
 
 static struct alien_cache **alloc_alien_cache(int node, int limit, gfp_t gfp)
 {
        struct alien_cache **alc_ptr;
-       int memsize = sizeof(void *) * nr_node_ids;
+       size_t memsize = sizeof(void *) * nr_node_ids;
        int i;
 
        if (limit > 1)
@@ -1051,10 +917,10 @@ static void free_alien_cache(struct alien_cache **alc_ptr)
 }
 
 static void __drain_alien_cache(struct kmem_cache *cachep,
-                               struct array_cache *ac, int node)
+                               struct array_cache *ac, int node,
+                               struct list_head *list)
 {
        struct kmem_cache_node *n = get_node(cachep, node);
-       LIST_HEAD(list);
 
        if (ac->avail) {
                spin_lock(&n->list_lock);
@@ -1066,10 +932,9 @@ static void __drain_alien_cache(struct kmem_cache *cachep,
                if (n->shared)
                        transfer_objects(n->shared, ac, ac->limit);
 
-               free_block(cachep, ac->entry, ac->avail, node, &list);
+               free_block(cachep, ac->entry, ac->avail, node, list);
                ac->avail = 0;
                spin_unlock(&n->list_lock);
-               slabs_destroy(cachep, &list);
        }
 }
 
@@ -1086,9 +951,12 @@ static void reap_alien(struct kmem_cache *cachep, struct kmem_cache_node *n)
 
                if (alc) {
                        ac = &alc->ac;
-                       if (ac->avail && spin_trylock_irq(&ac->lock)) {
-                               __drain_alien_cache(cachep, ac, node);
-                               spin_unlock_irq(&ac->lock);
+                       if (ac->avail && spin_trylock_irq(&alc->lock)) {
+                               LIST_HEAD(list);
+
+                               __drain_alien_cache(cachep, ac, node, &list);
+                               spin_unlock_irq(&alc->lock);
+                               slabs_destroy(cachep, &list);
                        }
                }
        }
@@ -1105,10 +973,13 @@ static void drain_alien_cache(struct kmem_cache *cachep,
        for_each_online_node(i) {
                alc = alien[i];
                if (alc) {
+                       LIST_HEAD(list);
+
                        ac = &alc->ac;
-                       spin_lock_irqsave(&ac->lock, flags);
-                       __drain_alien_cache(cachep, ac, i);
-                       spin_unlock_irqrestore(&ac->lock, flags);
+                       spin_lock_irqsave(&alc->lock, flags);
+                       __drain_alien_cache(cachep, ac, i, &list);
+                       spin_unlock_irqrestore(&alc->lock, flags);
+                       slabs_destroy(cachep, &list);
                }
        }
 }
@@ -1136,13 +1007,14 @@ static inline int cache_free_alien(struct kmem_cache *cachep, void *objp)
        if (n->alien && n->alien[nodeid]) {
                alien = n->alien[nodeid];
                ac = &alien->ac;
-               spin_lock(&ac->lock);
+               spin_lock(&alien->lock);
                if (unlikely(ac->avail == ac->limit)) {
                        STATS_INC_ACOVERFLOW(cachep);
-                       __drain_alien_cache(cachep, ac, nodeid);
+                       __drain_alien_cache(cachep, ac, nodeid, &list);
                }
                ac_put_obj(cachep, ac, objp);
-               spin_unlock(&ac->lock);
+               spin_unlock(&alien->lock);
+               slabs_destroy(cachep, &list);
        } else {
                n = get_node(cachep, nodeid);
                spin_lock(&n->list_lock);
@@ -1167,7 +1039,7 @@ static int init_cache_node_node(int node)
 {
        struct kmem_cache *cachep;
        struct kmem_cache_node *n;
-       const int memsize = sizeof(struct kmem_cache_node);
+       const size_t memsize = sizeof(struct kmem_cache_node);
 
        list_for_each_entry(cachep, &slab_caches, list) {
                /*
@@ -1343,13 +1215,7 @@ static int cpuup_prepare(long cpu)
                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, n);
-               else if (!OFF_SLAB(cachep) &&
-                        !(cachep->flags & SLAB_DESTROY_BY_RCU))
-                       on_slab_lock_classes_node(cachep, n);
        }
-       init_node_lock_keys(node);
 
        return 0;
 bad:
@@ -1613,10 +1479,6 @@ void __init kmem_cache_init(void)
 
                memcpy(ptr, cpu_cache_get(kmem_cache),
                       sizeof(struct arraycache_init));
-               /*
-                * Do not assume that spinlocks can be initialized via memcpy:
-                */
-               spin_lock_init(&ptr->lock);
 
                kmem_cache->array[smp_processor_id()] = ptr;
 
@@ -1626,10 +1488,6 @@ void __init kmem_cache_init(void)
                       != &initarray_generic.cache);
                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);
 
                kmalloc_caches[INDEX_AC]->array[smp_processor_id()] = ptr;
        }
@@ -1666,9 +1524,6 @@ void __init kmem_cache_init_late(void)
                        BUG();
        mutex_unlock(&slab_mutex);
 
-       /* Annotate slab for lockdep -- annotate the malloc caches */
-       init_lock_keys();
-
        /* Done! */
        slab_state = FULL;
 
@@ -1758,7 +1613,8 @@ slab_out_of_memory(struct kmem_cache *cachep, gfp_t gfpflags, int nodeid)
 }
 
 /*
- * Interface to system's page allocator. No need to hold the cache-lock.
+ * Interface to system's page allocator. No need to hold the
+ * kmem_cache_node ->list_lock.
  *
  * If we requested dmaable memory, we will get it. Even if we
  * did not request dmaable memory, we might get it, but that
@@ -2060,9 +1916,9 @@ static void slab_destroy_debugcheck(struct kmem_cache *cachep,
  * @cachep: cache pointer being destroyed
  * @page: page pointer being destroyed
  *
- * Destroy all the objs in a slab, and release the mem back to the system.
- * Before calling the slab must have been unlinked from the cache.  The
- * cache-lock is not held/needed.
+ * Destroy all the objs in a slab page, and release the mem back to the system.
+ * Before calling the slab page must have been unlinked from the cache. The
+ * kmem_cache_node ->list_lock is not held/needed.
  */
 static void slab_destroy(struct kmem_cache *cachep, struct page *page)
 {
@@ -2449,17 +2305,6 @@ __kmem_cache_create (struct kmem_cache *cachep, unsigned long flags)
                return err;
        }
 
-       if (flags & SLAB_DEBUG_OBJECTS) {
-               /*
-                * Would deadlock through slab_destroy()->call_rcu()->
-                * debug_object_activate()->kmem_cache_alloc().
-                */
-               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;
 }