mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Barry Song <baohua@kernel.org>, Hui Zhu <hui.zhu@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kairui Song <kasong@tencent.com>, Qi Zheng <qi.zheng@linux.dev>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	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>,
	Lorenzo Stoakes <ljs@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Hui Zhu <zhuhui@kylinos.cn>
Subject: Re: [PATCH mm-unstable v3 2/2] mm/vmscan: apply too_many_isolated() throttling to MGLRU eviction
Date: Wed, 19 Aug 2026 10:15:03 +0800	[thread overview]
Message-ID: <39871dbf-25e3-4518-9942-a733dbb6acf5@linux.alibaba.com> (raw)
In-Reply-To: <CAGsJ_4xKM1R95TEpKoicGYQB8Qafez6hKJF=Z98A_2j43X5GAA@mail.gmail.com>



On 8/19/26 6:06 AM, Barry Song wrote:
> On Tue, Aug 18, 2026 at 8:49 PM Hui Zhu <hui.zhu@linux.dev> wrote:
>>
>> From: Hui Zhu <zhuhui@kylinos.cn>
>>
>> The legacy path throttles direct reclaim in shrink_inactive_list()
>> when too many isolated folios pile up, but MGLRU's evict_folios()
>> isolates folios without this check, which can lead to unnecessary
>> swapping, thrashing and OOM.
>>
>> With the NR_ISOLATED counters now updated in evict_folios(), extract
>> the throttling loop from shrink_inactive_list() into
>> throttle_is_throttled() and reuse it in evict_folios(). Since the
>> type to isolate is unknown until isolation and isolate_folios() may
>> fall back to the other type, check all evictable types with
>> for_each_evictable_type() and throttle if any of them has too many
>> isolated folios.
>>
> 
> I feel this is unlikely to work. MGLRU behaves quite differently from the
> active/inactive LRU, and its `NR_INACTIVE_FILE` accounting is also very
> different.
> 
> With the active/inactive LRU, shrink_inactive_list() ensures that we
> always have an inactive list with pages available for reclaim. With MGLRU,
> however, a generation can legitimately point to an empty list, so this
> assumption does not hold.
> 
> try_to_inc_min_seq:
> 
>          /* see the comment on lru_gen_folio */
>          if (swappiness && swappiness <= MAX_SWAPPINESS) {
>                  unsigned long seq = lrugen->max_seq - MIN_NR_GENS;
> 
>                  if (min_seq[LRU_GEN_ANON] > seq && min_seq[LRU_GEN_FILE] < seq)
>                          min_seq[LRU_GEN_ANON] = seq;
>                  else if (min_seq[LRU_GEN_FILE] > seq &&
> min_seq[LRU_GEN_ANON] < seq)
>                          min_seq[LRU_GEN_FILE] = seq;
>          }
> 
> At that point, we have no inactive pages for the type, so the
> throttle will take effect when the following condition is true:
> 
> too_many = isolated > inactive;
> 
> With MGLRU, however, we can still fall back to the other type even
> when there are no inactive pages for the current type.

Yes, that's a valid concern. So I think we can check the isolation of 
both types for MGLRU to avoid this case:

static bool check_need_throttle()
{
         bool need_throttle = true;

         for_each_evictable_type(i, swappiness) {
                 if (!too_many_isolated(pgdat, i, sc))
                         need_throttle = false;
         }

         return need_throttle;
}

In evict_folios():
	......
	while (unlikely(check_need_throttle())) {
                 if (stalled)
                         return 0;

                 /* wait a bit for the reclaimer. */
                 stalled = true;
                 reclaim_throttle(pgdat, VMSCAN_THROTTLE_ISOLATED);

                 /* We are about to die and free our memory. Return now. */
                 if (fatal_signal_pending(current))
                         return SWAP_CLUSTER_MAX;
         }

> BTW, if we are hitting isolated > inactive with MGLRU, it probably
> means the generations are quite imbalanced—we are running out of
> reclaimable generations. In that case, we may actually want
> reclamation to proceed with aging instead.

The typical 'isolated > inactive' case is that we've tried our best with 
aging, but cold pages production can't keep up with isolation speed, 
especially under concurrent reclaim from multiple processes. In this 
case, I think throttling is reasonable.

>> If a fatal signal is pending, fake reclaim progress the same way the
>> legacy path does, so the dying task exits reclaim quickly instead of
>> being held in the throttle.
>>
>> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
>> ---
>>   mm/vmscan.c | 71 ++++++++++++++++++++++++++++++++++++++++++++---------
>>   1 file changed, 59 insertions(+), 12 deletions(-)
>>
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 98226bb021f3..6fe8824430ac 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -1819,7 +1819,7 @@ bool folio_isolate_lru(struct folio *folio)
>>    * the LRU list will go small and be scanned faster than necessary, leading to
>>    * unnecessary swapping, thrashing and OOM.
>>    */
>> -static bool too_many_isolated(struct pglist_data *pgdat, int file,
>> +static bool too_many_isolated(struct pglist_data *pgdat, bool file,
>>                  struct scan_control *sc)
>>   {
>>          unsigned long inactive, isolated;
>> @@ -1856,6 +1856,37 @@ static bool too_many_isolated(struct pglist_data *pgdat, int file,
>>          return too_many;
>>   }
>>
>> +/*
>> + * Throttle reclaim if too many isolated folios are piling up. If this makes
>> + * no progress, the caller is probably looping on unevictable folios, so give
>> + * up. Returns true to tell the caller to stop reclaiming, and sets @fatal
>> + * if the task received a fatal signal while waiting, so that the caller can
>> + * bail out faster.
>> + */
>> +static bool throttle_is_throttled(struct pglist_data *pgdat, bool file,
>> +                                 struct scan_control *sc, bool *fatal)
>> +{
>> +       bool stalled = false;
>> +
>> +       *fatal = false;
> 
> TBH, I find the name quite weird :-)

Yes, that is not what I meant. :) What I mean is to use a readable 
variable to return instead of 'true' or 'false':

static bool throttle_isolated(struct pglist_data *pgdat, bool file,
                 struct scan_control *sc, bool *fatal)
{
         bool stalled = false;

         *fatal = false;
         while (unlikely(too_many_isolated(pgdat, file, sc))) {
                 if (stalled)
                         return stalled;

                 /* wait a bit for the reclaimer. */
                 stalled = true;
                 reclaim_throttle(pgdat, VMSCAN_THROTTLE_ISOLATED);

                 /* We are about to die and free our memory. Return now. */
                 if (fatal_signal_pending(current)) {
                         *fatal = true;
                         return stalled;
                 }
         }

         return stalled;
}


  reply	other threads:[~2026-08-19  2:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 12:48 [PATCH mm-unstable v3 0/2] mm/vmscan: fix NR_ISOLATED accounting and throttling for MGLRU Hui Zhu
2026-08-18 12:48 ` [PATCH mm-unstable v3 1/2] mm/vmscan: fix missing NR_ISOLATED counter update in MGLRU reclaim path Hui Zhu
2026-08-18 21:33   ` Barry Song
2026-08-18 12:48 ` [PATCH mm-unstable v3 2/2] mm/vmscan: apply too_many_isolated() throttling to MGLRU eviction Hui Zhu
2026-08-18 22:06   ` Barry Song
2026-08-19  2:15     ` Baolin Wang [this message]
2026-08-19  9:29       ` Kairui Song
2026-08-19 22:01         ` Barry Song

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=39871dbf-25e3-4518-9942-a733dbb6acf5@linux.alibaba.com \
    --to=baolin.wang@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hui.zhu@linux.dev \
    --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=weixugc@google.com \
    --cc=yuanchu@google.com \
    --cc=zhuhui@kylinos.cn \
    /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®