From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Barry Song <baohua@kernel.org>
Cc: akpm@linux-foundation.org, kasong@tencent.com,
qi.zheng@linux.dev, shakeel.butt@linux.dev,
axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com,
hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org,
ljs@kernel.org, ridong.chen@linux.dev, hebaoquan@kylinos.cn,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: mglru: clear the reference counter for rejected folios
Date: Mon, 7 Sep 2026 13:53:11 +0800 [thread overview]
Message-ID: <b4c84ef4-0c2f-48d3-9eeb-6f39ed297be5@linux.alibaba.com> (raw)
In-Reply-To: <CAGsJ_4xxZWomhtUmdz9f1x5wdeoTSTRfEudzufdBs_ykKM1HBA@mail.gmail.com>
On 9/7/26 12:28 PM, Barry Song wrote:
> On Mon, Sep 7, 2026 at 11:25 AM Baolin Wang
> <baolin.wang@linux.alibaba.com> wrote:
>>
>> As per the comment on LRU_REFS_FLAGS, when accessed folios are promoted to
>> a new generation, LRU_REFS_FLAGS should be cleared so that the reference
>> counter can start over.
>>
>> For folios rejected by shrink_folio_list(), we clear LRU_REFS_FLAGS and
>> set the PG_active flag if the rejected folio is planned to be put back to
>> the oldest generation. That's fine.
>
> I find the description a bit confusing. Yes, according to
> `lru_gen_folio_seq()`, the folio would be put back into the oldest
> generation. That's why we set the active bit to prevent this from
> happening. So there is no case where the folio is intentionally put
> back into the oldest generation.
How about?
"
For folios rejected by shrink_folio_list(), we clear LRU_REFS_FLAGS and
set the PG_active flag when lru_gen_folio_seq() would place them in the
oldest generation.
"
>> But for those that are not put back to the oldest generation (which can
>> be treated as a promotion), we do not clear LRU_REFS_FLAGS, which can
>> violate the promotion mechanism. This means the rejected folio enters the
>> new generation with stale, inflated tier bits, which can inflate reference
>> counts and distort eviction statistics for these rejected folios.
>
> Maybe simply say that folios for which lru_gen_folio_seq()
> returns something other than min_seq?
OK.
>> Fix this by clearing LRU_REFS_FLAGS for rejected folios, and also do some
>> measurement. On my 32-core Arm machine, with the memcg limit set to 3G,
>> running 'make -j32' to build the kernel showed a small improvement in sys
>> time when using either a zram or NVMe swap device (averaged over 2 runs with
>> no significant variance).
>>
>> zram swap:
>> w/o patch w/ patch
>> sys time: 1666.5s 1589.5s
>>
>> NVMe swap:
>> w/o patch w/patch
>> sys time: 760s 741.5s
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> ---
>> mm/vmscan.c | 7 ++++---
>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 40d3f1b48a74..42c0a09938ab 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -5021,10 +5021,11 @@ static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
>> }
>>
>> /* don't add rejected folios to the oldest generation */
>> - if (lru_gen_folio_seq(lruvec, folio, false) == min_seq[type]) {
>> - folio_set_lru_refs(folio, 0);
>> + if (lru_gen_folio_seq(lruvec, folio, false) == min_seq[type])
>> folio_set_active(folio);
>> - }
>> +
>> + /* See the comments on LRU_REFS_FLAGS */
>> + folio_set_lru_refs(folio, 0);
>> }
>
> The code change makes sense to me if we keep aging and always reclaim
> only the oldest generation. However, if we go further in
> `scan_folios()`—for example, continuing to scan after we have fewer
> than two generations left—we might not be in that case anymore.
I may not fully understand your concern. If there is only one generation
(fewer than two generations), we should aging instead of reclaim.
But my point is that regardless, if promotion happens, we should clear
the reference counter. Otherwise, as I mentioned, it will distort
eviction statistics.
> So far, the code looks correct to me.
>
> BTW, Baolin, I wonder if you could find some time to test this
> change on your arm64 system:
> https://lore.kernel.org/linux-mm/20260901220430.79810-1-baohua@kernel.org/
>
> It might have addressed one of your previous, similar concerns here.
> On my x86 machine, I find that the change further reduces the
> sys time from 3 minutes 40 seconds to 3 minutes 30 seconds.
>
> Meanwhile, I will also run your patch on my x86 machine.
Sigh. I missed this thread. Yes, I also raised a similar issue before
[1] and this is still my next step. I'll find some time to check this
thread. Thanks for reminding me.
[1]
https://lore.kernel.org/all/eb395442-0aad-428a-a5ac-9072d2d89060@linux.alibaba.com/
next prev parent reply other threads:[~2026-09-07 5:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 3:25 Baolin Wang
2026-09-07 4:28 ` Barry Song
2026-09-07 5:53 ` Baolin Wang [this message]
2026-09-07 4:57 ` Kairui Song
2026-09-07 6:27 ` Baolin Wang
2026-09-08 2:30 ` Baoquan He
2026-09-08 2:34 ` Barry Song
2026-09-08 3:03 ` Baolin Wang
2026-09-08 4:01 ` Baolin Wang
2026-09-08 6:59 ` Baoquan He
2026-09-08 7:53 ` Baolin Wang
2026-09-08 8:23 ` Baoquan He
2026-09-08 9:39 ` Baolin Wang
2026-09-08 10:29 ` Baoquan He
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=b4c84ef4-0c2f-48d3-9eeb-6f39ed297be5@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=hebaoquan@kylinos.cn \
--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=ridong.chen@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=weixugc@google.com \
--cc=yuanchu@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®