From: Bingfang Guo <bfguo@icloud.com>
To: Barry Song <baohua@kernel.org>
Cc: bingfangguo@tencent.com,
Andrew Morton <akpm@linux-foundation.org>,
Johannes Weiner <hannes@cmpxchg.org>,
David Hildenbrand <david@kernel.org>,
Michal Hocko <mhocko@kernel.org>, Qi Zheng <qi.zheng@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Lorenzo Stoakes <ljs@kernel.org>,
Kairui Song <kasong@tencent.com>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baoquan He <baoquan.he@linux.dev>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Yu Zhao <yuzhao@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] mm/mglru: skip oom killing for order != 0 allocs in kswapd
Date: Wed, 25 Nov 2026 17:31:58 +0800 [thread overview]
Message-ID: <awarDrT/DT7tQu+U@lima-default> (raw)
In-Reply-To: <CAGsJ_4z-UdXQg0LYqymEZdoHALPmAZC7eGcXbGad6f0sdjmkcw@mail.gmail.com>
On Wed, Nov 25, 2026 at 03:38:25PM +0800, Barry Song wrote:
> On Wed, Nov 25, 2026 at 12:32 PM Bingfang Guo via B4 Relay
> <devnull+bingfangguo.tencent.com@kernel.org> wrote:
> >
> > From: Bingfang Guo <bingfangguo@tencent.com>
> >
> > We observed that when MGLRU min_ttl is set and the system is highly
> > fragmented, high order allocations (e.g. order == 9) will fail and wake
> > up kswapd. It can not make any progress, while pushing generations of
> > memcgs so that they all end up younger than min_ttl_ms, repeatedly
> > triggering the OOM killer in lru_gen_age_node(). Then the whole process
> > repeats until all processes are killed and the kernel panics.
>
> It seems we should address the underlying issue of why order-9 reclaim
> keeps advancing memcg generations until all memcgs are younger than
> min_ttl.
>
> >
> > The purpose of the min_ttl is to prevent thrashing when all memcgs are
> > too young to reclaim instead of preventing fragmentation. So fix this by
> > restoring the behavior in commit 30d77b7eef019 ("mm/mglru: fix
> > ineffective protection calculation"), which skips OOM killer invocations
> > in lru_gen_age_node() for sc->order != 0.
>
> I'm not really convinced this is the correct fix. It seems to work
> around an issue with min_ttl for higher-order allocations, but it
> doesn't appear to address the root cause.
>
> And what about order-1 and order-2 allocations?
>
Hi, Barry! Thanks for your reviewing!
I agree that we should fix the root cause. Reclaims triggered by high order
allocations should not push the generations forward too frequently. That is
really insightful!
> >
> > Fixes: 30d77b7eef019 ("mm/mglru: fix ineffective protection calculation")
> > Signed-off-by: Bingfang Guo <bingfangguo@tencent.com>
> > ---
> > ==== Testing ====
> >
> > Tested on a VM with 6 cores and 6GiB of memory, HZ=1000, MGLRU enabled,
> > min_ttl_ms set to 1000, and a workload that fragments the memory then
> > allocates 2M pages.
> >
>
> So the real question is: if order-9 reclaim can't make progress, why
> do we keep triggering memcg aging and end up over-reclaiming?
>
> > Without the patch, kswapd kills all processes and panics the system even
> > with plenty of memory available. With the patch, allocations fail but
> > the system remains stable.
>
> I know, I know. But this isn't really the root cause, is it?
> Even if we avoid OOM kills, we may still end up with excessive reclaim
> or system overheating, right?
>
You are right. Maybe we can start from skipping aging in reclaim path if the
youngest gen is still too young? And maybe for this path, min_ttl can have a
default value? Is that a good idea?
diff --git a/mm/vmscan.c b/mm/vmscan.c
index d891ae46baf49..7f9b14b772d14 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5136,8 +5136,11 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq,
return false;
+ /* avoid excessive aging for huge allocations */
+ if (unlikely(sc->order)) {
+ int gen = lru_gen_from_seq(max_seq);
+ unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]);
+ return !time_is_before_jiffies(birth + min_ttl);
+ }
/* better to run aging even though eviction is still possible */
return evictable_min_seq(min_seq, swappiness) + MIN_NR_GENS == max_seq;
I will give this a test later and share more findings.
Thanks,
Bingfang
> >
> > --
> > Changes in v2:
> > - Reword the comments to explain the purpose clearly. (Kairui)
> > - Relax the skip condition to sc->order != 0 for soundness. (sashiko)
> > - Rebase to mm-unstable.
> > - Cc stable.
> > - Link to v1: https://lore.kernel.org/all/20261027-fix-mglru-kswapd-age-v1-1-b1ffdec4ae52@tencent.com/
> > ---
> > mm/vmscan.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index 836f50814ffa..9fadc6f9da49 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -4351,7 +4351,7 @@ static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc)
> > {
> > struct mem_cgroup *memcg;
> > unsigned long min_ttl = READ_ONCE(lru_gen_min_ttl);
> > - bool reclaimable = !min_ttl;
> > + bool reclaimable = !min_ttl || sc->order;
> >
> > VM_WARN_ON_ONCE(!current_is_kswapd());
> >
> > @@ -4371,6 +4371,9 @@ static void lru_gen_age_node(struct pglist_data *pgdat, struct scan_control *sc)
> > * The main goal is to OOM kill if every generation from all memcgs is
> > * younger than min_ttl. However, another possibility is all memcgs are
> > * either too small or below min.
> > + *
> > + * OOM killing for fragmentation is not desired. So skip this when
> > + * sc->order != 0.
> > */
> > if (!reclaimable && mutex_trylock(&oom_lock)) {
> > struct oom_control oc = {
> >
> > ---
> > base-commit: a3d0117e02bfa1c3bb6c50e7afe42bbecdbb3459
> > change-id: 20261026-fix-mglru-kswapd-age-98390614c746
> >
> > Best regards,
> > --
> > Bingfang Guo <bingfangguo@tencent.com>
> >
> >
>
> Thanks,
> Barry
prev parent reply other threads:[~2026-11-25 9:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 4:32 Bingfang Guo via B4 Relay
2026-11-25 7:38 ` Barry Song
2026-11-25 9:31 ` Bingfang Guo [this message]
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=awarDrT/DT7tQu+U@lima-default \
--to=bfguo@icloud.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=bingfangguo@tencent.com \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=yuzhao@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
all inboxes | Powered by JetHome®