[Devel] [PATCH rh7] mm/slab: Fix deadlock on attempt to shrink slab.

Andrey Ryabinin aryabinin at virtuozzo.com
Thu Oct 10 11:21:14 MSK 2019


echo 1 > /sys/kernel/slab/<name>/shrink deadlocks as kmem_cache_shrink()
attempts to lock slab_mutex which is already held by caller.

Replace slab_mutex locking with [get,put]_online_mems(). This is what
the sane kernel does.

Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/slab_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/slab_common.c b/mm/slab_common.c
index b08f48541f4a..b73b7547de36 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -600,10 +600,10 @@ int kmem_cache_shrink(struct kmem_cache *cachep)
 	int ret;
 
 	get_online_cpus();
-	mutex_lock(&slab_mutex);
+	get_online_mems();
 	kasan_cache_shrink(cachep);
 	ret = __kmem_cache_shrink(cachep, false);
-	mutex_unlock(&slab_mutex);
+	put_online_mems();
 	put_online_cpus();
 	return ret;
 }
-- 
2.21.0



More information about the Devel mailing list