linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kairui Song <ryncsn@gmail.com>
To: kasong@tencent.com
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	 Axel Rasmussen <axelrasmussen@google.com>,
	Yuanchu Xie <yuanchu@google.com>,  Wei Xu <weixugc@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 David Hildenbrand <david@kernel.org>,
	Michal Hocko <mhocko@kernel.org>,
	 Qi Zheng <zhengqi.arch@bytedance.com>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	 Lorenzo Stoakes <ljs@kernel.org>, Barry Song <baohua@kernel.org>,
	David Stevens <stevensd@google.com>,
	 Chen Ridong <chenridong@huaweicloud.com>,
	Leno Hou <lenohou@gmail.com>,  Yafang Shao <laoar.shao@gmail.com>,
	Yu Zhao <yuzhao@google.com>,
	 Zicheng Wang <wangzicheng@honor.com>,
	Kalesh Singh <kaleshsingh@google.com>,
	 Suren Baghdasaryan <surenb@google.com>,
	Chris Li <chrisl@kernel.org>, Vernon Yang <vernon2gm@gmail.com>,
	 linux-kernel@vger.kernel.org, Qi Zheng <qi.zheng@linux.dev>,
	 Baolin Wang <baolin.wang@linux.alibaba.com>
Subject: Re: [PATCH v5 04/14] mm/mglru: restructure the reclaim loop
Date: Fri, 17 Apr 2026 02:47:18 +0800	[thread overview]
Message-ID: <CAMgjq7ArnmmoHOGRt6Wc8hu7tjx_t583-UVzJK+HOHgjjetQ9g@mail.gmail.com> (raw)
In-Reply-To: <20260413-mglru-reclaim-v5-4-8eaeacbddc44@tencent.com>

Forwarding a sashiko review, which I think part of it makes sense:

> commit d1c559ae5b78a93fe3aef7c2115b93fc96970a6f
> Author: Kairui Song <kasong@tencent.com>
> mm/mglru: restructure the reclaim loop
> This commit decouples aging and rotation in the MGLRU reclaim loop. It
> calculates the scan number once per reclaim pass and consistently applies
> priority shifting. The behavior for offline memcgs and default priority
> aging is adjusted to make rotation more explicit.
> > diff --git a/mm/vmscan.c b/mm/vmscan.c
> > index 963362523782a..d4aaaa62056d9 100644
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> [ ... ]
> > +static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc,
> > +    struct mem_cgroup *memcg, int swappiness)
> >  {
> [ ... ]
> >  nr_to_scan = apply_proportional_protection(memcg, sc, nr_to_scan);
> > + nr_to_scan >>= sc->priority;
> >
> > + if (!nr_to_scan && sc->priority < DEF_PRIORITY)
> > + nr_to_scan = min(evictable, SWAP_CLUSTER_MAX);
> >
> > + return nr_to_scan;
> >  }
> Does the new minimum batch fallback invert proportional memory protection?
> When an unprotected memcg has 1024 evictable pages at priority 10, the
> scan target evaluates to 1 (1024 >> 10) and bypasses the fallback. However,
> a protected memcg of the exact same size has its target floored to
> SWAP_CLUSTER_MAX (32) before shifting. This evaluates to 0 (32 >> 10),
> triggering the fallback and forcing a scan of 32 pages. This results in
> the protected memcg being scanned much more aggressively than the
> unprotected one.

No? This part of the review is not correct.
Proportional memory protection have a much more aggressive
batch fallback. We are already very cautious here.

> >  static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
> >  {
> > + bool need_rotate = false;
> >  long nr_batch, nr_to_scan;
> > - unsigned long scanned = 0;
> >  int swappiness = get_swappiness(lruvec, sc);
> > + struct mem_cgroup *memcg = lruvec_memcg(lruvec);
> > +
> > + nr_to_scan = get_nr_to_scan(lruvec, sc, memcg, swappiness);
> > + if (!nr_to_scan)
> > + need_rotate = true;
> >
> > - while (true) {
> > + while (nr_to_scan > 0) {
> Could setting need_rotate for zero scan targets shield small memcgs from
> reclaim?
> If a memcg has fewer than 4096 evictable pages, its scan target at
> DEF_PRIORITY evaluates to 0. Setting need_rotate to true causes shrink_one()
> to return MEMCG_LRU_YOUNG, moving the memcg to the young generation.
> Since subsequent global reclaim passes with higher priorities iterate over
> the old generation, this might completely isolate these small memcgs from
> memory reclaim.

This concern makes sense.

I think the need_rotate = true above can be just dropped then,
it was added due to previous concern that tiny cgroups don't have a
chance to be rotated, but now they might get overly rotated
indeed. Meanwhile now we already have a min batch limit above
when priority < DEF_PRIORITY, and we never do aging (before or
after this patch) at DEF_PRIORITY anyway. So if priority has be
escalated, we will
always enter the reclaim loop and have the chance to do aging / rotation.

Removing this need_rotate for !nr_to_scan looks perfectly fine to me now,
and cleaner than before.


  parent reply	other threads:[~2026-04-16 18:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-12 16:48 [PATCH v5 00/14] mm/mglru: improve reclaim loop and dirty folio handling Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 01/14] mm/mglru: consolidate common code for retrieving evictable size Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 02/14] mm/mglru: rename variables related to aging and rotation Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 03/14] mm/mglru: relocate the LRU scan batch limit to callers Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 04/14] mm/mglru: restructure the reclaim loop Kairui Song via B4 Relay
2026-04-16  6:33   ` Barry Song
2026-04-16 18:47   ` Kairui Song [this message]
2026-04-12 16:48 ` [PATCH v5 05/14] mm/mglru: scan and count the exact number of folios Kairui Song via B4 Relay
2026-04-15  3:16   ` Baolin Wang
2026-04-16  7:01   ` Barry Song
2026-04-16 17:39     ` Kairui Song
2026-04-12 16:48 ` [PATCH v5 06/14] mm/mglru: use a smaller batch for reclaim Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 07/14] mm/mglru: don't abort scan immediately right after aging Kairui Song via B4 Relay
2026-04-16  7:32   ` Barry Song
2026-04-12 16:48 ` [PATCH v5 08/14] mm/mglru: remove redundant swap constrained check upon isolation Kairui Song via B4 Relay
2026-04-14  7:43   ` Chen Ridong
2026-04-15  3:19   ` Baolin Wang
2026-04-16  9:05   ` Barry Song
2026-04-12 16:48 ` [PATCH v5 09/14] mm/mglru: use the common routine for dirty/writeback reactivation Kairui Song via B4 Relay
2026-04-15  3:30   ` Baolin Wang
2026-04-16  9:18   ` Barry Song
2026-04-12 16:48 ` [PATCH v5 10/14] mm/mglru: simplify and improve dirty writeback handling Kairui Song via B4 Relay
2026-04-15  3:25   ` Baolin Wang
2026-04-12 16:48 ` [PATCH v5 11/14] mm/mglru: remove no longer used reclaim argument for folio protection Kairui Song via B4 Relay
2026-04-12 16:48 ` [PATCH v5 12/14] mm/vmscan: remove sc->file_taken Kairui Song via B4 Relay
2026-04-14  7:46   ` Chen Ridong
2026-04-12 16:48 ` [PATCH v5 13/14] mm/vmscan: remove sc->unqueued_dirty Kairui Song via B4 Relay
2026-04-14  7:46   ` Chen Ridong
2026-04-12 16:48 ` [PATCH v5 14/14] mm/vmscan: unify writeback reclaim statistic and throttling Kairui Song via B4 Relay
2026-04-17  2:51 ` [PATCH v5 00/14] mm/mglru: improve reclaim loop and dirty folio handling wangxinyu19
2026-04-17  2:55 ` wangxinyu19

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=CAMgjq7ArnmmoHOGRt6Wc8hu7tjx_t583-UVzJK+HOHgjjetQ9g@mail.gmail.com \
    --to=ryncsn@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chenridong@huaweicloud.com \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kaleshsingh@google.com \
    --cc=kasong@tencent.com \
    --cc=laoar.shao@gmail.com \
    --cc=lenohou@gmail.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=stevensd@google.com \
    --cc=surenb@google.com \
    --cc=vernon2gm@gmail.com \
    --cc=wangzicheng@honor.com \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.com \
    --cc=yuzhao@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