summaryrefslogtreecommitdiffstats
path: root/mm/slab_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/slab_common.c')
-rw-r--r--mm/slab_common.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 807490fe217a..6491c3a41805 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -981,6 +981,43 @@ int kmem_cache_shrink(struct kmem_cache *cachep)
981} 981}
982EXPORT_SYMBOL(kmem_cache_shrink); 982EXPORT_SYMBOL(kmem_cache_shrink);
983 983
984/**
985 * kmem_cache_shrink_all - shrink a cache and all memcg caches for root cache
986 * @s: The cache pointer
987 */
988void kmem_cache_shrink_all(struct kmem_cache *s)
989{
990 struct kmem_cache *c;
991
992 if (!IS_ENABLED(CONFIG_MEMCG_KMEM) || !is_root_cache(s)) {
993 kmem_cache_shrink(s);
994 return;
995 }
996
997 get_online_cpus();
998 get_online_mems();
999 kasan_cache_shrink(s);
1000 __kmem_cache_shrink(s);
1001
1002 /*
1003 * We have to take the slab_mutex to protect from the memcg list
1004 * modification.
1005 */
1006 mutex_lock(&slab_mutex);
1007 for_each_memcg_cache(c, s) {
1008 /*
1009 * Don't need to shrink deactivated memcg caches.
1010 */
1011 if (s->flags & SLAB_DEACTIVATED)
1012 continue;
1013 kasan_cache_shrink(c);
1014 __kmem_cache_shrink(c);
1015 }
1016 mutex_unlock(&slab_mutex);
1017 put_online_mems();
1018 put_online_cpus();
1019}
1020
984bool slab_is_available(void) 1021bool slab_is_available(void)
985{ 1022{
986 return slab_state >= UP; 1023 return slab_state >= UP;