mm: memcg/slab: use a single set of kmem_caches for all accounted allocations
This is fairly big but mostly red patch, which makes all accounted slab allocations use a single set of kmem_caches instead of creating a separate set for each memory cgroup. Because the number of non-root kmem_caches is now capped by the number of root kmem_caches, there is no need to shrink or destroy them prematurely. They can be perfectly destroyed together with their root counterparts. This allows to dramatically simplify the management of non-root kmem_caches and delete a ton of code. This patch performs the following changes: 1) introduces memcg_params.memcg_cache pointer to represent the kmem_cache which will be used for all non-root allocations 2) reuses the existing memcg kmem_cache creation mechanism to create memcg kmem_cache on the first allocation attempt 3) memcg kmem_caches are named <kmemcache_name>-memcg, e.g. dentry-memcg 4) simplifies memcg_kmem_get_cache() to just return memcg kmem_cache or schedule it's creation and return the root cache 5) removes almost all non-root kmem_cache management code (separate refcounter, reparenting, shrinking, etc) 6) makes slab debugfs to display root_mem_cgroup css id and never show :dead and :deact flags in the memcg_slabinfo attribute. Following patches in the series will simplify the kmem_cache creation. Signed-off-by: Roman Gushchin <guro@fb.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Shakeel Butt <shakeelb@google.com> Cc: Christoph Lameter <cl@linux.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Tejun Heo <tj@kernel.org> Link: http://lkml.kernel.org/r/20200623174037.3951353-13-guro@fb.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Цей коміт міститься в:

зафіксовано
Linus Torvalds

джерело
0f876e4dc5
коміт
9855609bde
38
mm/slub.c
38
mm/slub.c
@@ -4204,36 +4204,6 @@ int __kmem_cache_shrink(struct kmem_cache *s)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MEMCG
|
||||
void __kmemcg_cache_deactivate_after_rcu(struct kmem_cache *s)
|
||||
{
|
||||
/*
|
||||
* Called with all the locks held after a sched RCU grace period.
|
||||
* Even if @s becomes empty after shrinking, we can't know that @s
|
||||
* doesn't have allocations already in-flight and thus can't
|
||||
* destroy @s until the associated memcg is released.
|
||||
*
|
||||
* However, let's remove the sysfs files for empty caches here.
|
||||
* Each cache has a lot of interface files which aren't
|
||||
* particularly useful for empty draining caches; otherwise, we can
|
||||
* easily end up with millions of unnecessary sysfs files on
|
||||
* systems which have a lot of memory and transient cgroups.
|
||||
*/
|
||||
if (!__kmem_cache_shrink(s))
|
||||
sysfs_slab_remove(s);
|
||||
}
|
||||
|
||||
void __kmemcg_cache_deactivate(struct kmem_cache *s)
|
||||
{
|
||||
/*
|
||||
* Disable empty slabs caching. Used to avoid pinning offline
|
||||
* memory cgroups by kmem pages that can be freed.
|
||||
*/
|
||||
slub_set_cpu_partial(s, 0);
|
||||
s->min_partial = 0;
|
||||
}
|
||||
#endif /* CONFIG_MEMCG */
|
||||
|
||||
static int slab_mem_going_offline_callback(void *arg)
|
||||
{
|
||||
struct kmem_cache *s;
|
||||
@@ -4390,7 +4360,7 @@ static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache)
|
||||
}
|
||||
slab_init_memcg_params(s);
|
||||
list_add(&s->list, &slab_caches);
|
||||
memcg_link_cache(s, NULL);
|
||||
memcg_link_cache(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -4458,7 +4428,8 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align,
|
||||
s->object_size = max(s->object_size, size);
|
||||
s->inuse = max(s->inuse, ALIGN(size, sizeof(void *)));
|
||||
|
||||
for_each_memcg_cache(c, s) {
|
||||
c = memcg_cache(s);
|
||||
if (c) {
|
||||
c->object_size = s->object_size;
|
||||
c->inuse = max(c->inuse, ALIGN(size, sizeof(void *)));
|
||||
}
|
||||
@@ -5591,7 +5562,8 @@ static ssize_t slab_attr_store(struct kobject *kobj,
|
||||
* directly either failed or succeeded, in which case we loop
|
||||
* through the descendants with best-effort propagation.
|
||||
*/
|
||||
for_each_memcg_cache(c, s)
|
||||
c = memcg_cache(s);
|
||||
if (c)
|
||||
attribute->store(c, buf, len);
|
||||
mutex_unlock(&slab_mutex);
|
||||
}
|
||||
|
Посилання в новій задачі
Заблокувати користувача