]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
memcg: mark caches that belong to offline memcgs as dead
authorVladimir Davydov <vdavydov@parallels.com>
Thu, 26 Jun 2014 00:42:30 +0000 (10:42 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 26 Jun 2014 00:42:30 +0000 (10:42 +1000)
This will be used by the next patches.

Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/slab.h
mm/memcontrol.c
mm/slab.h

index d9716fdc8211c175274aa561734b1580e28363c2..d99d5212b8151a8a7ffd0af78ebf5ec17358b308 100644 (file)
@@ -527,6 +527,7 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
  * @list: list_head for the list of all caches in this memcg
  * @root_cache: pointer to the global, root cache, this cache was derived from
  * @refcnt: reference counter
+ * @dead: set to true when owner memcg is turned offline
  * @unregister_work: worker to destroy the cache
  */
 struct memcg_cache_params {
@@ -541,6 +542,7 @@ struct memcg_cache_params {
                        struct list_head list;
                        struct kmem_cache *root_cache;
                        atomic_long_t refcnt;
+                       bool dead;
                        struct work_struct unregister_work;
                };
        };
index 4409688cd2f6042997b9f3e2ce61b20820030e76..2a36a3977e58d1b53e4341d54fb34dc371fecec7 100644 (file)
@@ -3256,7 +3256,10 @@ static void memcg_unregister_all_caches(struct mem_cgroup *memcg)
        mutex_lock(&memcg_slab_mutex);
        list_for_each_entry_safe(params, tmp, &memcg->memcg_slab_caches, list) {
                cachep = memcg_params_to_cache(params);
+
+               memcg_cache_mark_dead(cachep);
                kmem_cache_shrink(cachep);
+
                if (atomic_long_dec_and_test(&cachep->memcg_params->refcnt))
                        memcg_unregister_cache(cachep);
        }
index 3822b65edcc2e43bf218fc6fe5af44739711e93c..4789ca4b872177a51987bc0298d0057773a26c54 100644 (file)
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -121,6 +121,26 @@ static inline bool is_root_cache(struct kmem_cache *s)
        return !s->memcg_params || s->memcg_params->is_root_cache;
 }
 
+static inline bool memcg_cache_dead(struct kmem_cache *s)
+{
+       if (is_root_cache(s))
+               return false;
+
+       /*
+        * Since this function can be called without holding any locks, it
+        * needs a barrier here to guarantee the read won't be reordered.
+        */
+       smp_rmb();
+       return s->memcg_params->dead;
+}
+
+static inline void memcg_cache_mark_dead(struct kmem_cache *s)
+{
+       BUG_ON(is_root_cache(s));
+       s->memcg_params->dead = true;
+       smp_wmb();              /* matches rmb in memcg_cache_dead() */
+}
+
 static inline bool slab_equal_or_root(struct kmem_cache *s,
                                        struct kmem_cache *p)
 {
@@ -203,6 +223,11 @@ static inline bool is_root_cache(struct kmem_cache *s)
        return true;
 }
 
+static inline bool memcg_cache_dead(struct kmem_cache *s)
+{
+       return false;
+}
+
 static inline bool slab_equal_or_root(struct kmem_cache *s,
                                      struct kmem_cache *p)
 {