[PATCH] mm/mglru: restore accidentally removed seq < max_seq check

Barry Song (Xiaomi) posted 1 patch 1 week, 2 days ago
mm/vmscan.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] mm/mglru: restore accidentally removed seq < max_seq check
Posted by Barry Song (Xiaomi) 1 week, 2 days ago
Since commit 798c0330c2ca ("mm/mglru: rework aging feedback"),
the following sanity check was accidentally removed:
       if (seq < max_seq)
               return 0;

That means we can perform aging for any value less than or equal to
max_gen_nr.

This has been inconsistent with
Documentation/admin-guide/mm/multigen_lru.rst, which states:

 Users can write the following command to ``lru_gen`` to create a new
 generation ``max_gen_nr+1``:

     ``+ memcg_id node_id max_gen_nr [can_swap [force_scan]]``

The correct semantics are that writing a value smaller than
max_gen_nr should return 0, since the requested generation already
exists.

Fixes: 798c0330c2ca ("mm/mglru: rework aging feedback")
Reported-by: Chuanhua Han <hanchuanhua802@gmail.com>
Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
---
 mm/vmscan.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 5354eb8d3a07..18c4d3595749 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -5827,6 +5827,9 @@ static int run_aging(struct lruvec *lruvec, unsigned long seq,
 {
 	DEFINE_MAX_SEQ(lruvec);
 
+	if (seq < max_seq)
+		return 0;
+
 	if (seq > max_seq)
 		return -EINVAL;
 
-- 
2.39.3 (Apple Git-146)
Re: [PATCH] mm/mglru: restore accidentally removed seq < max_seq check
Posted by Kairui Song 1 week, 1 day ago
On Tue, Sep 15, 2026 at 6:51 PM Barry Song (Xiaomi) <baohua@kernel.org> wrote:
>
> Since commit 798c0330c2ca ("mm/mglru: rework aging feedback"),
> the following sanity check was accidentally removed:
>        if (seq < max_seq)
>                return 0;
>
> That means we can perform aging for any value less than or equal to
> max_gen_nr.
>
> This has been inconsistent with
> Documentation/admin-guide/mm/multigen_lru.rst, which states:
>
>  Users can write the following command to ``lru_gen`` to create a new
>  generation ``max_gen_nr+1``:
>
>      ``+ memcg_id node_id max_gen_nr [can_swap [force_scan]]``
>
> The correct semantics are that writing a value smaller than
> max_gen_nr should return 0, since the requested generation already
> exists.
>
> Fixes: 798c0330c2ca ("mm/mglru: rework aging feedback")
> Reported-by: Chuanhua Han <hanchuanhua802@gmail.com>
> Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
> ---
>  mm/vmscan.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 5354eb8d3a07..18c4d3595749 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -5827,6 +5827,9 @@ static int run_aging(struct lruvec *lruvec, unsigned long seq,
>  {
>         DEFINE_MAX_SEQ(lruvec);
>
> +       if (seq < max_seq)
> +               return 0;
> +
>         if (seq > max_seq)
>                 return -EINVAL;

Reviewed-by: Kairui Song <kasong@tencent.com>
Re: [PATCH] mm/mglru: restore accidentally removed seq < max_seq check
Posted by Baolin Wang 1 week, 2 days ago

On 9/15/26 6:15 PM, Barry Song (Xiaomi) wrote:
> Since commit 798c0330c2ca ("mm/mglru: rework aging feedback"),
> the following sanity check was accidentally removed:
>         if (seq < max_seq)
>                 return 0;
> 
> That means we can perform aging for any value less than or equal to
> max_gen_nr.
> 
> This has been inconsistent with
> Documentation/admin-guide/mm/multigen_lru.rst, which states:
> 
>   Users can write the following command to ``lru_gen`` to create a new
>   generation ``max_gen_nr+1``:
> 
>       ``+ memcg_id node_id max_gen_nr [can_swap [force_scan]]``
> 
> The correct semantics are that writing a value smaller than
> max_gen_nr should return 0, since the requested generation already
> exists.
> 
> Fixes: 798c0330c2ca ("mm/mglru: rework aging feedback")
> Reported-by: Chuanhua Han <hanchuanhua802@gmail.com>
> Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
> ---

LGTM.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>