From: YoungJun Park <youngjun.park@lge.com>
To: Kairui Song <ryncsn@gmail.com>
Cc: Baoquan He <bhe@redhat.com>,
akpm@linux-foundation.org, linux-mm@kvack.org,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
chrisl@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org,
roman.gushchin@linux.dev, shakeel.butt@linux.dev,
muchun.song@linux.dev, shikemeng@huaweicloud.com,
nphamcs@gmail.com, baohua@kernel.org, gunho.lee@lge.com,
taejoon.song@lge.com
Subject: Re: [PATCH 1/3] mm, swap: change back to use each swap device's percpu cluster
Date: Sat, 15 Nov 2025 18:28:17 +0900 [thread overview]
Message-ID: <aRhHsbh6ZtjCJ3wP@yjaykim-PowerEdge-T330> (raw)
In-Reply-To: <CAMgjq7D=eULiSQzUo6AQ16DUMtL_EQaRSOXGRhMJrUzakvj5Jg@mail.gmail.com>
On Fri, Nov 14, 2025 at 11:52:25PM +0800, Kairui Song wrote:
> On Fri, Nov 14, 2025 at 9:05 AM Baoquan He <bhe@redhat.com> wrote:
> > On 11/13/25 at 08:45pm, YoungJun Park wrote:
> > > On Thu, Nov 13, 2025 at 02:07:59PM +0800, Kairui Song wrote:
> > > > On Sun, Nov 9, 2025 at 8:54 PM Youngjun Park <youngjun.park@lge.com> wrote:
> > > > >
> > > > > This reverts commit 1b7e90020eb7 ("mm, swap: use percpu cluster as
> > > > > allocation fast path").
> > > > >
> > > > > Because in the newly introduced swap tiers, the global percpu cluster
> > > > > will cause two issues:
> > > > > 1) it will cause caching oscillation in the same order of different si
> > > > > if two different memcg can only be allowed to access different si and
> > > > > both of them are swapping out.
> > > > > 2) It can cause priority inversion on swap devices. Imagine a case where
> > > > > there are two memcg, say memcg1 and memcg2. Memcg1 can access si A, B
> > > > > and A is higher priority device. While memcg2 can only access si B.
> > > > > Then memcg 2 could write the global percpu cluster with si B, then
> > > > > memcg1 take si B in fast path even though si A is not exhausted.
> > > > >
> > > > > Hence in order to support swap tier, revert commit 1b7e90020eb7 to use
> > > > > each swap device's percpu cluster.
> > > > >
> > > > > Co-developed-by: Baoquan He <bhe@redhat.com>
> > > > > Suggested-by: Kairui Song <kasong@tencent.com>
> > > > > Signed-off-by: Baoquan He <bhe@redhat.com>
> > > > > Signed-off-by: Youngjun Park <youngjun.park@lge.com>
> > > >
> > > > Hi Youngjun, Baoquan, Thanks for the work on the percpu cluster thing.
> > >
> > > Hello Kairui,
>
> ...
>
> > >
> > > Yeah... The rotation rule has indeed changed. I remember the
> > > discussion about rotation behavior:
> > > https://lore.kernel.org/linux-mm/aPc3lmbJEVTXoV6h@yjaykim-PowerEdge-T330/
> > >
> > > After that discussion, I've been thinking about the rotation.
> > > Currently, the requeue happens after every priority list traversal, and this logic
> > > is easily affected by changes.
> > > The rotation logic change behavior change is not not mentioned somtimes.
> > > (as you mentioned in commit 1b7e90020eb7).
> > >
> > > I'd like to share some ideas and hear your thoughts:
> > >
> > > 1. Getting rid of the same priority requeue rule
> > > - same priority devices get priority - 1 or + 1 after requeue
> > > (more add or remove as needed to handle any overlapping priority appropriately)
> > >
> > > 2. Requeue only when a new cluster is allocated
> > > - Instead of requeueing after every priority list traversal, we
> > > requeue only when a cluster is fully used
> > > - This might have some performance impact, but the rotation behavior
> > > would be similar to the existing one (though slightly different due
> > > to synchronization and logic processing changes)
> >
> > 2) sounds better to me, and the logic and code change is simpler.
> >
> > Removing requeue may change behaviour. Swap devices of the same priority
> > should be round robin to take.
>
> I agree. We definitely need balancing between devices of the same
> priority, cluster based rotation seems good enough.
Hello Kairui, Baoquan.
Thanks for your feedback.
Okay I try to keep current rotation logic workable on next patch iteration.
Based on Kairui suggested previously,
We can keep the per-cpu si cache alive.
(However, since it could pick si from unselected tiers, it should
exist per tier - per cpu)
Or, following the current code structure, we could also consider,
Requeue while holding swap_avail_lock when the cluster is consumed.
> And I'm thinking if we can have a better rotation mechanism? Maybe
> plist isn't the best way to do rotation if we want to minimize the
> cost of rotation.
I did some more ideation.
(Although it is some workable way, next step idea. like I said just ideation )
I've been thinking about the inefficiencies with plist_requeue during
rotation, and the plist_for_each_entry traversal structure itself.
There is also small problem like it can be ended up selecting a lower priority swap device
while traversing the list, even when a higher priority swap device gets
inserted into the plist.
So anyway as I think...
- On the read side (alloc_swap_entry), manage it so only one swap
device can be obtained when selecting a swap device. (grabbing
read_lock). swap selection logic does not any behavior affecting
logic change like current approach. just see swapdevice only.
- On the write side, handle it appropriately using plist or some
improved data structure. (grabbing write_lock)
- For rotation, instead of placing a plist per swap device, we could
create something like a priority node. In this priority node
structure, entries would be rotated each time a cluster is fully used.
- Also, with tiers introduced, since we only need to traverse the
selected tier for each I/O, the current single swap_avail_list may
not be suitable anymore. This could be changed to a per-tier
structure.
Thanks,
YoungJun
next prev parent reply other threads:[~2025-11-15 9:28 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-09 12:49 [RFC] mm/swap, memcg: Introduce swap tiers for cgroup based swap control Youngjun Park
2025-11-09 12:49 ` [PATCH 1/3] mm, swap: change back to use each swap device's percpu cluster Youngjun Park
2025-11-13 6:07 ` Kairui Song
2025-11-13 11:45 ` YoungJun Park
2025-11-14 1:05 ` Baoquan He
2025-11-14 15:52 ` Kairui Song
2025-11-15 9:28 ` YoungJun Park [this message]
2025-11-09 12:49 ` [PATCH 2/3] mm: swap: introduce swap tier infrastructure Youngjun Park
2025-11-12 14:20 ` Chris Li
2025-11-13 2:01 ` YoungJun Park
2025-11-09 12:49 ` [PATCH 3/3] mm/swap: integrate swap tier infrastructure into swap subsystem Youngjun Park
2025-11-10 11:40 ` kernel test robot
2025-11-10 12:12 ` kernel test robot
2025-11-10 13:26 ` kernel test robot
2025-11-12 14:44 ` Chris Li
2025-11-13 4:07 ` YoungJun Park
2025-11-12 13:34 ` [RFC] mm/swap, memcg: Introduce swap tiers for cgroup based swap control Chris Li
2025-11-13 1:33 ` YoungJun Park
2025-11-15 1:22 ` SeongJae Park
2025-11-15 9:44 ` YoungJun Park
2025-11-15 16:56 ` SeongJae Park
2025-11-15 15:13 ` Chris Li
2025-11-15 17:24 ` SeongJae Park
2025-11-17 22:17 ` Chris Li
2025-11-18 1:11 ` SeongJae Park
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=aRhHsbh6ZtjCJ3wP@yjaykim-PowerEdge-T330 \
--to=youngjun.park@lge.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=bhe@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=chrisl@kernel.org \
--cc=gunho.lee@lge.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=roman.gushchin@linux.dev \
--cc=ryncsn@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=taejoon.song@lge.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