]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.10.34/mm-compaction-break-out-of-loop-on-pagebuddy-in-isolate_freepages_block.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.10.34 / mm-compaction-break-out-of-loop-on-pagebuddy-in-isolate_freepages_block.patch
1 From 2af120bc040c5ebcda156df6be6a66610ab6957f Mon Sep 17 00:00:00 2001
2 From: Laura Abbott <lauraa@codeaurora.org>
3 Date: Mon, 10 Mar 2014 15:49:44 -0700
4 Subject: mm/compaction: break out of loop on !PageBuddy in isolate_freepages_block
5
6 From: Laura Abbott <lauraa@codeaurora.org>
7
8 commit 2af120bc040c5ebcda156df6be6a66610ab6957f upstream.
9
10 We received several reports of bad page state when freeing CMA pages
11 previously allocated with alloc_contig_range:
12
13 BUG: Bad page state in process Binder_A pfn:63202
14 page:d21130b0 count:0 mapcount:1 mapping: (null) index:0x7dfbf
15 page flags: 0x40080068(uptodate|lru|active|swapbacked)
16
17 Based on the page state, it looks like the page was still in use. The
18 page flags do not make sense for the use case though. Further debugging
19 showed that despite alloc_contig_range returning success, at least one
20 page in the range still remained in the buddy allocator.
21
22 There is an issue with isolate_freepages_block. In strict mode (which
23 CMA uses), if any pages in the range cannot be isolated,
24 isolate_freepages_block should return failure 0. The current check
25 keeps track of the total number of isolated pages and compares against
26 the size of the range:
27
28 if (strict && nr_strict_required > total_isolated)
29 total_isolated = 0;
30
31 After taking the zone lock, if one of the pages in the range is not in
32 the buddy allocator, we continue through the loop and do not increment
33 total_isolated. If in the last iteration of the loop we isolate more
34 than one page (e.g. last page needed is a higher order page), the check
35 for total_isolated may pass and we fail to detect that a page was
36 skipped. The fix is to bail out if the loop immediately if we are in
37 strict mode. There's no benfit to continuing anyway since we need all
38 pages to be isolated. Additionally, drop the error checking based on
39 nr_strict_required and just check the pfn ranges. This matches with
40 what isolate_freepages_range does.
41
42 Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
43 Acked-by: Minchan Kim <minchan@kernel.org>
44 Cc: Mel Gorman <mgorman@suse.de>
45 Acked-by: Vlastimil Babka <vbabka@suse.cz>
46 Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
47 Acked-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
48 Acked-by: Michal Nazarewicz <mina86@mina86.com>
49 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
50 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
51 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
52
53 ---
54 mm/compaction.c | 20 +++++++++++++-------
55 1 file changed, 13 insertions(+), 7 deletions(-)
56
57 --- a/mm/compaction.c
58 +++ b/mm/compaction.c
59 @@ -252,7 +252,6 @@ static unsigned long isolate_freepages_b
60 {
61 int nr_scanned = 0, total_isolated = 0;
62 struct page *cursor, *valid_page = NULL;
63 - unsigned long nr_strict_required = end_pfn - blockpfn;
64 unsigned long flags;
65 bool locked = false;
66
67 @@ -265,11 +264,12 @@ static unsigned long isolate_freepages_b
68
69 nr_scanned++;
70 if (!pfn_valid_within(blockpfn))
71 - continue;
72 + goto isolate_fail;
73 +
74 if (!valid_page)
75 valid_page = page;
76 if (!PageBuddy(page))
77 - continue;
78 + goto isolate_fail;
79
80 /*
81 * The zone lock must be held to isolate freepages.
82 @@ -290,12 +290,10 @@ static unsigned long isolate_freepages_b
83
84 /* Recheck this is a buddy page under lock */
85 if (!PageBuddy(page))
86 - continue;
87 + goto isolate_fail;
88
89 /* Found a free page, break it into order-0 pages */
90 isolated = split_free_page(page);
91 - if (!isolated && strict)
92 - break;
93 total_isolated += isolated;
94 for (i = 0; i < isolated; i++) {
95 list_add(&page->lru, freelist);
96 @@ -306,7 +304,15 @@ static unsigned long isolate_freepages_b
97 if (isolated) {
98 blockpfn += isolated - 1;
99 cursor += isolated - 1;
100 + continue;
101 }
102 +
103 +isolate_fail:
104 + if (strict)
105 + break;
106 + else
107 + continue;
108 +
109 }
110
111 trace_mm_compaction_isolate_freepages(nr_scanned, total_isolated);
112 @@ -316,7 +322,7 @@ static unsigned long isolate_freepages_b
113 * pages requested were isolated. If there were any failures, 0 is
114 * returned and CMA will fail.
115 */
116 - if (strict && nr_strict_required > total_isolated)
117 + if (strict && blockpfn < end_pfn)
118 total_isolated = 0;
119
120 if (locked)