1 From eca3858631e0cbad2ca6e40f788892749428e4cb Mon Sep 17 00:00:00 2001
2 From: Yu Zhao <yuzhao@google.com>
3 Date: Wed, 21 Dec 2022 21:19:03 -0700
4 Subject: [PATCH 05/19] UPSTREAM: mm: multi-gen LRU: shuffle should_run_aging()
6 Move should_run_aging() next to its only caller left.
8 Link: https://lkml.kernel.org/r/20221222041905.2431096-6-yuzhao@google.com
9 Cc: Johannes Weiner <hannes@cmpxchg.org>
10 Cc: Jonathan Corbet <corbet@lwn.net>
11 Cc: Michael Larabel <Michael@MichaelLarabel.com>
12 Cc: Michal Hocko <mhocko@kernel.org>
13 Cc: Mike Rapoport <rppt@kernel.org>
14 Cc: Roman Gushchin <roman.gushchin@linux.dev>
15 Cc: Suren Baghdasaryan <surenb@google.com>
16 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
18 (cherry picked from commit 77d4459a4a1a472b7309e475f962dda87d950abd)
19 Signed-off-by: T.J. Mercier <tjmercier@google.com>
20 Change-Id: I3b0383fe16b93a783b4d8c0b3a0b325160392576
21 Signed-off-by: Yu Zhao <yuzhao@google.com>
22 Signed-off-by: T.J. Mercier <tjmercier@google.com>
24 mm/vmscan.c | 124 ++++++++++++++++++++++++++--------------------------
25 1 file changed, 62 insertions(+), 62 deletions(-)
29 @@ -4454,68 +4454,6 @@ done:
33 -static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq,
34 - struct scan_control *sc, bool can_swap, unsigned long *nr_to_scan)
36 - int gen, type, zone;
37 - unsigned long old = 0;
38 - unsigned long young = 0;
39 - unsigned long total = 0;
40 - struct lru_gen_folio *lrugen = &lruvec->lrugen;
41 - struct mem_cgroup *memcg = lruvec_memcg(lruvec);
42 - DEFINE_MIN_SEQ(lruvec);
44 - /* whether this lruvec is completely out of cold folios */
45 - if (min_seq[!can_swap] + MIN_NR_GENS > max_seq) {
50 - for (type = !can_swap; type < ANON_AND_FILE; type++) {
53 - for (seq = min_seq[type]; seq <= max_seq; seq++) {
54 - unsigned long size = 0;
56 - gen = lru_gen_from_seq(seq);
58 - for (zone = 0; zone < MAX_NR_ZONES; zone++)
59 - size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
64 - else if (seq + MIN_NR_GENS == max_seq)
69 - /* try to scrape all its memory if this memcg was deleted */
70 - *nr_to_scan = mem_cgroup_online(memcg) ? (total >> sc->priority) : total;
73 - * The aging tries to be lazy to reduce the overhead, while the eviction
74 - * stalls when the number of generations reaches MIN_NR_GENS. Hence, the
75 - * ideal number of generations is MIN_NR_GENS+1.
77 - if (min_seq[!can_swap] + MIN_NR_GENS < max_seq)
81 - * It's also ideal to spread pages out evenly, i.e., 1/(MIN_NR_GENS+1)
82 - * of the total number of pages for each generation. A reasonable range
83 - * for this average portion is [1/MIN_NR_GENS, 1/(MIN_NR_GENS+2)]. The
84 - * aging cares about the upper bound of hot pages, while the eviction
85 - * cares about the lower bound of cold pages.
87 - if (young * MIN_NR_GENS > total)
89 - if (old * (MIN_NR_GENS + 2) < total)
95 static bool lruvec_is_sizable(struct lruvec *lruvec, struct scan_control *sc)
98 @@ -5099,6 +5037,68 @@ retry:
102 +static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq,
103 + struct scan_control *sc, bool can_swap, unsigned long *nr_to_scan)
105 + int gen, type, zone;
106 + unsigned long old = 0;
107 + unsigned long young = 0;
108 + unsigned long total = 0;
109 + struct lru_gen_folio *lrugen = &lruvec->lrugen;
110 + struct mem_cgroup *memcg = lruvec_memcg(lruvec);
111 + DEFINE_MIN_SEQ(lruvec);
113 + /* whether this lruvec is completely out of cold folios */
114 + if (min_seq[!can_swap] + MIN_NR_GENS > max_seq) {
119 + for (type = !can_swap; type < ANON_AND_FILE; type++) {
122 + for (seq = min_seq[type]; seq <= max_seq; seq++) {
123 + unsigned long size = 0;
125 + gen = lru_gen_from_seq(seq);
127 + for (zone = 0; zone < MAX_NR_ZONES; zone++)
128 + size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
131 + if (seq == max_seq)
133 + else if (seq + MIN_NR_GENS == max_seq)
138 + /* try to scrape all its memory if this memcg was deleted */
139 + *nr_to_scan = mem_cgroup_online(memcg) ? (total >> sc->priority) : total;
142 + * The aging tries to be lazy to reduce the overhead, while the eviction
143 + * stalls when the number of generations reaches MIN_NR_GENS. Hence, the
144 + * ideal number of generations is MIN_NR_GENS+1.
146 + if (min_seq[!can_swap] + MIN_NR_GENS < max_seq)
150 + * It's also ideal to spread pages out evenly, i.e., 1/(MIN_NR_GENS+1)
151 + * of the total number of pages for each generation. A reasonable range
152 + * for this average portion is [1/MIN_NR_GENS, 1/(MIN_NR_GENS+2)]. The
153 + * aging cares about the upper bound of hot pages, while the eviction
154 + * cares about the lower bound of cold pages.
156 + if (young * MIN_NR_GENS > total)
158 + if (old * (MIN_NR_GENS + 2) < total)
165 * For future optimizations:
166 * 1. Defer try_to_inc_max_seq() to workqueues to reduce latency for memcg