From: Johannes Weiner Date: Fri, 6 Oct 2023 16:00:24 +0000 (-0400) Subject: mm: zswap: fix pool refcount bug around shrink_worker() X-Git-Tag: v6.6.17~3694^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=969d63e1af3b3abe35a49b08218f3125131ac32f;p=platform%2Fkernel%2Flinux-rpi.git 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/20231006160024.170748-1-hannes@cmpxchg.org Fixes: 45190f01dd40 ("mm/zswap.c: add allocation hysteresis if pool limit is hit") Signed-off-by: Johannes Weiner Reported-by: Chris Mason Acked-by: Nhat Pham Cc: Vitaly Wool Cc: Domenico Cerasuolo Cc: [5.6+] Signed-off-by: Andrew Morton --- diff --git a/mm/zswap.c b/mm/zswap.c index 083c693..37d2b1c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1383,8 +1383,8 @@ reject: shrink: pool = zswap_pool_last_get(); - if (pool) - queue_work(shrink_wq, &pool->shrink_work); + if (pool && !queue_work(shrink_wq, &pool->shrink_work)) + zswap_pool_put(pool); goto reject; }