linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Shakeel Butt <shakeel.butt@linux.dev>,
	mhocko@kernel.org,  hannes@cmpxchg.org,
	akpm@linux-foundation.org
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	 Johannes Weiner <hannes@cmpxchg.org>,
	David Hildenbrand <david@redhat.com>,
	 Michal Hocko <mhocko@kernel.org>,
	Qi Zheng <zhengqi.arch@bytedance.com>,
	 Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Axel Rasmussen <axelrasmussen@google.com>,
	 Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
	linux-kernel@vger.kernel.org,  chunguang.xu@shopee.com
Subject: Re: [PATCH v2] mm/vmscan: skip increasing kswapd_failures when reclaim was boosted
Date: Fri, 27 Feb 2026 10:15:09 +0800	[thread overview]
Message-ID: <6sx72x4eulir6hxacg7wlxpprv4hwszsvqsmz2qst2gjgd5s25@47sizxwwyrzh> (raw)
In-Reply-To: <e5bdgvhyr6ainrwyfybt6szu23ucnsvlgn4pv2xdzikr4p3ka4@hyyhkudfcorw>

On Fri, Nov 07, 2025 at 05:11:58PM +0800, Shakeel Butt wrote:
> On Fri, Oct 24, 2025 at 10:27:11AM +0800, Jiayuan Chen wrote:
> > We encountered a scenario where direct memory reclaim was triggered,
> > leading to increased system latency:
> > 
> > 1. The memory.low values set on host pods are actually quite large, some
> >    pods are set to 10GB, others to 20GB, etc.
> > 2. Since most pods have memory protection configured, each time kswapd is
> >    woken up, if a pod's memory usage hasn't exceeded its own memory.low,
> >    its memory won't be reclaimed.
> 
> Can you share the numa configuration of your system? How many nodes are
> there?
> 
> > 3. When applications start up, rapidly consume memory, or experience
> >    network traffic bursts, the kernel reaches steal_suitable_fallback(),
> >    which sets watermark_boost and subsequently wakes kswapd.
> > 4. In the core logic of kswapd thread (balance_pgdat()), when reclaim is
> >    triggered by watermark_boost, the maximum priority is 10. Higher
> >    priority values mean less aggressive LRU scanning, which can result in
> >    no pages being reclaimed during a single scan cycle:
> > 
> > if (nr_boost_reclaim && sc.priority == DEF_PRIORITY - 2)
> >     raise_priority = false;
> 
> Am I understanding this correctly that watermark boost increase the
> chances of this issue but it can still happen?
> 
> > 
> > 5. This eventually causes pgdat->kswapd_failures to continuously
> >    accumulate, exceeding MAX_RECLAIM_RETRIES, and consequently kswapd stops
> >    working. At this point, the system's available memory is still
> >    significantly above the high watermark — it's inappropriate for kswapd
> >    to stop under these conditions.
> > 
> > The final observable issue is that a brief period of rapid memory
> > allocation causes kswapd to stop running, ultimately triggering direct
> > reclaim and making the applications unresponsive.
> > 
> > Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> > 
> > ---
> > v1 -> v2: Do not modify memory.low handling
> > https://lore.kernel.org/linux-mm/20251014081850.65379-1-jiayuan.chen@linux.dev/
> > ---
> >  mm/vmscan.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index 92f4ca99b73c..fa8663781086 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -7128,7 +7128,12 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
> >  		goto restart;
> >  	}
> >  
> > -	if (!sc.nr_reclaimed)
> > +	/*
> > +	 * If the reclaim was boosted, we might still be far from the
> > +	 * watermark_high at this point. We need to avoid increasing the
> > +	 * failure count to prevent the kswapd thread from stopping.
> > +	 */
> > +	if (!sc.nr_reclaimed && !boosted)
> >  		atomic_inc(&pgdat->kswapd_failures);
> 
> In general I think not incrementing the failure for boosted kswapd
> iteration is right. If this issue (high protection causing kswap
> failures) happen on non-boosted case, I am not sure what should be right
> behavior i.e. allocators doing direct reclaim potentially below low
> protection or allowing kswapd to reclaim below low. For min, it is very
> clear that direct reclaimer has to reclaim as they may have to trigger
> oom-kill. For low protection, I am not sure.





Hi all,

Sorry to bring this up late, but I've been thinking about a potential
corner case with this patch and would appreciate some input.

Since steal_suitable_fallback() triggers boost_watermark() whenever
pages are stolen across migrate types, and this patch prevents
kswapd_failures from incrementing during boosted reclaim, I'm wondering
if there's a theoretical scenario where kswapd could end up running
continuously.

For example, if UNMOVABLE and MOVABLE allocations are competing for
memory over a sustained period, the repeated cross-migratetype stealing
would keep boosting watermarks and waking kswapd. If kswapd can't
actually reclaim anything in this situation, it would never hit
MAX_RECLAIM_RETRIES and just keep spinning.

Two questions:

1. Has anyone seen this kind of sustained migratetype stealing in
practice? I'm not sure how realistic this scenario is.


2. If it does happen, waking kswapd for boost reclaim itself makes
total sense - reclaiming order-0 pages to reduce fragmentation is
the right thing to do. But a busy-looping kswapd that can't
actually reclaim anything would still burn CPU cycles, and keep
grabbing lruvec->lru_lock and zone->lock on every pass through
shrink_node(), which could hurt page fault and allocation latency
for other threads. Would it be worth adding some backoff mechanism
for boosted reclaim failures?

Just want to understand if this is something worth worrying about
or purely theoretical.

Thanks,


  parent reply	other threads:[~2026-02-27  2:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251024022711.382238-1-jiayuan.chen@linux.dev>
2025-10-26  4:40 ` Andrew Morton
2025-11-08  1:11 ` Shakeel Butt
2025-11-12  2:21   ` Jiayuan Chen
2025-11-13 23:41     ` Shakeel Butt
2025-11-13 10:02   ` Michal Hocko
2025-11-13 19:28     ` Shakeel Butt
2025-11-14  2:23       ` Jiayuan Chen
2026-02-27  2:15   ` Jiayuan Chen [this message]
2025-11-13 23:47 ` Shakeel Butt
2025-11-14  4:17   ` Jiayuan Chen
2025-11-15  0:40     ` Andrew Morton

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=6sx72x4eulir6hxacg7wlxpprv4hwszsvqsmz2qst2gjgd5s25@47sizxwwyrzh \
    --to=jiayuan.chen@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=chunguang.xu@shopee.com \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    --cc=zhengqi.arch@bytedance.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