Commit 9a41707b authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Linus Torvalds

slub: rework sysfs layout for memcg caches

Currently, we try to arrange sysfs entries for memcg caches in the same
manner as for global caches.  Apart from turning /sys/kernel/slab into a
mess when there are a lot of kmem-active memcgs created, it actually
does not work properly - we won't create more than one link to a memcg
cache in case its parent is merged with another cache.  For instance, if
A is a root cache merged with another root cache B, we will have the
following sysfs setup:

  X
  A -> X
  B -> X

where X is some unique id (see create_unique_id()).  Now if memcgs M and
N start to allocate from cache A (or B, which is the same), we will get:

  X
  X:M
  X:N
  A -> X
  B -> X
  A:M -> X:M
  A:N -> X:N

Since B is an alias for A, we won't get entries B:M and B:N, which is
confusing.

It is more logical to have entries for memcg caches under the
corresponding root cache's sysfs directory.  This would allow us to keep
sysfs layout clean, and avoid such inconsistencies like one described
above.

This patch does the trick.  It creates a "cgroup" kset in each root
cache kobject to keep its children caches there.
Signed-off-by: default avatarVladimir Davydov <vdavydov@parallels.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Glauber Costa <glommer@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 84d0ddd6
...@@ -87,6 +87,9 @@ struct kmem_cache { ...@@ -87,6 +87,9 @@ struct kmem_cache {
#ifdef CONFIG_MEMCG_KMEM #ifdef CONFIG_MEMCG_KMEM
struct memcg_cache_params *memcg_params; struct memcg_cache_params *memcg_params;
int max_attr_size; /* for propagation, maximum size of a stored attr */ int max_attr_size; /* for propagation, maximum size of a stored attr */
#ifdef CONFIG_SYSFS
struct kset *memcg_kset;
#endif
#endif #endif
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
......
...@@ -5138,6 +5138,15 @@ static const struct kset_uevent_ops slab_uevent_ops = { ...@@ -5138,6 +5138,15 @@ static const struct kset_uevent_ops slab_uevent_ops = {
static struct kset *slab_kset; static struct kset *slab_kset;
static inline struct kset *cache_kset(struct kmem_cache *s)
{
#ifdef CONFIG_MEMCG_KMEM
if (!is_root_cache(s))
return s->memcg_params->root_cache->memcg_kset;
#endif
return slab_kset;
}
#define ID_STR_LENGTH 64 #define ID_STR_LENGTH 64
/* Create a unique string id for a slab cache: /* Create a unique string id for a slab cache:
...@@ -5203,7 +5212,7 @@ static int sysfs_slab_add(struct kmem_cache *s) ...@@ -5203,7 +5212,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
name = create_unique_id(s); name = create_unique_id(s);
} }
s->kobj.kset = slab_kset; s->kobj.kset = cache_kset(s);
err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name); err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
if (err) { if (err) {
kobject_put(&s->kobj); kobject_put(&s->kobj);
...@@ -5216,6 +5225,18 @@ static int sysfs_slab_add(struct kmem_cache *s) ...@@ -5216,6 +5225,18 @@ static int sysfs_slab_add(struct kmem_cache *s)
kobject_put(&s->kobj); kobject_put(&s->kobj);
return err; return err;
} }
#ifdef CONFIG_MEMCG_KMEM
if (is_root_cache(s)) {
s->memcg_kset = kset_create_and_add("cgroup", NULL, &s->kobj);
if (!s->memcg_kset) {
kobject_del(&s->kobj);
kobject_put(&s->kobj);
return -ENOMEM;
}
}
#endif
kobject_uevent(&s->kobj, KOBJ_ADD); kobject_uevent(&s->kobj, KOBJ_ADD);
if (!unmergeable) { if (!unmergeable) {
/* Setup first alias */ /* Setup first alias */
...@@ -5234,6 +5255,9 @@ static void sysfs_slab_remove(struct kmem_cache *s) ...@@ -5234,6 +5255,9 @@ static void sysfs_slab_remove(struct kmem_cache *s)
*/ */
return; return;
#ifdef CONFIG_MEMCG_KMEM
kset_unregister(s->memcg_kset);
#endif
kobject_uevent(&s->kobj, KOBJ_REMOVE); kobject_uevent(&s->kobj, KOBJ_REMOVE);
kobject_del(&s->kobj); kobject_del(&s->kobj);
kobject_put(&s->kobj); kobject_put(&s->kobj);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment