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
155155 void kmem_cache_destroy(struct kmem_cache *);
156156 int kmem_cache_shrink(struct kmem_cache *);
157157
158−void memcg_create_kmem_cache(struct kmem_cache *cachep);
159−
160158 /*
161159 * Please use this macro to create slab caches. Simply specify the
162160 * 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
7272 int obj_offset;
7373 #endif /* CONFIG_DEBUG_SLAB */
7474
75−#ifdef CONFIG_MEMCG
76− struct memcg_cache_params memcg_params;
77−#endif
7875 #ifdef CONFIG_KASAN
7976 struct kasan_cache kasan_info;
8077 #endif
include/linux/slub_def.h+0−10
@@ -108,17 +108,7 @@ struct kmem_cache { · 107 unmodified lines
108108 struct list_head list; /* List of slab caches */
109109 #ifdef CONFIG_SYSFS
110110 struct kobject kobj; /* For sysfs */
111− struct work_struct kobj_remove_work;
112111 #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−
122112 #ifdef CONFIG_SLAB_FREELIST_HARDENED
123113 unsigned long random;
124114 #endif