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
Showing the changes to include/linux (3 of 8 files). Show all
Unified · Split
| @@ -155,8 +155,6 @@ struct kmem_cache *kmem_cache_create_usercopy(const char *name, · 154 unmodified lines | |||
| 155 | void kmem_cache_destroy(struct kmem_cache *); | 155 | void kmem_cache_destroy(struct kmem_cache *); |
| 156 | int kmem_cache_shrink(struct kmem_cache *); | 156 | int kmem_cache_shrink(struct kmem_cache *); |
| 157 | 157 | ||
| 158 | void memcg_create_kmem_cache(struct kmem_cache *cachep); | ||
| 159 | |||
| 160 | /* | 158 | /* |
| 161 | * Please use this macro to create slab caches. Simply specify the | 159 | * 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. |
| @@ -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_KASAN | 75 | #ifdef CONFIG_KASAN |
| 79 | struct kasan_cache kasan_info; | 76 | struct kasan_cache kasan_info; |
| 80 | #endif | 77 | #endif |
| @@ -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_SYSFS | 109 | #ifdef CONFIG_SYSFS |
| 110 | struct kobject kobj; /* For sysfs */ | 110 | struct kobject kobj; /* For sysfs */ |
| 111 | struct work_struct kobj_remove_work; | ||
| 112 | #endif | 111 | #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_HARDENED | 112 | #ifdef CONFIG_SLAB_FREELIST_HARDENED |
| 123 | unsigned long random; | 113 | unsigned long random; |
| 124 | #endif | 114 | #endif |