]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
8bc5613e81a112f71a3ddb67959021a41eb2f441
[thirdparty/kernel/stable-queue.git] /
1 From 1a501907bbea8e6ebb0b16cf6db9e9cbf1d2c813 Mon Sep 17 00:00:00 2001
2 From: Mel Gorman <mgorman@suse.de>
3 Date: Wed, 4 Jun 2014 16:10:49 -0700
4 Subject: mm: vmscan: use proportional scanning during direct reclaim and full scan at DEF_PRIORITY
5
6 From: Mel Gorman <mgorman@suse.de>
7
8 commit 1a501907bbea8e6ebb0b16cf6db9e9cbf1d2c813 upstream.
9
10 Commit "mm: vmscan: obey proportional scanning requirements for kswapd"
11 ensured that file/anon lists were scanned proportionally for reclaim from
12 kswapd but ignored it for direct reclaim. The intent was to minimse
13 direct reclaim latency but Yuanhan Liu pointer out that it substitutes one
14 long stall for many small stalls and distorts aging for normal workloads
15 like streaming readers/writers. Hugh Dickins pointed out that a
16 side-effect of the same commit was that when one LRU list dropped to zero
17 that the entirety of the other list was shrunk leading to excessive
18 reclaim in memcgs. This patch scans the file/anon lists proportionally
19 for direct reclaim to similarly age page whether reclaimed by kswapd or
20 direct reclaim but takes care to abort reclaim if one LRU drops to zero
21 after reclaiming the requested number of pages.
22
23 Based on ext4 and using the Intel VM scalability test
24
25 3.15.0-rc5 3.15.0-rc5
26 shrinker proportion
27 Unit lru-file-readonce elapsed 5.3500 ( 0.00%) 5.4200 ( -1.31%)
28 Unit lru-file-readonce time_range 0.2700 ( 0.00%) 0.1400 ( 48.15%)
29 Unit lru-file-readonce time_stddv 0.1148 ( 0.00%) 0.0536 ( 53.33%)
30 Unit lru-file-readtwice elapsed 8.1700 ( 0.00%) 8.1700 ( 0.00%)
31 Unit lru-file-readtwice time_range 0.4300 ( 0.00%) 0.2300 ( 46.51%)
32 Unit lru-file-readtwice time_stddv 0.1650 ( 0.00%) 0.0971 ( 41.16%)
33
34 The test cases are running multiple dd instances reading sparse files. The results are within
35 the noise for the small test machine. The impact of the patch is more noticable from the vmstats
36
37 3.15.0-rc5 3.15.0-rc5
38 shrinker proportion
39 Minor Faults 35154 36784
40 Major Faults 611 1305
41 Swap Ins 394 1651
42 Swap Outs 4394 5891
43 Allocation stalls 118616 44781
44 Direct pages scanned 4935171 4602313
45 Kswapd pages scanned 15921292 16258483
46 Kswapd pages reclaimed 15913301 16248305
47 Direct pages reclaimed 4933368 4601133
48 Kswapd efficiency 99% 99%
49 Kswapd velocity 670088.047 682555.961
50 Direct efficiency 99% 99%
51 Direct velocity 207709.217 193212.133
52 Percentage direct scans 23% 22%
53 Page writes by reclaim 4858.000 6232.000
54 Page writes file 464 341
55 Page writes anon 4394 5891
56
57 Note that there are fewer allocation stalls even though the amount
58 of direct reclaim scanning is very approximately the same.
59
60 Signed-off-by: Mel Gorman <mgorman@suse.de>
61 Cc: Johannes Weiner <hannes@cmpxchg.org>
62 Cc: Hugh Dickins <hughd@google.com>
63 Cc: Tim Chen <tim.c.chen@linux.intel.com>
64 Cc: Dave Chinner <david@fromorbit.com>
65 Tested-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
66 Cc: Bob Liu <bob.liu@oracle.com>
67 Cc: Jan Kara <jack@suse.cz>
68 Cc: Rik van Riel <riel@redhat.com>
69 Cc: Al Viro <viro@zeniv.linux.org.uk>
70 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
71 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
72 Signed-off-by: Mel Gorman <mgorman@suse.de>
73 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
74
75 ---
76 mm/vmscan.c | 36 +++++++++++++++++++++++++-----------
77 1 file changed, 25 insertions(+), 11 deletions(-)
78
79 --- a/mm/vmscan.c
80 +++ b/mm/vmscan.c
81 @@ -2018,13 +2018,27 @@ static void shrink_lruvec(struct lruvec
82 unsigned long nr_reclaimed = 0;
83 unsigned long nr_to_reclaim = sc->nr_to_reclaim;
84 struct blk_plug plug;
85 - bool scan_adjusted = false;
86 + bool scan_adjusted;
87
88 get_scan_count(lruvec, sc, nr);
89
90 /* Record the original scan target for proportional adjustments later */
91 memcpy(targets, nr, sizeof(nr));
92
93 + /*
94 + * Global reclaiming within direct reclaim at DEF_PRIORITY is a normal
95 + * event that can occur when there is little memory pressure e.g.
96 + * multiple streaming readers/writers. Hence, we do not abort scanning
97 + * when the requested number of pages are reclaimed when scanning at
98 + * DEF_PRIORITY on the assumption that the fact we are direct
99 + * reclaiming implies that kswapd is not keeping up and it is best to
100 + * do a batch of work at once. For memcg reclaim one check is made to
101 + * abort proportional reclaim if either the file or anon lru has already
102 + * dropped to zero at the first pass.
103 + */
104 + scan_adjusted = (global_reclaim(sc) && !current_is_kswapd() &&
105 + sc->priority == DEF_PRIORITY);
106 +
107 blk_start_plug(&plug);
108 while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] ||
109 nr[LRU_INACTIVE_FILE]) {
110 @@ -2045,17 +2059,8 @@ static void shrink_lruvec(struct lruvec
111 continue;
112
113 /*
114 - * For global direct reclaim, reclaim only the number of pages
115 - * requested. Less care is taken to scan proportionally as it
116 - * is more important to minimise direct reclaim stall latency
117 - * than it is to properly age the LRU lists.
118 - */
119 - if (global_reclaim(sc) && !current_is_kswapd())
120 - break;
121 -
122 - /*
123 * For kswapd and memcg, reclaim at least the number of pages
124 - * requested. Ensure that the anon and file LRUs shrink
125 + * requested. Ensure that the anon and file LRUs are scanned
126 * proportionally what was requested by get_scan_count(). We
127 * stop reclaiming one LRU and reduce the amount scanning
128 * proportional to the original scan target.
129 @@ -2063,6 +2068,15 @@ static void shrink_lruvec(struct lruvec
130 nr_file = nr[LRU_INACTIVE_FILE] + nr[LRU_ACTIVE_FILE];
131 nr_anon = nr[LRU_INACTIVE_ANON] + nr[LRU_ACTIVE_ANON];
132
133 + /*
134 + * It's just vindictive to attack the larger once the smaller
135 + * has gone to zero. And given the way we stop scanning the
136 + * smaller below, this makes sure that we only make one nudge
137 + * towards proportionality once we've got nr_to_reclaim.
138 + */
139 + if (!nr_file || !nr_anon)
140 + break;
141 +
142 if (nr_file > nr_anon) {
143 unsigned long scan_target = targets[LRU_INACTIVE_ANON] +
144 targets[LRU_ACTIVE_ANON] + 1;