mm/memory_hotplug: use helper zone_is_zone_device() to simplify the code
[linux-2.6-microblaze.git] / mm / slab_common.c
index 7cab776..1c673c3 100644 (file)
@@ -377,11 +377,11 @@ out_unlock:
 
        if (err) {
                if (flags & SLAB_PANIC)
-                       panic("kmem_cache_create: Failed to create slab '%s'. Error %d\n",
-                               name, err);
+                       panic("%s: Failed to create slab '%s'. Error %d\n",
+                               __func__, name, err);
                else {
-                       pr_warn("kmem_cache_create(%s) failed with error %d\n",
-                               name, err);
+                       pr_warn("%s(%s) failed with error %d\n",
+                               __func__, name, err);
                        dump_stack();
                }
                return NULL;
@@ -448,6 +448,7 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)
        rcu_barrier();
 
        list_for_each_entry_safe(s, s2, &to_destroy, list) {
+               debugfs_slab_release(s);
                kfence_shutdown_cache(s);
 #ifdef SLAB_SUPPORTS_SYSFS
                sysfs_slab_release(s);
@@ -475,6 +476,7 @@ static int shutdown_cache(struct kmem_cache *s)
                schedule_work(&slab_caches_to_rcu_destroy_work);
        } else {
                kfence_shutdown_cache(s);
+               debugfs_slab_release(s);
 #ifdef SLAB_SUPPORTS_SYSFS
                sysfs_slab_unlink(s);
                sysfs_slab_release(s);
@@ -508,8 +510,8 @@ void kmem_cache_destroy(struct kmem_cache *s)
 
        err = shutdown_cache(s);
        if (err) {
-               pr_err("kmem_cache_destroy %s: Slab cache still has objects\n",
-                      s->name);
+               pr_err("%s %s: Slab cache still has objects\n",
+                      __func__, s->name);
                dump_stack();
        }
 out_unlock:
@@ -573,7 +575,7 @@ EXPORT_SYMBOL_GPL(kmem_valid_obj);
  * depends on the type of object and on how much debugging is enabled.
  * For a slab-cache object, the fact that it is a slab object is printed,
  * and, if available, the slab name, return address, and stack trace from
- * the allocation of that object.
+ * the allocation and last free path of that object.
  *
  * This function will splat if passed a pointer to a non-slab object.
  * If you are not sure what type of object you have, you should instead
@@ -618,6 +620,16 @@ void kmem_dump_obj(void *object)
                        break;
                pr_info("    %pS\n", kp.kp_stack[i]);
        }
+
+       if (kp.kp_free_stack[0])
+               pr_cont(" Free path:\n");
+
+       for (i = 0; i < ARRAY_SIZE(kp.kp_free_stack); i++) {
+               if (!kp.kp_free_stack[i])
+                       break;
+               pr_info("    %pS\n", kp.kp_free_stack[i]);
+       }
+
 }
 EXPORT_SYMBOL_GPL(kmem_dump_obj);
 #endif
@@ -736,26 +748,30 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
 }
 
 #ifdef CONFIG_ZONE_DMA
-#define INIT_KMALLOC_INFO(__size, __short_size)                        \
-{                                                              \
-       .name[KMALLOC_NORMAL]  = "kmalloc-" #__short_size,      \
-       .name[KMALLOC_RECLAIM] = "kmalloc-rcl-" #__short_size,  \
-       .name[KMALLOC_DMA]     = "dma-kmalloc-" #__short_size,  \
-       .size = __size,                                         \
-}
+#define KMALLOC_DMA_NAME(sz)   .name[KMALLOC_DMA] = "dma-kmalloc-" #sz,
+#else
+#define KMALLOC_DMA_NAME(sz)
+#endif
+
+#ifdef CONFIG_MEMCG_KMEM
+#define KMALLOC_CGROUP_NAME(sz)        .name[KMALLOC_CGROUP] = "kmalloc-cg-" #sz,
 #else
+#define KMALLOC_CGROUP_NAME(sz)
+#endif
+
 #define INIT_KMALLOC_INFO(__size, __short_size)                        \
 {                                                              \
        .name[KMALLOC_NORMAL]  = "kmalloc-" #__short_size,      \
        .name[KMALLOC_RECLAIM] = "kmalloc-rcl-" #__short_size,  \
+       KMALLOC_CGROUP_NAME(__short_size)                       \
+       KMALLOC_DMA_NAME(__short_size)                          \
        .size = __size,                                         \
 }
-#endif
 
 /*
  * kmalloc_info[] is to make slub_debug=,kmalloc-xx option work at boot time.
- * kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is
- * kmalloc-67108864.
+ * kmalloc_index() supports up to 2^25=32MB, so the final entry of the table is
+ * kmalloc-32M.
  */
 const struct kmalloc_info_struct kmalloc_info[] __initconst = {
        INIT_KMALLOC_INFO(0, 0),
@@ -783,8 +799,7 @@ const struct kmalloc_info_struct kmalloc_info[] __initconst = {
        INIT_KMALLOC_INFO(4194304, 4M),
        INIT_KMALLOC_INFO(8388608, 8M),
        INIT_KMALLOC_INFO(16777216, 16M),
-       INIT_KMALLOC_INFO(33554432, 32M),
-       INIT_KMALLOC_INFO(67108864, 64M)
+       INIT_KMALLOC_INFO(33554432, 32M)
 };
 
 /*
@@ -837,13 +852,27 @@ void __init setup_kmalloc_cache_index_table(void)
 static void __init
 new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags)
 {
-       if (type == KMALLOC_RECLAIM)
+       if (type == KMALLOC_RECLAIM) {
                flags |= SLAB_RECLAIM_ACCOUNT;
+       } else if (IS_ENABLED(CONFIG_MEMCG_KMEM) && (type == KMALLOC_CGROUP)) {
+               if (cgroup_memory_nokmem) {
+                       kmalloc_caches[type][idx] = kmalloc_caches[KMALLOC_NORMAL][idx];
+                       return;
+               }
+               flags |= SLAB_ACCOUNT;
+       }
 
        kmalloc_caches[type][idx] = create_kmalloc_cache(
                                        kmalloc_info[idx].name[type],
                                        kmalloc_info[idx].size, flags, 0,
                                        kmalloc_info[idx].size);
+
+       /*
+        * If CONFIG_MEMCG_KMEM is enabled, disable cache merging for
+        * KMALLOC_NORMAL caches.
+        */
+       if (IS_ENABLED(CONFIG_MEMCG_KMEM) && (type == KMALLOC_NORMAL))
+               kmalloc_caches[type][idx]->refcount = -1;
 }
 
 /*
@@ -856,6 +885,9 @@ void __init create_kmalloc_caches(slab_flags_t flags)
        int i;
        enum kmalloc_cache_type type;
 
+       /*
+        * Including KMALLOC_CGROUP if CONFIG_MEMCG_KMEM defined
+        */
        for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) {
                for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
                        if (!kmalloc_caches[type][i])