857072296bfb836929cf72e039cba54e57350408
[openwrt/staging/blogic.git] /
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()
5
6 Move should_run_aging() next to its only caller left.
7
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>
17 Bug: 274865848
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>
23 ---
24 mm/vmscan.c | 124 ++++++++++++++++++++++++++--------------------------
25 1 file changed, 62 insertions(+), 62 deletions(-)
26
27 --- a/mm/vmscan.c
28 +++ b/mm/vmscan.c
29 @@ -4454,68 +4454,6 @@ done:
30 return true;
31 }
32
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)
35 -{
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);
43 -
44 - /* whether this lruvec is completely out of cold folios */
45 - if (min_seq[!can_swap] + MIN_NR_GENS > max_seq) {
46 - *nr_to_scan = 0;
47 - return true;
48 - }
49 -
50 - for (type = !can_swap; type < ANON_AND_FILE; type++) {
51 - unsigned long seq;
52 -
53 - for (seq = min_seq[type]; seq <= max_seq; seq++) {
54 - unsigned long size = 0;
55 -
56 - gen = lru_gen_from_seq(seq);
57 -
58 - for (zone = 0; zone < MAX_NR_ZONES; zone++)
59 - size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
60 -
61 - total += size;
62 - if (seq == max_seq)
63 - young += size;
64 - else if (seq + MIN_NR_GENS == max_seq)
65 - old += size;
66 - }
67 - }
68 -
69 - /* try to scrape all its memory if this memcg was deleted */
70 - *nr_to_scan = mem_cgroup_online(memcg) ? (total >> sc->priority) : total;
71 -
72 - /*
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.
76 - */
77 - if (min_seq[!can_swap] + MIN_NR_GENS < max_seq)
78 - return false;
79 -
80 - /*
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.
86 - */
87 - if (young * MIN_NR_GENS > total)
88 - return true;
89 - if (old * (MIN_NR_GENS + 2) < total)
90 - return true;
91 -
92 - return false;
93 -}
94 -
95 static bool lruvec_is_sizable(struct lruvec *lruvec, struct scan_control *sc)
96 {
97 int gen, type, zone;
98 @@ -5099,6 +5037,68 @@ retry:
99 return scanned;
100 }
101
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)
104 +{
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);
112 +
113 + /* whether this lruvec is completely out of cold folios */
114 + if (min_seq[!can_swap] + MIN_NR_GENS > max_seq) {
115 + *nr_to_scan = 0;
116 + return true;
117 + }
118 +
119 + for (type = !can_swap; type < ANON_AND_FILE; type++) {
120 + unsigned long seq;
121 +
122 + for (seq = min_seq[type]; seq <= max_seq; seq++) {
123 + unsigned long size = 0;
124 +
125 + gen = lru_gen_from_seq(seq);
126 +
127 + for (zone = 0; zone < MAX_NR_ZONES; zone++)
128 + size += max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L);
129 +
130 + total += size;
131 + if (seq == max_seq)
132 + young += size;
133 + else if (seq + MIN_NR_GENS == max_seq)
134 + old += size;
135 + }
136 + }
137 +
138 + /* try to scrape all its memory if this memcg was deleted */
139 + *nr_to_scan = mem_cgroup_online(memcg) ? (total >> sc->priority) : total;
140 +
141 + /*
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.
145 + */
146 + if (min_seq[!can_swap] + MIN_NR_GENS < max_seq)
147 + return false;
148 +
149 + /*
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.
155 + */
156 + if (young * MIN_NR_GENS > total)
157 + return true;
158 + if (old * (MIN_NR_GENS + 2) < total)
159 + return true;
160 +
161 + return false;
162 +}
163 +
164 /*
165 * For future optimizations:
166 * 1. Defer try_to_inc_max_seq() to workqueues to reduce latency for memcg