Currently there are two lists of kmem_caches:
1) slab_caches, which contains all kmem_caches,
2) slab_root_caches, which contains only root kmem_caches.
And there is some preprocessor magic to have a single list
if CONFIG_MEMCG_KMEM isn't enabled.
It was required earlier because the number of non-root kmem_caches
was proportional to the number of memory cgroups and could reach
really big values. Now, when it cannot exceed the number of root
kmem_caches, there is really no reason to maintain two lists.
We never iterate over the slab_root_caches list on any hot paths,
so it's perfectly fine to iterate over slab_caches and filter out
non-root kmem_caches.
It allows to remove a lot of config-dependent code and two pointers
from the kmem_cache structure.
Signed-off-by: Roman Gushchin
Reviewed-by: Vlastimil Babka
---
mm/slab.c| 1 -
mm/slab.h| 17 -
mm/slab_common.c | 37 -
mm/slub.c| 1 -
4 files changed, 8 insertions(+), 48 deletions(-)
diff --git a/mm/slab.c b/mm/slab.c
index 7e8d0f62f30b..18a782bacd1b 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1239,7 +1239,6 @@ void __init kmem_cache_init(void)
nr_node_ids * sizeof(struct kmem_cache_node
*),
SLAB_HWCACHE_ALIGN, 0, 0);
list_add(_cache->list, _caches);
- memcg_link_cache(kmem_cache);
slab_state = PARTIAL;
/*
diff --git a/mm/slab.h b/mm/slab.h
index f4033298a776..c49a863adb63 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -44,14 +44,12 @@ struct kmem_cache {
*
* @memcg_cache: pointer to memcg kmem cache, used by all non-root memory
* cgroups.
- * @root_caches_node: list node for slab_root_caches list.
* @work: work struct used to create the non-root cache.
*/
struct memcg_cache_params {
struct kmem_cache *root_cache;
struct kmem_cache *memcg_cache;
- struct list_head __root_caches_node;
struct work_struct work;
};
#endif /* CONFIG_SLOB */
@@ -235,11 +233,6 @@ static inline int cache_vmstat_idx(struct kmem_cache *s)
}
#ifdef CONFIG_MEMCG_KMEM
-
-/* List of all root caches. */
-extern struct list_headslab_root_caches;
-#define root_caches_node memcg_params.__root_caches_node
-
static inline bool is_root_cache(struct kmem_cache *s)
{
return !s->memcg_params.root_cache;
@@ -415,14 +408,8 @@ static inline void memcg_slab_free_hook(struct kmem_cache
*s, struct page *page,
}
extern void slab_init_memcg_params(struct kmem_cache *);
-extern void memcg_link_cache(struct kmem_cache *s);
#else /* CONFIG_MEMCG_KMEM */
-
-/* If !memcg, all caches are root. */
-#define slab_root_caches slab_caches
-#define root_caches_node list
-
static inline bool is_root_cache(struct kmem_cache *s)
{
return true;
@@ -491,10 +478,6 @@ static inline void slab_init_memcg_params(struct
kmem_cache *s)
{
}
-static inline void memcg_link_cache(struct kmem_cache *s)
-{
-}
-
#endif /* CONFIG_MEMCG_KMEM */
static inline struct kmem_cache *virt_to_cache(const void *obj)
diff --git a/mm/slab_common.c b/mm/slab_common.c
index f8874a159637..c045afb9724e 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -129,9 +129,6 @@ int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t
flags, size_t nr,
}
#ifdef CONFIG_MEMCG_KMEM
-
-LIST_HEAD(slab_root_caches);
-
static void memcg_kmem_cache_create_func(struct work_struct *work)
{
struct kmem_cache *cachep = container_of(work, struct kmem_cache,
@@ -154,27 +151,11 @@ static void init_memcg_params(struct kmem_cache *s,
else
slab_init_memcg_params(s);
}
-
-void memcg_link_cache(struct kmem_cache *s)
-{
- if (is_root_cache(s))
- list_add(>root_caches_node, _root_caches);
-}
-
-static void memcg_unlink_cache(struct kmem_cache *s)
-{
- if (is_root_cache(s))
- list_del(>root_caches_node);
-}
#else
static inline void init_memcg_params(struct kmem_cache *s,
struct kmem_cache *root_cache)
{
}
-
-static inline void memcg_unlink_cache(struct kmem_cache *s)
-{
-}
#endif /* CONFIG_MEMCG_KMEM */
/*
@@ -251,7 +232,7 @@ struct kmem_cache *find_mergeable(unsigned int size,
unsigned int align,
if (flags & SLAB_NEVER_MERGE)
return NULL;
- list_for_each_entry_reverse(s, _root_caches, root_caches_node) {
+ list_for_each_entry_reverse(s, _caches, list) {
if (slab_unmergeable(s))
continue;
@@ -310,7 +291,6 @@ static struct kmem_cache *create_cache(const char *name,
s->refcount = 1;
list_add(>list, _caches);
- memcg_link_cache(s);
out:
if (err)
return ERR_PTR(err);
@@ -505,7 +485,6 @@ static int shutdown_cache(struct kmem_cache *s)
if (__kmem_cache_shutdown(s) != 0)
return -EBUSY;
-