The patch titled Subject: slub: make sysfs directories for memcg sub-caches optional has been added to the -mm tree. Its filename is slub-make-sysfs-directories-for-memcg-sub-caches-optional.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/slub-make-sysfs-directories-for-memcg-sub-caches-optional.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/slub-make-sysfs-directories-for-memcg-sub-caches-optional.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Tejun Heo <tj@xxxxxxxxxx> Subject: slub: make sysfs directories for memcg sub-caches optional SLUB creates a per-cache directory under /sys/kernel/slab which hosts a bunch of debug files. Usually, there aren't that many caches on a system and this doesn't really matter; however, if memcg is in use, each cache can have per-cgroup sub-caches. SLUB creates the same directories for these sub-caches under /sys/kernel/slab/$CACHE/cgroup. Unfortunately, because there can be a lot of cgroups, active or draining, the product of the numbers of caches, cgroups and files in each directory can reach a very high number - hundreds of thousands is commonplace. Millions and beyond aren't difficult to reach either. What's under /sys/kernel/slab is primarily for debugging and the information and control on the a root cache already cover its sub-caches. While having a separate directory for each sub-cache can be helpful for development, it doesn't make much sense to pay this amount of overhead by default. This patch introduces a boot parameter slub_memcg_sysfs which determines whether to create sysfs directories for per-memcg sub-caches. It also adds CONFIG_SLUB_MEMCG_SYSFS_ON which determines the boot parameter's default value and defaults to 0. Link: http://lkml.kernel.org/r/20170204145203.GB26958@xxxxxxxxxxxxxxx Signed-off-by: Tejun Heo <tj@xxxxxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: Pekka Enberg <penberg@xxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx> Cc: Vladimir Davydov <vdavydov.dev@xxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- Documentation/admin-guide/kernel-parameters.txt | 8 +++ init/Kconfig | 14 ++++++ mm/slub.c | 29 ++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-) diff -puN Documentation/admin-guide/kernel-parameters.txt~slub-make-sysfs-directories-for-memcg-sub-caches-optional Documentation/admin-guide/kernel-parameters.txt --- a/Documentation/admin-guide/kernel-parameters.txt~slub-make-sysfs-directories-for-memcg-sub-caches-optional +++ a/Documentation/admin-guide/kernel-parameters.txt @@ -3679,6 +3679,14 @@ last alloc / free. For more information see Documentation/vm/slub.txt. + slub_memcg_sysfs= [MM, SLUB] + Determines whether to enable sysfs directories for + memory cgroup sub-caches. 1 to enable, 0 to disable. + The default is determined by CONFIG_SLUB_MEMCG_SYSFS_ON. + Enabling this can lead to a very high number of debug + directories and files being created under + /sys/kernel/slub. + slub_max_order= [MM, SLUB] Determines the maximum allowed order for slabs. A high setting may cause OOMs due to memory diff -puN init/Kconfig~slub-make-sysfs-directories-for-memcg-sub-caches-optional init/Kconfig --- a/init/Kconfig~slub-make-sysfs-directories-for-memcg-sub-caches-optional +++ a/init/Kconfig @@ -1786,6 +1786,20 @@ config SLUB_DEBUG SLUB sysfs support. /sys/slab will not exist and there will be no support for cache validation etc. +config SLUB_MEMCG_SYSFS_ON + default n + bool "Enable memcg SLUB sysfs support by default" if EXPERT + depends on SLUB && SYSFS && MEMCG + help + SLUB creates a directory under /sys/kernel/slab for each + allocation cache to host info and debug files. If memory + cgroup is enabled, each cache can have per memory cgroup + caches. SLUB can create the same sysfs directories for these + caches under /sys/kernel/slab/CACHE/cgroup but it can lead + to a very high number of debug files being created. This is + controlled by slub_memcg_sysfs boot parameter and this + config option determines the parameter's default value. + config COMPAT_BRK bool "Disable heap randomization" default y diff -puN mm/slub.c~slub-make-sysfs-directories-for-memcg-sub-caches-optional mm/slub.c --- a/mm/slub.c~slub-make-sysfs-directories-for-memcg-sub-caches-optional +++ a/mm/slub.c @@ -4704,6 +4704,22 @@ enum slab_stat_type { #define SO_OBJECTS (1 << SL_OBJECTS) #define SO_TOTAL (1 << SL_TOTAL) +#ifdef CONFIG_MEMCG +static bool memcg_sysfs_enabled = IS_ENABLED(CONFIG_SLUB_MEMCG_SYSFS_ON); + +static int __init setup_slub_memcg_sysfs(char *str) +{ + int v; + + if (get_option(&str, &v) > 0) + memcg_sysfs_enabled = v; + + return 1; +} + +__setup("slub_memcg_sysfs=", setup_slub_memcg_sysfs); +#endif + static ssize_t show_slab_objects(struct kmem_cache *s, char *buf, unsigned long flags) { @@ -5607,8 +5623,14 @@ static int sysfs_slab_add(struct kmem_ca { int err; const char *name; + struct kset *kset = cache_kset(s); int unmergeable = slab_unmergeable(s); + if (!kset) { + kobject_init(&s->kobj, &slab_ktype); + return 0; + } + if (unmergeable) { /* * Slabcache can never be merged so we can use the name proper. @@ -5625,7 +5647,7 @@ static int sysfs_slab_add(struct kmem_ca name = create_unique_id(s); } - s->kobj.kset = cache_kset(s); + s->kobj.kset = kset; err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name); if (err) goto out; @@ -5635,7 +5657,7 @@ static int sysfs_slab_add(struct kmem_ca goto out_del_kobj; #ifdef CONFIG_MEMCG - if (is_root_cache(s)) { + if (is_root_cache(s) && memcg_sysfs_enabled) { s->memcg_kset = kset_create_and_add("cgroup", NULL, &s->kobj); if (!s->memcg_kset) { err = -ENOMEM; @@ -5677,7 +5699,8 @@ static void sysfs_slab_remove(struct kme return; #ifdef CONFIG_MEMCG - kset_unregister(s->memcg_kset); + if (s->memcg_kset) + kset_unregister(s->memcg_kset); #endif kobject_uevent(&s->kobj, KOBJ_REMOVE); kobject_del(&s->kobj); _ Patches currently in -mm which might be from tj@xxxxxxxxxx are cpumask-use-nr_cpumask_bits-for-parsing-functions.patch revert-slub-move-synchronize_sched-out-of-slab_mutex-on-shrink.patch slub-separate-out-sysfs_slab_release-from-sysfs_slab_remove.patch slab-remove-synchronous-rcu_barrier-call-in-memcg-cache-release-path.patch slab-reorganize-memcg_cache_params.patch slab-link-memcg-kmem_caches-on-their-associated-memory-cgroup.patch slab-implement-slab_root_caches-list.patch slab-introduce-__kmemcg_cache_deactivate.patch slab-remove-synchronous-synchronize_sched-from-memcg-cache-deactivation-path.patch slab-remove-slub-sysfs-interface-files-early-for-empty-memcg-caches.patch slab-use-memcg_kmem_cache_wq-for-slab-destruction-operations.patch slub-make-sysfs-directories-for-memcg-sub-caches-optional.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html