aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinayak Menon <vinmenon@codeaurora.org>2017-02-24 17:59:39 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-02-24 20:46:56 -0500
commite1587a4945408faa58d0485002c110eb2454740c (patch)
tree83aca8da303ea0e1001aca318de83885a140d881
parent3a4f8a0b3ffa733ffbb327685e83b63383127cf6 (diff)
mm: vmpressure: fix sending wrong events on underflow
At the end of a window period, if the reclaimed pages is greater than scanned, an unsigned underflow can result in a huge pressure value and thus a critical event. Reclaimed pages is found to go higher than scanned because of the addition of reclaimed slab pages to reclaimed in shrink_node without a corresponding increment to scanned pages. Minchan Kim mentioned that this can also happen in the case of a THP page where the scanned is 1 and reclaimed could be 512. Link: http://lkml.kernel.org/r/1486641577-11685-1-git-send-email-vinmenon@codeaurora.org Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org> Acked-by: Minchan Kim <minchan@kernel.org> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Rik van Riel <riel@redhat.com> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Anton Vorontsov <anton.vorontsov@linaro.org> Cc: Shiraz Hashim <shashim@codeaurora.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/vmpressure.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index 149fdf6c5c56..6063581f705c 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -112,9 +112,16 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned,
112 unsigned long reclaimed) 112 unsigned long reclaimed)
113{ 113{
114 unsigned long scale = scanned + reclaimed; 114 unsigned long scale = scanned + reclaimed;
115 unsigned long pressure; 115 unsigned long pressure = 0;
116 116
117 /* 117 /*
118 * reclaimed can be greater than scanned in cases
119 * like THP, where the scanned is 1 and reclaimed
120 * could be 512
121 */
122 if (reclaimed >= scanned)
123 goto out;
124 /*
118 * We calculate the ratio (in percents) of how many pages were 125 * We calculate the ratio (in percents) of how many pages were
119 * scanned vs. reclaimed in a given time frame (window). Note that 126 * scanned vs. reclaimed in a given time frame (window). Note that
120 * time is in VM reclaimer's "ticks", i.e. number of pages 127 * time is in VM reclaimer's "ticks", i.e. number of pages
@@ -124,6 +131,7 @@ static enum vmpressure_levels vmpressure_calc_level(unsigned long scanned,
124 pressure = scale - (reclaimed * scale / scanned); 131 pressure = scale - (reclaimed * scale / scanned);
125 pressure = pressure * 100 / scale; 132 pressure = pressure * 100 / scale;
126 133
134out:
127 pr_debug("%s: %3lu (s: %lu r: %lu)\n", __func__, pressure, 135 pr_debug("%s: %3lu (s: %lu r: %lu)\n", __func__, pressure,
128 scanned, reclaimed); 136 scanned, reclaimed);
129 137