path: root/mm
diff options
authorWeijie Yang <>2013-10-16 20:46:54 (GMT)
committerChanho Park <>2014-11-18 02:47:20 (GMT)
commit200e32eaec5f4407ea07a594d4ea0c2f4fe2efdc (patch)
treeab9903ba16e96f87eb78ab324f45a452981fe9a8 /mm
parentb0fb92919f3ac9070b158f0b5c2007e9a206fc78 (diff)
mm/zswap: bugfix: memory leak when re-swapon
zswap_tree is not freed when swapoff, and it got re-kmalloced in swapon, so a memory leak occurs. Free the memory of zswap_tree in zswap_frontswap_invalidate_area(). Signed-off-by: Weijie Yang <> Reviewed-by: Bob Liu <> Cc: Minchan Kim <> Reviewed-by: Minchan Kim <> Cc: <> From: Weijie Yang <> Subject: mm/zswap: bugfix: memory leak when invalidate and reclaim occur concurrently Consider the following scenario: thread 0: reclaim entry x (get refcount, but not call zswap_get_swap_cache_page) thread 1: call zswap_frontswap_invalidate_page to invalidate entry x. finished, entry x and its zbud is not freed as its refcount != 0 now, the swap_map[x] = 0 thread 0: now call zswap_get_swap_cache_page swapcache_prepare return -ENOENT because entry x is not used any more zswap_get_swap_cache_page return ZSWAP_SWAPCACHE_NOMEM zswap_writeback_entry do nothing except put refcount Now, the memory of zswap_entry x and its zpage leak. Modify: - check the refcount in fail path, free memory if it is not referenced. - use ZSWAP_SWAPCACHE_FAIL instead of ZSWAP_SWAPCACHE_NOMEM as the fail path can be not only caused by nomem but also by invalidate. [ coding-style fixes] Signed-off-by: Weijie Yang <> Reviewed-by: Bob Liu <> Cc: Minchan Kim <> Cc: <> Acked-by: Seth Jennings <> Change-Id: I4a875e48714d73bf2c1f75b60d90776365c047de Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'mm')
1 files changed, 4 insertions, 0 deletions
diff --git a/mm/zswap.c b/mm/zswap.c
index 841e35f..d93510c 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -804,6 +804,10 @@ static void zswap_frontswap_invalidate_area(unsigned type)
tree->rbroot = RB_ROOT;
+ zbud_destroy_pool(tree->pool);
+ kfree(tree);
+ zswap_trees[type] = NULL;
static struct zbud_ops zswap_zbud_ops = {