]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
slab: propagate tunable values
authorGlauber Costa <glommer@parallels.com>
Fri, 9 Nov 2012 03:04:18 +0000 (14:04 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Mon, 12 Nov 2012 04:17:04 +0000 (15:17 +1100)
SLAB allows us to tune a particular cache behavior with tunables.  When
creating a new memcg cache copy, we'd like to preserve any tunables the
parent cache already had.

This could be done by an explicit call to do_tune_cpucache() after the
cache is created.  But this is not very convenient now that the caches are
created from common code, since this function is SLAB-specific.

Another method of doing that is taking advantage of the fact that
do_tune_cpucache() is always called from enable_cpucache(), which is
called at cache initialization.  We can just preset the values, and then
things work as expected.

It can also happen that a root cache has its tunables updated during
normal system operation.  In this case, we will propagate the change to
all caches that are already active.

This change will require us to move the assignment of root_cache in
memcg_params a bit earlier.  We need this to be already set - which
memcg_kmem_register_cache will do - when we reach __kmem_cache_create()

Signed-off-by: Glauber Costa <glommer@parallels.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Frederic Weisbecker <fweisbec@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: JoonSoo Kim <js1304@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Rik van Riel <riel@redhat.com>
Cc: Suleiman Souhlal <suleiman@google.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/memcontrol.h
include/linux/slab.h
mm/memcontrol.c
mm/slab.c
mm/slab.h
mm/slab_common.c

index c780dd6bfc542b4ab8f9b89578224f4bec58e910..c91e3c15a913366d5c4a93c1eb799685ec43bcb2 100644 (file)
@@ -441,7 +441,8 @@ void __memcg_kmem_commit_charge(struct page *page,
 void __memcg_kmem_uncharge_pages(struct page *page, int order);
 
 int memcg_cache_id(struct mem_cgroup *memcg);
-int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s);
+int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s,
+                        struct kmem_cache *root_cache);
 void memcg_release_cache(struct kmem_cache *cachep);
 void memcg_cache_list_add(struct mem_cgroup *memcg, struct kmem_cache *cachep);
 
@@ -583,8 +584,9 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg)
        return -1;
 }
 
-static inline int memcg_register_cache(struct mem_cgroup *memcg,
-                                      struct kmem_cache *s)
+static inline int
+memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s,
+                    struct kmem_cache *root_cache)
 {
        return 0;
 }
index bcec2722af9d87336bf3e3a94fd5f05fca47f39c..e54291e646c1fbf1f2d3e83a7e145921d8ca0a37 100644 (file)
@@ -128,7 +128,7 @@ struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
                        void (*)(void *));
 struct kmem_cache *
 kmem_cache_create_memcg(struct mem_cgroup *, const char *, size_t, size_t,
-                       unsigned long, void (*)(void *));
+                       unsigned long, void (*)(void *), struct kmem_cache *);
 void kmem_cache_destroy(struct kmem_cache *);
 int kmem_cache_shrink(struct kmem_cache *);
 void kmem_cache_free(struct kmem_cache *, void *);
index 34712c91b66ab768e2babc3b0f3b4069b4659395..60f966c3b0521ce07936edceeded4d3220f1d695 100644 (file)
@@ -2989,7 +2989,8 @@ int memcg_update_cache_size(struct kmem_cache *s, int num_groups)
        return 0;
 }
 
-int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s)
+int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s,
+                        struct kmem_cache *root_cache)
 {
        size_t size = sizeof(struct memcg_cache_params);
 
@@ -3003,8 +3004,10 @@ int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s)
        if (!s->memcg_params)
                return -ENOMEM;
 
-       if (memcg)
+       if (memcg) {
                s->memcg_params->memcg = memcg;
+               s->memcg_params->root_cache = root_cache;
+       }
        return 0;
 }
 
@@ -3170,7 +3173,7 @@ static struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg,
                return NULL;
 
        new = kmem_cache_create_memcg(memcg, name, s->object_size, s->align,
-                                     (s->flags & ~SLAB_PANIC), s->ctor);
+                                     (s->flags & ~SLAB_PANIC), s->ctor, s);
 
        if (new)
                new->allocflags |= __GFP_KMEMCG;
@@ -3214,7 +3217,6 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
        }
 
        mem_cgroup_get(memcg);
-       new_cachep->memcg_params->root_cache = cachep;
        atomic_set(&new_cachep->memcg_params->nr_pages , 0);
 
        cachep->memcg_params->memcg_caches[idx] = new_cachep;
index 90538b77e114e0d10bedc13d1c3352bd8b25cf58..d87a28ba5779afe7ca5076e817689763f2a01c21 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4096,7 +4096,7 @@ static void do_ccupdate_local(void *info)
 }
 
 /* Always called with the slab_mutex held */
-static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
+static int __do_tune_cpucache(struct kmem_cache *cachep, int limit,
                                int batchcount, int shared, gfp_t gfp)
 {
        struct ccupdate_struct *new;
@@ -4139,12 +4139,48 @@ static int do_tune_cpucache(struct kmem_cache *cachep, int limit,
        return alloc_kmemlist(cachep, gfp);
 }
 
+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;
+
+       ret = __do_tune_cpucache(cachep, limit, batchcount, shared, gfp);
+
+       if (slab_state < FULL)
+               return ret;
+
+       if ((ret < 0) || !is_root_cache(cachep))
+               return ret;
+
+       for_each_memcg_cache_index(i) {
+               c = cache_from_memcg(cachep, i);
+               if (c)
+                       /* return value determined by the parent cache only */
+                       __do_tune_cpucache(c, limit, batchcount, shared, gfp);
+       }
+
+       return ret;
+}
+
 /* Called with slab_mutex held always */
 static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp)
 {
        int err;
-       int limit, shared;
+       int limit = 0;
+       int shared = 0;
+       int batchcount = 0;
+
+       if (!is_root_cache(cachep)) {
+               struct kmem_cache *root = memcg_root_cache(cachep);
+               limit = root->limit;
+               shared = root->shared;
+               batchcount = root->batchcount;
+       }
 
+       if (limit && shared && batchcount)
+               goto skip_setup;
        /*
         * The head array serves three purposes:
         * - create a LIFO ordering, i.e. return objects that are cache-warm
@@ -4186,7 +4222,9 @@ static int enable_cpucache(struct kmem_cache *cachep, gfp_t gfp)
        if (limit > 32)
                limit = 32;
 #endif
-       err = do_tune_cpucache(cachep, limit, (limit + 1) / 2, shared, gfp);
+       batchcount = (limit + 1) / 2;
+skip_setup:
+       err = do_tune_cpucache(cachep, limit, batchcount, shared, gfp);
        if (err)
                printk(KERN_ERR "enable_cpucache failed for %s, error %d.\n",
                       cachep->name, -err);
index 08ef4689100ae4862c640d3256089287a94242ff..9fc04b036796d8c8550a94567724726fbef4a74a 100644 (file)
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -147,6 +147,13 @@ static inline struct kmem_cache *cache_from_memcg(struct kmem_cache *s, int idx)
 {
        return s->memcg_params->memcg_caches[idx];
 }
+
+static inline struct kmem_cache *memcg_root_cache(struct kmem_cache *s)
+{
+       if (is_root_cache(s))
+               return s;
+       return s->memcg_params->root_cache;
+}
 #else
 static inline bool is_root_cache(struct kmem_cache *s)
 {
@@ -182,6 +189,11 @@ static inline struct kmem_cache *cache_from_memcg(struct kmem_cache *s, int idx)
 {
        return NULL;
 }
+
+static inline struct kmem_cache *memcg_root_cache(struct kmem_cache *s)
+{
+       return s;
+}
 #endif
 
 static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
index 9a6f421288272849e5326eb10978d59317fc8614..34743d89dc36523fa08c21c4866f8fe7aacd2182 100644 (file)
@@ -136,7 +136,8 @@ out:
 
 struct kmem_cache *
 kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
-                       size_t align, unsigned long flags, void (*ctor)(void *))
+                       size_t align, unsigned long flags, void (*ctor)(void *),
+                       struct kmem_cache *parent_cache)
 {
        struct kmem_cache *s = NULL;
        int err = 0;
@@ -165,7 +166,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
                s->align = align;
                s->ctor = ctor;
 
-               if (memcg_register_cache(memcg, s)) {
+               if (memcg_register_cache(memcg, s, parent_cache)) {
                        kmem_cache_free(kmem_cache, s);
                        err = -ENOMEM;
                        goto out_locked;
@@ -215,7 +216,7 @@ struct kmem_cache *
 kmem_cache_create(const char *name, size_t size, size_t align,
                  unsigned long flags, void (*ctor)(void *))
 {
-       return kmem_cache_create_memcg(NULL, name, size, align, flags, ctor);
+       return kmem_cache_create_memcg(NULL, name, size, align, flags, ctor, NULL);
 }
 EXPORT_SYMBOL(kmem_cache_create);