* [PATCH] mm: zswap: fix pool refcount bug around shrink_worker()
@ 2023-10-06 16:00 Johannes Weiner
2023-10-06 21:40 ` Nhat Pham
0 siblings, 1 reply; 2+ messages in thread
From: Johannes Weiner @ 2023-10-06 16:00 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-mm, linux-kernel, Chris Mason, stable, Vitaly Wool,
Domenico Cerasuolo, Nhat Pham
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@fb.com>
Fixes: 45190f01dd40 ("mm/zswap.c: add allocation hysteresis if pool limit is hit")
Cc: stable@vger.kernel.org [5.6+]
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Signed-off-by: Johannes Weiner <hannes@cmpxchg.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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: zswap: fix pool refcount bug around shrink_worker()
2023-10-06 16:00 [PATCH] mm: zswap: fix pool refcount bug around shrink_worker() Johannes Weiner
@ 2023-10-06 21:40 ` Nhat Pham
0 siblings, 0 replies; 2+ messages in thread
From: Nhat Pham @ 2023-10-06 21:40 UTC (permalink / raw)
To: Johannes Weiner
Cc: Andrew Morton, linux-mm, linux-kernel, Chris Mason, stable,
Vitaly Wool, Domenico Cerasuolo
On Fri, Oct 6, 2023 at 9:00 AM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> 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@fb.com>
> Fixes: 45190f01dd40 ("mm/zswap.c: add allocation hysteresis if pool limit is hit")
> Cc: stable@vger.kernel.org [5.6+]
> Cc: Vitaly Wool <vitaly.wool@konsulko.com>
> Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
> Cc: Nhat Pham <nphamcs@gmail.com>
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.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
>
Acked-by: Nhat Pham <nphamcs@gmail.com>
Random tangent: this asynchronous writeback mechanism
is always kinda weird to me. We could have quite a bit of memory
inversion before the shrinker finally kicks in and frees up zswap
pool space. But I guess if it doesn't break then don't fix it.
Maybe a shrinker that proactively writes pages back as memory
pressure builds up could help ;)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-06 21:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 16:00 [PATCH] mm: zswap: fix pool refcount bug around shrink_worker() Johannes Weiner
2023-10-06 21:40 ` Nhat Pham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox