mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 020-v6.3-29-mm-multi-gen-LRU-avoid-futile-retries.patch
1 From cc67f962cc53f6e1dfa92eb85b7b26fe83a3c66f Mon Sep 17 00:00:00 2001
2 From: Yu Zhao <yuzhao@google.com>
3 Date: Mon, 13 Feb 2023 00:53:22 -0700
4 Subject: [PATCH 29/29] mm: multi-gen LRU: avoid futile retries
5
6 Recall that the per-node memcg LRU has two generations and they alternate
7 when the last memcg (of a given node) is moved from one to the other.
8 Each generation is also sharded into multiple bins to improve scalability.
9 A reclaimer starts with a random bin (in the old generation) and, if it
10 fails, it will retry, i.e., to try the rest of the bins.
11
12 If a reclaimer fails with the last memcg, it should move this memcg to the
13 young generation first, which causes the generations to alternate, and
14 then retry. Otherwise, the retries will be futile because all other bins
15 are empty.
16
17 Link: https://lkml.kernel.org/r/20230213075322.1416966-1-yuzhao@google.com
18 Fixes: e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists")
19 Signed-off-by: Yu Zhao <yuzhao@google.com>
20 Reported-by: T.J. Mercier <tjmercier@google.com>
21 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
22 ---
23 mm/vmscan.c | 25 +++++++++++++++----------
24 1 file changed, 15 insertions(+), 10 deletions(-)
25
26 --- a/mm/vmscan.c
27 +++ b/mm/vmscan.c
28 @@ -4934,18 +4934,20 @@ static int shrink_one(struct lruvec *lru
29
30 static void shrink_many(struct pglist_data *pgdat, struct scan_control *sc)
31 {
32 + int op;
33 int gen;
34 int bin;
35 int first_bin;
36 struct lruvec *lruvec;
37 struct lru_gen_page *lrugen;
38 + struct mem_cgroup *memcg;
39 const struct hlist_nulls_node *pos;
40 - int op = 0;
41 - struct mem_cgroup *memcg = NULL;
42 unsigned long nr_to_reclaim = get_nr_to_reclaim(sc);
43
44 bin = first_bin = prandom_u32_max(MEMCG_NR_BINS);
45 restart:
46 + op = 0;
47 + memcg = NULL;
48 gen = get_memcg_gen(READ_ONCE(pgdat->memcg_lru.seq));
49
50 rcu_read_lock();
51 @@ -4969,14 +4971,22 @@ restart:
52
53 op = shrink_one(lruvec, sc);
54
55 - if (sc->nr_reclaimed >= nr_to_reclaim)
56 - goto success;
57 -
58 rcu_read_lock();
59 +
60 + if (sc->nr_reclaimed >= nr_to_reclaim)
61 + break;
62 }
63
64 rcu_read_unlock();
65
66 + if (op)
67 + lru_gen_rotate_memcg(lruvec, op);
68 +
69 + mem_cgroup_put(memcg);
70 +
71 + if (sc->nr_reclaimed >= nr_to_reclaim)
72 + return;
73 +
74 /* restart if raced with lru_gen_rotate_memcg() */
75 if (gen != get_nulls_value(pos))
76 goto restart;
77 @@ -4985,11 +4995,6 @@ restart:
78 bin = get_memcg_bin(bin + 1);
79 if (bin != first_bin)
80 goto restart;
81 -success:
82 - if (op)
83 - lru_gen_rotate_memcg(lruvec, op);
84 -
85 - mem_cgroup_put(memcg);
86 }
87
88 static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)