[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231006160024.170748-1-hannes@cmpxchg.org>
Date: Fri, 6 Oct 2023 12:00:24 -0400
From: Johannes Weiner <hannes@...xchg.org>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org,
Chris Mason <clm@...com>, stable@...r.kernel.org,
Vitaly Wool <vitaly.wool@...sulko.com>,
Domenico Cerasuolo <cerasuolodomenico@...il.com>,
Nhat Pham <nphamcs@...il.com>
Subject: [PATCH] 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.
Reported-by: Chris Mason <clm@...com>
Fixes: 45190f01dd40 ("mm/zswap.c: add allocation hysteresis if pool limit is hit")
Cc: stable@...r.kernel.org [5.6+]
Cc: Vitaly Wool <vitaly.wool@...sulko.com>
Cc: Domenico Cerasuolo <cerasuolodomenico@...il.com>
Cc: Nhat Pham <nphamcs@...il.com>
Signed-off-by: Johannes Weiner <hannes@...xchg.org>
---
mm/zswap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/zswap.c b/mm/zswap.c
index 083c693602b8..37d2b1cb2ecb 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1383,8 +1383,8 @@ bool zswap_store(struct folio *folio)
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;
}
--
2.42.0
Powered by blists - more mailing lists