mm/slab: move kmalloc_slab() to mm/slab.h
[sfrench/cifs-2.6.git] / mm / slab_common.c
index f4f275613d2a783f0835cf5c41c20b4cdfe6586f..31ade17a7ad9b3588c56219f3be53474169eab25 100644 (file)
@@ -665,7 +665,7 @@ EXPORT_SYMBOL(random_kmalloc_seed);
  * of two cache sizes there. The size of larger slabs can be determined using
  * fls.
  */
-static u8 size_index[24] __ro_after_init = {
+u8 kmalloc_size_index[24] __ro_after_init = {
        3,      /* 8 */
        4,      /* 16 */
        5,      /* 24 */
@@ -692,33 +692,6 @@ static u8 size_index[24] __ro_after_init = {
        2       /* 192 */
 };
 
-static inline unsigned int size_index_elem(unsigned int bytes)
-{
-       return (bytes - 1) / 8;
-}
-
-/*
- * Find the kmem_cache structure that serves a given size of
- * allocation
- */
-struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags, unsigned long caller)
-{
-       unsigned int index;
-
-       if (size <= 192) {
-               if (!size)
-                       return ZERO_SIZE_PTR;
-
-               index = size_index[size_index_elem(size)];
-       } else {
-               if (WARN_ON_ONCE(size > KMALLOC_MAX_CACHE_SIZE))
-                       return NULL;
-               index = fls(size - 1);
-       }
-
-       return kmalloc_caches[kmalloc_type(flags, caller)][index];
-}
-
 size_t kmalloc_size_roundup(size_t size)
 {
        if (size && size <= KMALLOC_MAX_CACHE_SIZE) {
@@ -843,9 +816,9 @@ void __init setup_kmalloc_cache_index_table(void)
        for (i = 8; i < KMALLOC_MIN_SIZE; i += 8) {
                unsigned int elem = size_index_elem(i);
 
-               if (elem >= ARRAY_SIZE(size_index))
+               if (elem >= ARRAY_SIZE(kmalloc_size_index))
                        break;
-               size_index[elem] = KMALLOC_SHIFT_LOW;
+               kmalloc_size_index[elem] = KMALLOC_SHIFT_LOW;
        }
 
        if (KMALLOC_MIN_SIZE >= 64) {
@@ -854,7 +827,7 @@ void __init setup_kmalloc_cache_index_table(void)
                 * is 64 byte.
                 */
                for (i = 64 + 8; i <= 96; i += 8)
-                       size_index[size_index_elem(i)] = 7;
+                       kmalloc_size_index[size_index_elem(i)] = 7;
 
        }
 
@@ -865,7 +838,7 @@ void __init setup_kmalloc_cache_index_table(void)
                 * instead.
                 */
                for (i = 128 + 8; i <= 192; i += 8)
-                       size_index[size_index_elem(i)] = 8;
+                       kmalloc_size_index[size_index_elem(i)] = 8;
        }
 }
 
@@ -977,10 +950,10 @@ void *__do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller
                return ret;
        }
 
-       s = kmalloc_slab(size, flags, caller);
+       if (unlikely(!size))
+               return ZERO_SIZE_PTR;
 
-       if (unlikely(ZERO_OR_NULL_PTR(s)))
-               return s;
+       s = kmalloc_slab(size, flags, caller);
 
        ret = __kmem_cache_alloc_node(s, flags, node, size, caller);
        ret = kasan_kmalloc(s, ret, size, flags);