History

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. [akpm@linux-foundation.org: kset_unregister(NULL) is legal] Link: http://lkml.kernel.org/r/20170204145203.GB26958@mtj.duckdns.org Signed-off-by: Tejun Heo <tj@kernel.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> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Tejun Heo committed 9 years ago

Commit 1663f261 parent 17cc4df3 files · +46 −2Browse files

Unified · Split

3 files
  1. Documentation/admin-guide/kernel-parameters.txt +8 −0
  2. init/Kconfig +14 −0
  3. mm/slub.c +24 −2
Documentation/admin-guide/kernel-parameters.txt+8−0
@@ -3694,6 +3694,14 @@ · 3693 unmodified lines
3694 last alloc / free. For more information see3694 last alloc / free. For more information see
3695 Documentation/vm/slub.txt.3695 Documentation/vm/slub.txt.
3696 3696
3697 slub_memcg_sysfs= [MM, SLUB]
3698 Determines whether to enable sysfs directories for
3699 memory cgroup sub-caches. 1 to enable, 0 to disable.
3700 The default is determined by CONFIG_SLUB_MEMCG_SYSFS_ON.
3701 Enabling this can lead to a very high number of debug
3702 directories and files being created under
3703 /sys/kernel/slub.
3704
3697 slub_max_order= [MM, SLUB]3705 slub_max_order= [MM, SLUB]
3698 Determines the maximum allowed order for slabs.3706 Determines the maximum allowed order for slabs.
3699 A high setting may cause OOMs due to memory3707 A high setting may cause OOMs due to memory
init/Kconfig+14−0
@@ -1779,6 +1779,20 @@ config SLUB_DEBUG · 1778 unmodified lines
1779 SLUB sysfs support. /sys/slab will not exist and there will be1779 SLUB sysfs support. /sys/slab will not exist and there will be
1780 no support for cache validation etc.1780 no support for cache validation etc.
1781 1781
1782config SLUB_MEMCG_SYSFS_ON
1783 default n
1784 bool "Enable memcg SLUB sysfs support by default" if EXPERT
1785 depends on SLUB && SYSFS && MEMCG
1786 help
1787 SLUB creates a directory under /sys/kernel/slab for each
1788 allocation cache to host info and debug files. If memory
1789 cgroup is enabled, each cache can have per memory cgroup
1790 caches. SLUB can create the same sysfs directories for these
1791 caches under /sys/kernel/slab/CACHE/cgroup but it can lead
1792 to a very high number of debug files being created. This is
1793 controlled by slub_memcg_sysfs boot parameter and this
1794 config option determines the parameter's default value.
1795
1782config COMPAT_BRK1796config COMPAT_BRK
1783 bool "Disable heap randomization"1797 bool "Disable heap randomization"
1784 default y1798 default y
mm/slub.c+24−2
@@ -4708,6 +4708,22 @@ enum slab_stat_type { · 4707 unmodified lines
4708#define SO_OBJECTS (1 << SL_OBJECTS)4708#define SO_OBJECTS (1 << SL_OBJECTS)
4709#define SO_TOTAL (1 << SL_TOTAL)4709#define SO_TOTAL (1 << SL_TOTAL)
4710 4710
4711#ifdef CONFIG_MEMCG
4712static bool memcg_sysfs_enabled = IS_ENABLED(CONFIG_SLUB_MEMCG_SYSFS_ON);
4713
4714static int __init setup_slub_memcg_sysfs(char *str)
4715{
4716 int v;
4717
4718 if (get_option(&str, &v) > 0)
4719 memcg_sysfs_enabled = v;
4720
4721 return 1;
4722}
4723
4724__setup("slub_memcg_sysfs=", setup_slub_memcg_sysfs);
4725#endif
4726
4711static ssize_t show_slab_objects(struct kmem_cache *s,4727static ssize_t show_slab_objects(struct kmem_cache *s,
4712 char *buf, unsigned long flags)4728 char *buf, unsigned long flags)
4713{4729{
@@ -5611,8 +5627,14 @@ static int sysfs_slab_add(struct kmem_cache *s) · 897 unmodified lines
5611{5627{
5612 int err;5628 int err;
5613 const char *name;5629 const char *name;
5630 struct kset *kset = cache_kset(s);
5614 int unmergeable = slab_unmergeable(s);5631 int unmergeable = slab_unmergeable(s);
5615 5632
5633 if (!kset) {
5634 kobject_init(&s->kobj, &slab_ktype);
5635 return 0;
5636 }
5637
5616 if (unmergeable) {5638 if (unmergeable) {
5617 /*5639 /*
5618 * Slabcache can never be merged so we can use the name proper.5640 * Slabcache can never be merged so we can use the name proper.
@@ -5629,7 +5651,7 @@ static int sysfs_slab_add(struct kmem_cache *s) · 10 unmodified lines
5629 name = create_unique_id(s);5651 name = create_unique_id(s);
5630 }5652 }
5631 5653
5632 s->kobj.kset = cache_kset(s);5654 s->kobj.kset = kset;
5633 err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);5655 err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
5634 if (err)5656 if (err)
5635 goto out;5657 goto out;
@@ -5639,7 +5661,7 @@ static int sysfs_slab_add(struct kmem_cache *s) · 3 unmodified lines
5639 goto out_del_kobj;5661 goto out_del_kobj;
5640 5662
5641#ifdef CONFIG_MEMCG5663#ifdef CONFIG_MEMCG
5642 if (is_root_cache(s)) {5664 if (is_root_cache(s) && memcg_sysfs_enabled) {
5643 s->memcg_kset = kset_create_and_add("cgroup", NULL, &s->kobj);5665 s->memcg_kset = kset_create_and_add("cgroup", NULL, &s->kobj);
5644 if (!s->memcg_kset) {5666 if (!s->memcg_kset) {
5645 err = -ENOMEM;5667 err = -ENOMEM;