Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/mglru: stop try_to_inc_min_seq() if min_seq[type] has not increased

In try_to_inc_min_seq(), if min_seq[type] has not increased. In other
words, min_seq[type] == lrugen->min_seq[type]. Then we should return
directly to avoid unnecessary overhead later.

Corollary: If min_seq[type] of both anonymous and file is not increased,
try_to_inc_min_seq() will fail.

Proof:
It is known that min_seq[type] has not increased, that is, min_seq[type]
is equal to lrugen->min_seq[type], then the following:

case 1: min_seq[type] has not been reassigned and changed before
judgment min_seq[type] <= lrugen->min_seq[type].
Then the subsequent min_seq[type] <= lrugen->min_seq[type] judgment
will always be true.

case 2: min_seq[type] is reassigned to seq, before judgment
min_seq[type] <= lrugen->min_seq[type].
Then at least the condition of min_seq[type] > seq must be met
before min_seq[type] will be reassigned to seq.
That is to say, before the reassignment, lrugen->min_seq[type] > seq
is met, and then min_seq[type] = seq.
Then the following min_seq[type](seq) <= lrugen->min_seq[type] judgment
is always true.

Therefore, in try_to_inc_min_seq(), If min_seq[type] of both anonymous
and file is not increased, we can return false directly to avoid
unnecessary overhead.

Link: https://lkml.kernel.org/r/20250703023946.65315-1-jiahao.kernel@gmail.com
Signed-off-by: Hao Jia <jiahao1@lixiang.com>
Suggested-by: Yuanchu Xie <yuanchu@google.com>
Reviewed-by: Axel Rasmussen <axelrasmussen@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kinsey Ho <kinseyho@google.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Hao Jia and committed by
Andrew Morton
526660b9 9989db9f

+10
+10
mm/vmscan.c
··· 3921 3921 { 3922 3922 int gen, type, zone; 3923 3923 bool success = false; 3924 + bool seq_inc_flag = false; 3924 3925 struct lru_gen_folio *lrugen = &lruvec->lrugen; 3925 3926 DEFINE_MIN_SEQ(lruvec); 3926 3927 ··· 3938 3937 } 3939 3938 3940 3939 min_seq[type]++; 3940 + seq_inc_flag = true; 3941 3941 } 3942 3942 next: 3943 3943 ; 3944 3944 } 3945 + 3946 + /* 3947 + * If min_seq[type] of both anonymous and file is not increased, 3948 + * we can directly return false to avoid unnecessary checking 3949 + * overhead later. 3950 + */ 3951 + if (!seq_inc_flag) 3952 + return success; 3945 3953 3946 3954 /* see the comment on lru_gen_folio */ 3947 3955 if (swappiness && swappiness <= MAX_SWAPPINESS) {