From: YoungJun Park <youngjun.park@lge.com>
To: Chris Li <chrisl@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Kairui Song <kasong@tencent.com>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Nhat Pham <nphamcs@gmail.com>, Baoquan He <bhe@redhat.com>,
Barry Song <baohua@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
gunho.lee@lge.com, taejoon.song@lge.com, austin.kim@lge.com
Subject: Re: [RFC PATCH v2 v2 1/5] mm: swap: introduce swap tier infrastructure
Date: Fri, 13 Feb 2026 11:18:05 +0900 [thread overview]
Message-ID: <aY6J3Yky6yfcIf36@yjaykim-PowerEdge-T330> (raw)
In-Reply-To: <CACePvbVML6ZNJBWU9YSUCWwrbGd2eXMcsWxs6yFssfyBoEk5Uw@mail.gmail.com>
On Thu, Feb 12, 2026 at 01:07:45AM -0800, Chris Li wrote:
> > +
> > + spin_lock(&swap_lock);
> > + spin_lock(&swap_tier_lock);
> > +
> > + p = tmp;
> > + swap_tiers_save(ctx);
> > +
> > + while (!ret && (token = strsep(&p, ", \t\n")) != NULL) {
> > + if (!*token)
> > + continue;
> > +
> > + if (token[0] == '-') {
> > + ret = swap_tiers_remove(token + 1);
> > + } else {
> > +
> > + name = strsep(&token, ":");
> > + if (!token || kstrtos16(token, 10, &prio)) {
> > + ret = -EINVAL;
> > + goto out;
> > + }
> > +
> > + if (name[0] == '+')
> > + ret = swap_tiers_add(name + 1, prio);
> > + else
> > + ret = swap_tiers_modify(name, prio);
> > + }
> > +
> > + if (ret)
> > + goto restore;
> > + }
>
> This function can use some simplification to make the indentation flater.
Agreed. I will refactor this to flatten the indentation.
> > +/*
> > + * struct swap_tier - structure representing a swap tier.
> > + *
> > + * @name: name of the swap_tier.
> > + * @prio: starting value of priority.
> > + * @list: linked list of tiers.
> > +*/
> > +static struct swap_tier {
> > + char name[MAX_TIERNAME];
> > + short prio;
> > + struct list_head list;
> > +} swap_tiers[MAX_SWAPTIER];
>
> We can have a CONFIG option for the MAX_SWAPTIER. I think the default
> should be a small number like 4.
Sounds good. I will add a CONFIG option for it and ensure it doesn't exceed
MAX_SWAPFILE.
> > +
> > +/*
> > + * XXX: Reverting individual operations becomes complex as the number of
> > + * operations grows. Instead, we save the original state beforehand and
> > + * fully restore it if any operation fails.
> > + */
> > +void swap_tiers_save(struct swap_tier_save_ctx ctx[])
>
> I really hope we don't have to do the save and restore thing. Is there
> another design we can simplify this?
I have given this a lot of thought.
Since the current interface allows mixing add (+), remove (-), and modify
operations, we must either restore from a saved state or reverse the
successful individual operations upon failure.
I implemented both approaches and concluded that reversing individual
operations is error-prone. Also, it could be slow if there are many
operations.
Another approach could be using a "global clone tier" strategy.
(Because operation globally synchronized)
Therefore, I would like to propose restricting the interface to handle a
single operation at a time. What do you think?
> > @@ -76,7 +77,6 @@ atomic_long_t nr_swap_pages;
> > EXPORT_SYMBOL_GPL(nr_swap_pages);
> > /* protected with swap_lock. reading in vm_swap_full() doesn't need lock */
> > long total_swap_pages;
> > -#define DEF_SWAP_PRIO -1
> > unsigned long swapfile_maximum_size;
> > #ifdef CONFIG_MIGRATION
> > bool swap_migration_ad_supported;
> > @@ -89,7 +89,7 @@ static const char Bad_offset[] = "Bad swap offset entry ";
> > * all active swap_info_structs
> > * protected with swap_lock, and ordered by priority.
> > */
> > -static PLIST_HEAD(swap_active_head);
> > +PLIST_HEAD(swap_active_head);
>
> One idea is to make each tier have swap_active_head. So different swap
> entry releases on different tiers don't need to be competing on the
> same swap_active_head.
>
> That will require the swapfile don't jump to another tiers.
>
I agree. With the tier structure, we can limit contention to objects within
the same tier.
I also think swap_avail_list could be optimized in a similar way in the
future.
Youngjun
next prev parent reply other threads:[~2026-02-13 2:18 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-26 6:52 [RFC PATCH v2 0/5] mm/swap, memcg: Introduce swap tiers for cgroup based swap control Youngjun Park
2026-01-26 6:52 ` [RFC PATCH v2 v2 1/5] mm: swap: introduce swap tier infrastructure Youngjun Park
2026-02-12 9:07 ` Chris Li
2026-02-13 2:18 ` YoungJun Park [this message]
2026-02-13 14:33 ` YoungJun Park
2026-01-26 6:52 ` [RFC PATCH v2 v2 2/5] mm: swap: associate swap devices with tiers Youngjun Park
2026-01-26 6:52 ` [RFC PATCH v2 v2 3/5] mm: memcontrol: add interface for swap tier selection Youngjun Park
2026-01-26 6:52 ` [RFC PATCH v2 v2 4/5] mm, swap: change back to use each swap device's percpu cluster Youngjun Park
2026-02-12 7:37 ` Chris Li
2026-01-26 6:52 ` [RFC PATCH v2 v2 5/5] mm, swap: introduce percpu swap device cache to avoid fragmentation Youngjun Park
2026-02-12 6:12 ` [RFC PATCH v2 0/5] mm/swap, memcg: Introduce swap tiers for cgroup based swap control Chris Li
2026-02-12 9:22 ` Chris Li
2026-02-13 2:26 ` YoungJun Park
2026-02-13 1:59 ` YoungJun Park
2026-02-12 17:57 ` Nhat Pham
2026-02-12 17:58 ` Nhat Pham
2026-02-13 2:43 ` YoungJun Park
2026-02-12 18:33 ` Shakeel Butt
2026-02-13 3:58 ` YoungJun Park
2026-02-21 3:47 ` Shakeel Butt
2026-02-21 6:07 ` Chris Li
2026-02-21 17:44 ` Shakeel Butt
2026-02-22 1:16 ` YoungJun Park
2026-02-21 14:30 ` YoungJun 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=aY6J3Yky6yfcIf36@yjaykim-PowerEdge-T330 \
--to=youngjun.park@lge.com \
--cc=akpm@linux-foundation.org \
--cc=austin.kim@lge.com \
--cc=baohua@kernel.org \
--cc=bhe@redhat.com \
--cc=chrisl@kernel.org \
--cc=gunho.lee@lge.com \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=roman.gushchin@linux.dev \
--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