From: Ridong Chen <ridong.chen@linux.dev>
To: Barry Song <baohua@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Kairui Song <kasong@tencent.com>,
David Hildenbrand <david@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
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>,
Baoquan He <baoquan.he@linux.dev>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
Yu Zhao <yuzhao@google.com>,
"open list:MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU)"
<linux-mm@kvack.org>, Ridong Chen <chenridong@xiaomi.com>
Subject: Re: [PATCH v2 2/2] mm/mglru: deactivate anon folios into the oldest generation
Date: Tue, 24 Nov 2026 09:50:21 +0800 [thread overview]
Message-ID: <f65aa688-d236-4b4f-87bf-c12e15991aef@linux.dev> (raw)
In-Reply-To: <CAGsJ_4xsz0TdYUTtS2Pfr6PvfAs1PvDxzmPGU5wgBgjGVrB1EA@mail.gmail.com>
On 11/24/2026 9:18 AM, Barry Song wrote:
> On Thu, Nov 19, 2026 at 9:48 PM Ridong Chen <ridong.chen@linux.dev> wrote:
>>
> [...]
>>
>> diff --git a/mm/folio.c b/mm/folio.c
>> index 7a3394e7c5dc..1bfd746d7f07 100644
>> --- a/mm/folio.c
>> +++ b/mm/folio.c
>> @@ -423,6 +423,14 @@ static bool lru_gen_clear_refs(struct folio *folio)
>> return gen == lru_gen_from_seq(seq);
>> }
>>
>> +/* add the folio to the head of the oldest generation */
>> +static bool lru_gen_add_deactivated_folio(struct lruvec *lruvec, struct folio *folio)
>> +{
>> + int type = folio_is_file_lru(folio);
>> +
>> + return lru_gen_add_folio(lruvec, folio, -1UL, lruvec->lrugen.min_seq[type], false);
>> +}
>> +
>> #else /* !CONFIG_LRU_GEN */
>>
>> static void lru_gen_inc_refs(struct folio *folio)
>> @@ -434,6 +442,11 @@ static bool lru_gen_clear_refs(struct folio *folio)
>> return false;
>> }
>>
>> +static bool lru_gen_add_deactivated_folio(struct lruvec *lruvec, struct folio *folio)
>> +{
>> + return false;
>> +}
>> +
>> #endif /* CONFIG_LRU_GEN */
>>
>> /**
>> @@ -609,7 +622,8 @@ static void lru_deactivate(struct lruvec *lruvec, struct folio *folio)
>> lruvec_del_folio(lruvec, folio);
>> folio_clear_active(folio);
>> folio_clear_referenced(folio);
>> - lruvec_add_folio(lruvec, folio);
>> + if (!lru_gen_add_deactivated_folio(lruvec, folio))
>> + lruvec_add_folio(lruvec, folio);
>
> Since we're already introducing a new wrapper,
> lru_gen_add_deactivated_folio(), could we make it more readable
> and self-contained by handling the fallback within it?
>
> This way, lru_deactivate() only needs to care about deactivating the
> folio, not whether we are using MGLRU or the classic LRU, or whether
> MGLRU is enabled at compile time or runtime.
>
> index 1bfd746d7f07..5a6092e64fe1 100644
> --- a/mm/folio.c
> +++ b/mm/folio.c
> @@ -424,11 +424,13 @@ static bool lru_gen_clear_refs(struct folio *folio)
> @@ -424,11 +424,13 @@ static bool lru_gen_clear_refs(struct folio *folio)
> }
>
> /* add the folio to the head of the oldest generation */
> -static bool lru_gen_add_deactivated_folio(struct lruvec *lruvec,
> struct folio *folio)
> +static void lruvec_add_deactivated_folio(struct lruvec *lruvec,
> struct folio *folio)
> {
> int type = folio_is_file_lru(folio);
> + unsigned long seq = lruvec->lrugen.min_seq[type];
>
> - return lru_gen_add_folio(lruvec, folio, -1UL,
> lruvec->lrugen.min_seq[type], false);
> + if (!lru_gen_add_folio(lruvec, folio, MIN_SEQ_UNBOUNDED, seq, false))
> + lruvec_add_folio(lruvec, folio);
> }
>
> #else /* !CONFIG_LRU_GEN */
> @@ -442,9 +444,9 @@ static bool lru_gen_clear_refs(struct folio *folio)
> return false;
> }
>
> -static bool lru_gen_add_deactivated_folio(struct lruvec *lruvec,
> struct folio *folio)
> +static void lruvec_add_deactivated_folio(struct lruvec *lruvec,
> struct folio *folio)
> {
> - return false;
> + lruvec_add_folio(lruvec, folio);
> }
>
> #endif /* CONFIG_LRU_GEN */
> @@ -622,8 +624,7 @@ static void lru_deactivate(struct lruvec *lruvec,
> struct folio *folio)
> lruvec_del_folio(lruvec, folio);
> folio_clear_active(folio);
> folio_clear_referenced(folio);
> - if (!lru_gen_add_deactivated_folio(lruvec, folio))
> - lruvec_add_folio(lruvec, folio);
> + lruvec_add_deactivated_folio(lruvec, folio);
>
> __count_vm_events(PGDEACTIVATE, nr_pages);
> count_memcg_events(lruvec_memcg(lruvec), PGDEACTIVATE, nr_pages);
>
>
Makes sense, thanks. I'll take your version in v3.
>>
>> __count_vm_events(PGDEACTIVATE, nr_pages);
>> count_memcg_events(lruvec_memcg(lruvec), PGDEACTIVATE, nr_pages);
>> --
>> 2.34.1
>>
>
> Thanks,
> Barry
--
Best regards
Ridong
prev parent reply other threads:[~2026-11-24 1:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 13:47 [PATCH v2 0/2] mm/mglru: deactivate anon folios into the oldest generation Ridong Chen
2026-11-19 13:47 ` [PATCH v2 1/2] mm/mglru: pass a seq range to lru_gen_add_folio() Ridong Chen
2026-11-24 0:43 ` Barry Song
2026-11-24 1:48 ` Ridong Chen
2026-11-24 1:54 ` Barry Song
2026-11-19 13:47 ` [PATCH v2 2/2] mm/mglru: deactivate anon folios into the oldest generation Ridong Chen
2026-11-24 1:18 ` Barry Song
2026-11-24 1:50 ` Ridong Chen [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=f65aa688-d236-4b4f-87bf-c12e15991aef@linux.dev \
--to=ridong.chen@linux.dev \
--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=chenridong@xiaomi.com \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=qi.zheng@linux.dev \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=vbabka@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.