]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - mm/slab_common.c
memcg: zap memcg_name argument of memcg_create_kmem_cache
[karo-tx-linux.git] / mm / slab_common.c
index dcdab81bd240bafe3bec02cb32bf3390763a90e9..1b782a2d3b3d1a7006fcc027fc7895767a04c51f 100644 (file)
@@ -240,7 +240,7 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
        size = ALIGN(size, align);
        flags = kmem_cache_flags(size, flags, name, NULL);
 
-       list_for_each_entry(s, &slab_caches, list) {
+       list_for_each_entry_reverse(s, &slab_caches, list) {
                if (slab_unmergeable(s))
                        continue;
 
@@ -331,7 +331,7 @@ out:
 
 out_free_cache:
        memcg_free_cache_params(s);
-       kfree(s);
+       kmem_cache_free(kmem_cache, s);
        goto out;
 }
 
@@ -430,16 +430,15 @@ EXPORT_SYMBOL(kmem_cache_create);
  * memcg_create_kmem_cache - Create a cache for a memory cgroup.
  * @memcg: The memory cgroup the new cache is for.
  * @root_cache: The parent of the new cache.
- * @memcg_name: The name of the memory cgroup (used for naming the new cache).
  *
  * This function attempts to create a kmem cache that will serve allocation
  * requests going from @memcg to @root_cache. The new cache inherits properties
  * from its parent.
  */
 struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
-                                          struct kmem_cache *root_cache,
-                                          const char *memcg_name)
+                                          struct kmem_cache *root_cache)
 {
+       static char memcg_name_buf[NAME_MAX + 1]; /* protected by slab_mutex */
        struct kmem_cache *s = NULL;
        char *cache_name;
 
@@ -448,8 +447,10 @@ struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
 
        mutex_lock(&slab_mutex);
 
+       cgroup_name(mem_cgroup_css(memcg)->cgroup,
+                   memcg_name_buf, sizeof(memcg_name_buf));
        cache_name = kasprintf(GFP_KERNEL, "%s(%d:%s)", root_cache->name,
-                              memcg_cache_id(memcg), memcg_name);
+                              memcg_cache_id(memcg), memcg_name_buf);
        if (!cache_name)
                goto out_unlock;
 
@@ -811,7 +812,7 @@ EXPORT_SYMBOL(kmalloc_order_trace);
 #define SLABINFO_RIGHTS S_IRUSR
 #endif
 
-void print_slabinfo_header(struct seq_file *m)
+static void print_slabinfo_header(struct seq_file *m)
 {
        /*
         * Output format version, so at least we can change it
@@ -834,14 +835,9 @@ void print_slabinfo_header(struct seq_file *m)
        seq_putc(m, '\n');
 }
 
-static void *s_start(struct seq_file *m, loff_t *pos)
+void *slab_start(struct seq_file *m, loff_t *pos)
 {
-       loff_t n = *pos;
-
        mutex_lock(&slab_mutex);
-       if (!n)
-               print_slabinfo_header(m);
-
        return seq_list_start(&slab_caches, *pos);
 }
 
@@ -881,7 +877,7 @@ memcg_accumulate_slabinfo(struct kmem_cache *s, struct slabinfo *info)
        }
 }
 
-int cache_show(struct kmem_cache *s, struct seq_file *m)
+static void cache_show(struct kmem_cache *s, struct seq_file *m)
 {
        struct slabinfo sinfo;
 
@@ -900,17 +896,32 @@ int cache_show(struct kmem_cache *s, struct seq_file *m)
                   sinfo.active_slabs, sinfo.num_slabs, sinfo.shared_avail);
        slabinfo_show_stats(m, s);
        seq_putc(m, '\n');
+}
+
+static int slab_show(struct seq_file *m, void *p)
+{
+       struct kmem_cache *s = list_entry(p, struct kmem_cache, list);
+
+       if (p == slab_caches.next)
+               print_slabinfo_header(m);
+       if (is_root_cache(s))
+               cache_show(s, m);
        return 0;
 }
 
-static int s_show(struct seq_file *m, void *p)
+#ifdef CONFIG_MEMCG_KMEM
+int memcg_slab_show(struct seq_file *m, void *p)
 {
        struct kmem_cache *s = list_entry(p, struct kmem_cache, list);
+       struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
 
-       if (!is_root_cache(s))
-               return 0;
-       return cache_show(s, m);
+       if (p == slab_caches.next)
+               print_slabinfo_header(m);
+       if (!is_root_cache(s) && s->memcg_params->memcg == memcg)
+               cache_show(s, m);
+       return 0;
 }
+#endif
 
 /*
  * slabinfo_op - iterator that generates /proc/slabinfo
@@ -926,10 +937,10 @@ static int s_show(struct seq_file *m, void *p)
  * + further values on SMP and with statistics enabled
  */
 static const struct seq_operations slabinfo_op = {
-       .start = s_start,
+       .start = slab_start,
        .next = slab_next,
        .stop = slab_stop,
-       .show = s_show,
+       .show = slab_show,
 };
 
 static int slabinfo_open(struct inode *inode, struct file *file)