mm/sl[aou]b: Use "kmem_cache" name for slab cache with kmem_cache struct
[firefly-linux-kernel-4.4.55.git] / mm / slab_common.c
index fe8dc943c285c5b3627fd9fc331cb504f552eb9f..5374150f54866c5ae33e75354d9fc7a2d7c47e67 100644 (file)
@@ -22,6 +22,7 @@
 enum slab_state slab_state;
 LIST_HEAD(slab_caches);
 DEFINE_MUTEX(slab_mutex);
+struct kmem_cache *kmem_cache;
 
 #ifdef CONFIG_DEBUG_VM
 static int kmem_cache_sanity_check(const char *name, size_t size)
@@ -111,6 +112,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
        if (!s)
                err = -ENOSYS; /* Until __kmem_cache_create returns code */
 
+       /*
+        * Check if the slab has actually been created and if it was a
+        * real instatiation. Aliases do not belong on the list
+        */
+       if (s && s->refcount == 1)
+               list_add(&s->list, &slab_caches);
+
 out_locked:
        mutex_unlock(&slab_mutex);
        put_online_cpus();
@@ -133,6 +141,31 @@ out_locked:
 }
 EXPORT_SYMBOL(kmem_cache_create);
 
+void kmem_cache_destroy(struct kmem_cache *s)
+{
+       get_online_cpus();
+       mutex_lock(&slab_mutex);
+       s->refcount--;
+       if (!s->refcount) {
+               list_del(&s->list);
+
+               if (!__kmem_cache_shutdown(s)) {
+                       if (s->flags & SLAB_DESTROY_BY_RCU)
+                               rcu_barrier();
+
+                       __kmem_cache_destroy(s);
+               } else {
+                       list_add(&s->list, &slab_caches);
+                       printk(KERN_ERR "kmem_cache_destroy %s: Slab cache still has objects\n",
+                               s->name);
+                       dump_stack();
+               }
+       }
+       mutex_unlock(&slab_mutex);
+       put_online_cpus();
+}
+EXPORT_SYMBOL(kmem_cache_destroy);
+
 int slab_is_available(void)
 {
        return slab_state >= UP;