mm/sl[aou]b: Use "kmem_cache" name for slab cache with kmem_cache struct
[firefly-linux-kernel-4.4.55.git] / mm / slob.c
index 74c3bb25f640424225d09d283753e21a110c91f7..7d272c3dcc083263088460961b62f757c45ce68b 100644 (file)
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -59,6 +59,8 @@
 
 #include <linux/kernel.h>
 #include <linux/slab.h>
+#include "slab.h"
+
 #include <linux/mm.h>
 #include <linux/swap.h> /* struct reclaim_state */
 #include <linux/cache.h>
@@ -91,14 +93,6 @@ struct slob_block {
 };
 typedef struct slob_block slob_t;
 
-/*
- * free_slob_page: call before a slob_page is returned to the page allocator.
- */
-static inline void free_slob_page(struct page *sp)
-{
-       reset_page_mapcount(sp);
-}
-
 /*
  * All partially free slob pages go on these lists.
  */
@@ -108,29 +102,6 @@ static LIST_HEAD(free_slob_small);
 static LIST_HEAD(free_slob_medium);
 static LIST_HEAD(free_slob_large);
 
-/*
- * is_slob_page: True for all slob pages (false for bigblock pages)
- */
-static inline int is_slob_page(struct page *sp)
-{
-       return PageSlab(sp);
-}
-
-static inline void set_slob_page(struct page *sp)
-{
-       __SetPageSlab(sp);
-}
-
-static inline void clear_slob_page(struct page *sp)
-{
-       __ClearPageSlab(sp);
-}
-
-static inline struct page *slob_page(const void *addr)
-{
-       return virt_to_page(addr);
-}
-
 /*
  * slob_page_free: true for pages on free_slob_pages list.
  */
@@ -347,8 +318,8 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
                b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
                if (!b)
                        return NULL;
-               sp = slob_page(b);
-               set_slob_page(sp);
+               sp = virt_to_page(b);
+               __SetPageSlab(sp);
 
                spin_lock_irqsave(&slob_lock, flags);
                sp->units = SLOB_UNITS(PAGE_SIZE);
@@ -380,7 +351,7 @@ static void slob_free(void *block, int size)
                return;
        BUG_ON(!size);
 
-       sp = slob_page(block);
+       sp = virt_to_page(block);
        units = SLOB_UNITS(size);
 
        spin_lock_irqsave(&slob_lock, flags);
@@ -390,8 +361,8 @@ static void slob_free(void *block, int size)
                if (slob_page_free(sp))
                        clear_slob_page_free(sp);
                spin_unlock_irqrestore(&slob_lock, flags);
-               clear_slob_page(sp);
-               free_slob_page(sp);
+               __ClearPageSlab(sp);
+               reset_page_mapcount(sp);
                slob_free_pages(b, 0);
                return;
        }
@@ -508,8 +479,8 @@ void kfree(const void *block)
                return;
        kmemleak_free(block);
 
-       sp = slob_page(block);
-       if (is_slob_page(sp)) {
+       sp = virt_to_page(block);
+       if (PageSlab(sp)) {
                int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
                unsigned int *m = (unsigned int *)(block - align);
                slob_free(m, *m + align);
@@ -527,8 +498,8 @@ size_t ksize(const void *block)
        if (unlikely(block == ZERO_SIZE_PTR))
                return 0;
 
-       sp = slob_page(block);
-       if (is_slob_page(sp)) {
+       sp = virt_to_page(block);
+       if (PageSlab(sp)) {
                int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
                unsigned int *m = (unsigned int *)(block - align);
                return SLOB_UNITS(*m) * SLOB_UNIT;
@@ -537,14 +508,7 @@ size_t ksize(const void *block)
 }
 EXPORT_SYMBOL(ksize);
 
-struct kmem_cache {
-       unsigned int size, align;
-       unsigned long flags;
-       const char *name;
-       void (*ctor)(void *);
-};
-
-struct kmem_cache *kmem_cache_create(const char *name, size_t size,
+struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
        size_t align, unsigned long flags, void (*ctor)(void *))
 {
        struct kmem_cache *c;
@@ -567,22 +531,18 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
                        c->align = ARCH_SLAB_MINALIGN;
                if (c->align < align)
                        c->align = align;
-       } else if (flags & SLAB_PANIC)
-               panic("Cannot create slab cache %s\n", name);
 
-       kmemleak_alloc(c, sizeof(struct kmem_cache), 1, GFP_KERNEL);
+               kmemleak_alloc(c, sizeof(struct kmem_cache), 1, GFP_KERNEL);
+               c->refcount = 1;
+       }
        return c;
 }
-EXPORT_SYMBOL(kmem_cache_create);
 
-void kmem_cache_destroy(struct kmem_cache *c)
+void __kmem_cache_destroy(struct kmem_cache *c)
 {
        kmemleak_free(c);
-       if (c->flags & SLAB_DESTROY_BY_RCU)
-               rcu_barrier();
        slob_free(c, sizeof(struct kmem_cache));
 }
-EXPORT_SYMBOL(kmem_cache_destroy);
 
 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
 {
@@ -650,25 +610,32 @@ unsigned int kmem_cache_size(struct kmem_cache *c)
 }
 EXPORT_SYMBOL(kmem_cache_size);
 
-int kmem_cache_shrink(struct kmem_cache *d)
+int __kmem_cache_shutdown(struct kmem_cache *c)
 {
+       /* No way to check for remaining objects */
        return 0;
 }
-EXPORT_SYMBOL(kmem_cache_shrink);
 
-static unsigned int slob_ready __read_mostly;
-
-int slab_is_available(void)
+int kmem_cache_shrink(struct kmem_cache *d)
 {
-       return slob_ready;
+       return 0;
 }
+EXPORT_SYMBOL(kmem_cache_shrink);
+
+struct kmem_cache kmem_cache_boot = {
+       .name = "kmem_cache",
+       .size = sizeof(struct kmem_cache),
+       .flags = SLAB_PANIC,
+       .align = ARCH_KMALLOC_MINALIGN,
+};
 
 void __init kmem_cache_init(void)
 {
-       slob_ready = 1;
+       kmem_cache = &kmem_cache_boot;
+       slab_state = UP;
 }
 
 void __init kmem_cache_init_late(void)
 {
-       /* Nothing to do */
+       slab_state = FULL;
 }