Skip to content

Commit 969d63e

Browse files
hnazakpm00
authored andcommitted
mm: zswap: fix pool refcount bug around shrink_worker()
When a zswap store fails due to the limit, it acquires a pool reference and queues the shrinker. When the shrinker runs, it drops the reference. However, there can be multiple store attempts before the shrinker wakes up and runs once. This results in reference leaks and eventual saturation warnings for the pool refcount. Fix this by dropping the reference again when the shrinker is already queued. This ensures one reference per shrinker run. Link: https://lkml.kernel.org/r/[email protected] Fixes: 45190f0 ("mm/zswap.c: add allocation hysteresis if pool limit is hit") Signed-off-by: Johannes Weiner <[email protected]> Reported-by: Chris Mason <[email protected]> Acked-by: Nhat Pham <[email protected]> Cc: Vitaly Wool <[email protected]> Cc: Domenico Cerasuolo <[email protected]> Cc: <[email protected]> [5.6+] Signed-off-by: Andrew Morton <[email protected]>
1 parent 229e225 commit 969d63e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mm/zswap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,8 @@ bool zswap_store(struct folio *folio)
13831383

13841384
shrink:
13851385
pool = zswap_pool_last_get();
1386-
if (pool)
1387-
queue_work(shrink_wq, &pool->shrink_work);
1386+
if (pool && !queue_work(shrink_wq, &pool->shrink_work))
1387+
zswap_pool_put(pool);
13881388
goto reject;
13891389
}
13901390

0 commit comments

Comments
 (0)