slab: link memcg caches of the same kind into a list
authorVladimir Davydov <vdavydov@parallels.com>
Thu, 12 Feb 2015 22:59:23 +0000 (14:59 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 13 Feb 2015 02:54:09 +0000 (18:54 -0800)
Sometimes, we need to iterate over all memcg copies of a particular root
kmem cache.  Currently, we use memcg_cache_params->memcg_caches array for
that, because it contains all existing memcg caches.

However, it's a bad practice to keep all caches, including those that
belong to offline cgroups, in this array, because it will be growing
beyond any bounds then.  I'm going to wipe away dead caches from it to
save space.  To still be able to perform iterations over all memcg caches
of the same kind, let us link them into a list.

Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Dave Chinner <david@fromorbit.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/slab.h
mm/slab.c
mm/slab.h
mm/slab_common.c
mm/slub.c

index 1e03c11..26d99f4 100644 (file)
@@ -491,9 +491,13 @@ struct memcg_cache_array {
  *
  * @memcg: pointer to the memcg this cache belongs to
  * @root_cache: pointer to the global, root cache, this cache was derived from
+ *
+ * Both root and child caches of the same kind are linked into a list chained
+ * through @list.
  */
 struct memcg_cache_params {
        bool is_root_cache;
+       struct list_head list;
        union {
                struct memcg_cache_array __rcu *memcg_caches;
                struct {
index 65b5dcb..7894017 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3708,8 +3708,7 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
                                int batchcount, int shared, gfp_t gfp)
 {
        int ret;
-       struct kmem_cache *c = NULL;
-       int i = 0;
+       struct kmem_cache *c;
 
        ret = __do_tune_cpucache(cachep, limit, batchcount, shared, gfp);
 
@@ -3719,12 +3718,10 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
        if ((ret < 0) || !is_root_cache(cachep))
                return ret;
 
-       VM_BUG_ON(!mutex_is_locked(&slab_mutex));
-       for_each_memcg_cache_index(i) {
-               c = cache_from_memcg_idx(cachep, i);
-               if (c)
-                       /* return value determined by the parent cache only */
-                       __do_tune_cpucache(c, limit, batchcount, shared, gfp);
+       lockdep_assert_held(&slab_mutex);
+       for_each_memcg_cache(c, cachep) {
+               /* return value determined by the root cache only */
+               __do_tune_cpucache(c, limit, batchcount, shared, gfp);
        }
 
        return ret;
diff --cc mm/slab.h
Simple merge
Simple merge
diff --cc mm/slub.c
Simple merge