1 From 620b0ee94455e48d124414cd06d8a53f69fb6453 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 09/19] UPSTREAM: mm: multi-gen LRU: avoid futile retries
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.
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
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>
23 (cherry picked from commit 9f550d78b40da21b4da515db4c37d8d7b12aa1a6)
24 Change-Id: Ie92535676b005ec9e7987632b742fdde8d54436f
25 Signed-off-by: T.J. Mercier <tjmercier@google.com>
27 mm/vmscan.c | 25 +++++++++++++++----------
28 1 file changed, 15 insertions(+), 10 deletions(-)
32 @@ -5218,18 +5218,20 @@ static int shrink_one(struct lruvec *lru
34 static void shrink_many(struct pglist_data *pgdat, struct scan_control *sc)
40 struct lruvec *lruvec;
41 struct lru_gen_folio *lrugen;
42 + struct mem_cgroup *memcg;
43 const struct hlist_nulls_node *pos;
45 - struct mem_cgroup *memcg = NULL;
46 unsigned long nr_to_reclaim = get_nr_to_reclaim(sc);
48 bin = first_bin = get_random_u32_below(MEMCG_NR_BINS);
52 gen = get_memcg_gen(READ_ONCE(pgdat->memcg_lru.seq));
55 @@ -5253,14 +5255,22 @@ restart:
57 op = shrink_one(lruvec, sc);
59 - if (sc->nr_reclaimed >= nr_to_reclaim)
64 + if (sc->nr_reclaimed >= nr_to_reclaim)
71 + lru_gen_rotate_memcg(lruvec, op);
73 + mem_cgroup_put(memcg);
75 + if (sc->nr_reclaimed >= nr_to_reclaim)
78 /* restart if raced with lru_gen_rotate_memcg() */
79 if (gen != get_nulls_value(pos))
81 @@ -5269,11 +5279,6 @@ restart:
82 bin = get_memcg_bin(bin + 1);
87 - lru_gen_rotate_memcg(lruvec, op);
89 - mem_cgroup_put(memcg);
92 static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)