From: Yosry Ahmed <yosryahmed@google.com>
To: "Sridhar, Kanchana P" <kanchana.p.sridhar@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Nhat Pham <nphamcs@gmail.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Vitaly Wool <vitalywool@gmail.com>,
Barry Song <baohua@kernel.org>,
Sam Sun <samsun1006219@gmail.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] mm: zswap: disable migration while using per-CPU acomp_ctx
Date: Tue, 7 Jan 2025 17:18:39 -0800 [thread overview]
Message-ID: <CAJD7tkYV_pFGCwpzMD_WiBd+46oVHu946M_ARA8tP79zqkJsDA@mail.gmail.com> (raw)
In-Reply-To: <SJ0PR11MB5678847E829448EF36A3961FC9122@SJ0PR11MB5678.namprd11.prod.outlook.com>
[..]
> > > Couple of possibly related thoughts:
> > >
> > > 1) I have been thinking some more about the purpose of this per-cpu
> > acomp_ctx
> > > mutex. It appears that the main benefit is it causes task blocked errors
> > (which are
> > > useful to detect problems) if any computes in the code section it covers
> > take a
> > > long duration. Other than that, it does not protect a resource, nor
> > prevent
> > > cpu offlining from deleting its containing structure.
> >
> > It does protect resources. Consider this case:
> > - Process A runs on CPU #1, gets the acomp_ctx, and locks it, then is
> > migrated to CPU #2.
> > - Process B runs on CPU #1, gets the same acomp_ctx, and tries to lock
> > it then waits for process A. Without the lock they would be using the
> > same lock.
> >
> > It is also possible that process A simply gets preempted while running
> > on CPU #1 by another task that also tries to use the acomp_ctx. The
> > mutex also protects against this case.
>
> Got it, thanks for the explanations. It seems with this patch, the mutex
> would be redundant in the first example. Would this also be true of the
> second example where process A gets preempted?
I think the mutex is still required in the second example. Migration
being disabled does not prevent other processes from running on the
same CPU and attempting to use the same acomp_ctx.
> If not, is it worth
> figuring out a solution that works for both migration and preemption?
Not sure exactly what you mean here. I suspect you mean have a single
mechanism to protect against concurrent usage and CPU hotunplug rather
than disabling migration and having a mutex. Yeah that would be ideal,
but probably not for a hotfix.
>
> >
> > >
> > > 2) Seems like the overall problem appears to be applicable to any per-cpu
> > data
> > > that is being used by a process, vis-a-vis cpu hotunplug. Could it be that a
> > > solution in cpu hotunplug can safe-guard more generally? Really not sure
> > > about the specifics of any solution, but it occurred to me that this may
> > not
> > > be a problem unique to zswap.
> >
> > Not really. Static per-CPU data and data allocated with alloc_percpu()
> > should be available for all possible CPUs, regardless of whether they
> > are online or not, so CPU hotunplug is not relevant. It is relevant
> > here because we allocate the memory dynamically for online CPUs only
> > to save memory. I am not sure how important this is as I am not aware
> > what the difference between the number of online and possible CPUs can
> > be in real life deployments.
>
> Thought I would clarify what I meant: the problem of per-cpu data that
> gets allocated dynamically using cpu hotplug and deleted even while in use
> by cpu hotunplug may not be unique to zswap. If so, I was wondering if
> a more generic solution in the cpu hotunplug code would be feasible/worth
> exploring.
I didn't look too closely, if there's something out there or something
can be easily developed I'd be open to updating the zswap code
accordingly, but I don't have time to look into it tbh, and it's too
late in the release cycle to get creative imo.
next prev parent reply other threads:[~2025-01-08 1:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-07 22:22 [PATCH v2 1/2] Revert "mm: zswap: fix race between [de]compression and CPU hotunplug" Yosry Ahmed
2025-01-07 22:22 ` [PATCH v2 2/2] mm: zswap: disable migration while using per-CPU acomp_ctx Yosry Ahmed
2025-01-07 22:47 ` Barry Song
2025-01-07 23:25 ` Yosry Ahmed
2025-01-07 23:38 ` Barry Song
2025-01-07 23:56 ` Barry Song
2025-01-08 0:01 ` Yosry Ahmed
2025-01-07 23:26 ` Barry Song
2025-01-08 0:01 ` Sridhar, Kanchana P
2025-01-08 0:12 ` Yosry Ahmed
2025-01-08 1:10 ` Sridhar, Kanchana P
2025-01-08 1:18 ` Yosry Ahmed [this message]
2025-01-08 2:33 ` Yosry Ahmed
2025-01-08 4:46 ` Nhat Pham
2025-01-08 5:00 ` Chengming Zhou
2025-01-08 5:34 ` Yosry Ahmed
2025-01-08 5:55 ` Yosry Ahmed
2025-01-08 7:56 ` Barry Song
2025-01-08 15:36 ` Yosry Ahmed
2025-01-08 15:49 ` Nhat Pham
2025-01-08 16:17 ` Yosry Ahmed
2025-01-08 6:00 ` Chengming Zhou
2025-01-08 15:36 ` Nhat Pham
2025-01-08 5:06 ` Barry Song
2025-01-08 5:25 ` Barry Song
2025-01-07 23:01 ` [PATCH v2 1/2] Revert "mm: zswap: fix race between [de]compression and CPU hotunplug" Barry Song
2025-01-07 23:39 ` Yosry Ahmed
2025-01-08 0:34 ` Barry Song
2025-01-08 0:54 ` Yosry Ahmed
2025-01-08 1:11 ` Barry Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJD7tkYV_pFGCwpzMD_WiBd+46oVHu946M_ARA8tP79zqkJsDA@mail.gmail.com \
--to=yosryahmed@google.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=kanchana.p.sridhar@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=samsun1006219@gmail.com \
--cc=stable@vger.kernel.org \
--cc=vitalywool@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox