History

mm: memcg/slab: use a single set of kmem_caches for all allocations

Instead of having two sets of kmem_caches: one for system-wide and non-accounted allocations and the second one shared by all accounted allocations, we can use just one. The idea is simple: space for obj_cgroup metadata can be allocated on demand and filled only for accounted allocations. It allows to remove a bunch of code which is required to handle kmem_cache clones for accounted allocations. There is no more need to create them, accumulate statistics, propagate attributes, etc. It's a quite significant simplification. Also, because the total number of slab_caches is reduced almost twice (not all kmem_caches have a memcg clone), some additional memory savings are expected. On my devvm it additionally saves about 3.5% of slab memory. [guro@fb.com: fix build on MIPS] Link: http://lkml.kernel.org/r/20200717214810.3733082-1-guro@fb.com

Roman Gushchin committed 6 years ago

Commit 10befea1 parent 15999ee8 files · +78 −590Browse files

Showing the changes to include/linux (3 of 8 files). Show all

Unified · Split

3 files
  1. include/linux/slab.h +0 −2
  2. include/linux/slab_def.h +0 −3
  3. include/linux/slub_def.h +0 −10
include/linux/slab.h+0−2
@@ -155,8 +155,6 @@ struct kmem_cache *kmem_cache_create_usercopy(const char *name, · 154 unmodified lines
155void kmem_cache_destroy(struct kmem_cache *);155void kmem_cache_destroy(struct kmem_cache *);
156int kmem_cache_shrink(struct kmem_cache *);156int kmem_cache_shrink(struct kmem_cache *);
157 157
158void memcg_create_kmem_cache(struct kmem_cache *cachep);
159
160/*158/*
161 * Please use this macro to create slab caches. Simply specify the159 * Please use this macro to create slab caches. Simply specify the
162 * name of the structure and maybe some flags that are listed above.160 * name of the structure and maybe some flags that are listed above.
include/linux/slab_def.h+0−3
@@ -72,9 +72,6 @@ struct kmem_cache { · 71 unmodified lines
72 int obj_offset;72 int obj_offset;
73#endif /* CONFIG_DEBUG_SLAB */73#endif /* CONFIG_DEBUG_SLAB */
74 74
75#ifdef CONFIG_MEMCG
76 struct memcg_cache_params memcg_params;
77#endif
78#ifdef CONFIG_KASAN75#ifdef CONFIG_KASAN
79 struct kasan_cache kasan_info;76 struct kasan_cache kasan_info;
80#endif77#endif
include/linux/slub_def.h+0−10
@@ -108,17 +108,7 @@ struct kmem_cache { · 107 unmodified lines
108 struct list_head list; /* List of slab caches */108 struct list_head list; /* List of slab caches */
109#ifdef CONFIG_SYSFS109#ifdef CONFIG_SYSFS
110 struct kobject kobj; /* For sysfs */110 struct kobject kobj; /* For sysfs */
111 struct work_struct kobj_remove_work;
112#endif111#endif
113#ifdef CONFIG_MEMCG
114 struct memcg_cache_params memcg_params;
115 /* For propagation, maximum size of a stored attr */
116 unsigned int max_attr_size;
117#ifdef CONFIG_SYSFS
118 struct kset *memcg_kset;
119#endif
120#endif
121
122#ifdef CONFIG_SLAB_FREELIST_HARDENED112#ifdef CONFIG_SLAB_FREELIST_HARDENED
123 unsigned long random;113 unsigned long random;
124#endif114#endif