Re: [PATCH] mm: zswap: limit number of zpools based on CPU and RAM

From: Nhat Pham
Date: Fri Jun 07 2024 - 05:26:25 EST


On Thu, Jun 6, 2024 at 5:53 PM Takero Funaki <flintglass@xxxxxxxxx> wrote:
>
> This patch limits the number of zpools used by zswap on smaller systems.
>
> Currently, zswap allocates 32 pools unconditionally. This was
> implemented to reduce contention on per-zpool locks. However, it incurs
> allocation overhead by distributing pages across pools, wasting memory
> on systems with fewer CPUs and less RAM.
>
> This patch allocates approximately 2*CPU zpools, with a minimum of 1
> zpool for single-CPU systems and up to 32 zpools for systems with 16 or
> more CPUs. This number is sufficient to keep the probability of
> busy-waiting by a thread under 40%. The upper limit of 32 zpools remains
> unchanged.
>
> For memory, it limits to 1 zpool per 60MB of memory for the 20% default
> max pool size limit, assuming the best case with no fragmentation in
> zspages. It expects 90% pool usage for zsmalloc.
>
> Signed-off-by: Takero Funaki <flintglass@xxxxxxxxx>
> ---

I think this needs benchmarking. Theoretical justification is nice,
but I'm not convinced it'll translate neatly to the messy world of
real life systems.