RE: [PATCH v8 12/14] mm: zswap: Simplify acomp_ctx resource allocation/deletion and mutex lock usage.

Sridhar, Kanchana P
2025-03-18T23:37:38Z

> -----Original Message-----
> From: Yosry Ahmed <yosry.ahmed@linux.dev>
> Sent: Tuesday, March 18, 2025 4:14 PM
> To: Sridhar, Kanchana P <kanchana.p.sridhar@intel.com>
> Cc: linux-kernel@vger.kernel.org; linux-mm@kvack.org;
> hannes@cmpxchg.org; nphamcs@gmail.com; chengming.zhou@linux.dev;
> usamaarif642@gmail.com; ryan.roberts@arm.com; 21cnbao@gmail.com;
> ying.huang@linux.alibaba.com; akpm@linux-foundation.org; linux-
> crypto@vger.kernel.org; herbert@gondor.apana.org.au;
> davem@davemloft.net; clabbe@baylibre.com; ardb@kernel.org;
> ebiggers@google.com; surenb@google.com; Accardi, Kristen C
> <kristen.c.accardi@intel.com>; Feghali, Wajdi K <wajdi.k.feghali@intel.com>;
> Gopal, Vinodh <vinodh.gopal@intel.com>
> Subject: Re: [PATCH v8 12/14] mm: zswap: Simplify acomp_ctx resource
> allocation/deletion and mutex lock usage.
>
> On Tue, Mar 18, 2025 at 09:09:05PM +0000, Sridhar, Kanchana P wrote:
> [..]
> > > > > >
> > > > > > The only other fallback solution in lieu of the proposed
> simplification
> > > that
> > > > > > I can think of is to keep the lifespan of these resources from pool
> > > creation
> > > > > > to deletion, using the CPU hotplug code. Although, it is not totally
> > > clear
> > > > > > to me if there is potential for deadlock during pool transitions, as
> > > noted
> > > > > above.
> > > > >
> > > > > I am not sure what's the deadlock scenario you're worried about,
> please
> > > > > clarify.
> > > >
> > > > My apologies: I was referring to triggering direct reclaim during pool
> > > creation,
> > > > which could, in theory, run into a scenario where the pool switching
> would
> > > > have to wait for reclaim to free up enough memory for the acomp_ctx
> > > > resources allocation: this could cause the system to hang, but not a
> > > deadlock.
> > > > This can happen even today, hence trying to see if a better design is
> > > possible.
> > >
> > > I think the concern here is unfounded. We shouldn't care about the
> > > performance of zswap compressor switching, especially under memory
> > > pressure. A lot of things will slow down under memory pressure, and
> > > compressor switching should be the least of our concerns.
> >
> > Sounds good. It then appears that making the per-cpu acomp_ctx resources'
> > lifetime track that of the zswap_pool, is the way to go. These resources
> > will be allocated as per the requirements of the compressor, i.e.,
> zswap_pool,
> > and will persist through CPU online/offline transitions through the hotplug
> > interface. If this plan is acceptable, it appears that
> acomp_ctx_get_cpu_lock()
> > and acomp_ctx_put_unlock() can be replaced with mutex_lock()/unlock() in
> > zswap_[de]compress()? I will incorporate these changes in v9 if this sounds
> Ok.
>
> Sounds good to me. Thanks!

Thanks Yosry! Will proceed accordingly.

Thanks,
Kanchana