From: Nhat Pham <nphamcs@gmail.com>
To: Yosry Ahmed <yosryahmed@google.com>
Cc: Chengming Zhou <chengming.zhou@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>,
Andrew Morton <akpm@linux-foundation.org>,
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>,
"Sridhar, Kanchana P" <kanchana.p.sridhar@intel.com>
Subject: Re: [PATCH v2 2/2] mm: zswap: disable migration while using per-CPU acomp_ctx
Date: Wed, 8 Jan 2025 22:36:57 +0700 [thread overview]
Message-ID: <CAKEwX=NHP7G1KJ1A0c+ciWme8iU6NKddgQfmcqscHrVQnbQyrQ@mail.gmail.com> (raw)
In-Reply-To: <CAJD7tkZ+UeXXvFc+M9JssooW_0rW-GVgUMo3GVcSMCxQhndZuA@mail.gmail.com>
On Wed, Jan 8, 2025 at 12:34 PM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> On Tue, Jan 7, 2025 at 9:00 PM Chengming Zhou <chengming.zhou@linux.dev> wrote:
> Please correct me if I am wrong, but my understanding is that memory
> allocated with alloc_percpu() is allocated for each *possible* CPU,
> and does not go away when CPUs are offlined. We allocate the per-CPU
> crypto_acomp_ctx structs with alloc_percpu() (including the mutex), so
> they should not go away with CPU offlining.
>
> OTOH, we allocate the crypto_acomp_ctx.acompx, crypto_acomp_ctx.req,
> and crypto_acomp_ctx.buffer only for online CPUs through the CPU
> hotplug notifiers (i.e. zswap_cpu_comp_prepare() and
> zswap_cpu_comp_dead()). These are the resources that can go away with
> CPU offlining, and what we need to protect about.
>
> The approach I am taking here is to hold the per-CPU mutex in the CPU
> offlining code while we free these resources, and set
> crypto_acomp_ctx.req to NULL. In acomp_ctx_get_cpu_locked(), we hold
> the mutex of the current CPU, and check if crypto_acomp_ctx.req is
> NULL.
>
> If it is NULL, then the CPU is offlined between raw_cpu_ptr() and
> acquiring the mutex, and we retry on the new CPU that we end up on. If
> it is not NULL, then we are guaranteed that the resources will not be
> freed by CPU offlining until acomp_ctx_put_unlock() is called and the
> mutex is unlocked.
>
Ah you're right, that makes a lot of sense now :)
next prev parent reply other threads:[~2025-01-08 15:37 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
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 [this message]
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='CAKEwX=NHP7G1KJ1A0c+ciWme8iU6NKddgQfmcqscHrVQnbQyrQ@mail.gmail.com' \
--to=nphamcs@gmail.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=samsun1006219@gmail.com \
--cc=stable@vger.kernel.org \
--cc=vitalywool@gmail.com \
--cc=yosryahmed@google.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