]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/mm-cma.c-fix-the-bitmap-status-to-show-failed-alloca.patch
26c93c72df1d466317e81b0fefeb123778473d5c
[thirdparty/kernel/stable-queue.git] / queue-4.19 / mm-cma.c-fix-the-bitmap-status-to-show-failed-alloca.patch
1 From 9da1b4ca02dcc2d7059c9f615dcd317d8fb28dd0 Mon Sep 17 00:00:00 2001
2 From: Yue Hu <huyue2@yulong.com>
3 Date: Mon, 13 May 2019 17:17:41 -0700
4 Subject: mm/cma.c: fix the bitmap status to show failed allocation reason
5
6 [ Upstream commit 2b59e01a3aa665f751d1410b99fae9336bd424e1 ]
7
8 Currently one bit in cma bitmap represents number of pages rather than
9 one page, cma->count means cma size in pages. So to find available pages
10 via find_next_zero_bit()/find_next_bit() we should use cma size not in
11 pages but in bits although current free pages number is correct due to
12 zero value of order_per_bit. Once order_per_bit is changed the bitmap
13 status will be incorrect.
14
15 The size input in cma_debug_show_areas() is not correct. It will
16 affect the available pages at some position to debug the failure issue.
17
18 This is an example with order_per_bit = 1
19
20 Before this change:
21 [ 4.120060] cma: number of available pages: 1@93+4@108+7@121+7@137+7@153+7@169+7@185+7@201+3@213+3@221+3@229+3@237+3@245+3@253+3@261+3@269+3@277+3@285+3@293+3@301+3@309+3@317+3@325+19@333+15@369+512@512=> 638 free of 1024 total pages
22
23 After this change:
24 [ 4.143234] cma: number of available pages: 2@93+8@108+14@121+14@137+14@153+14@169+14@185+14@201+6@213+6@221+6@229+6@237+6@245+6@253+6@261+6@269+6@277+6@285+6@293+6@301+6@309+6@317+6@325+38@333+30@369=> 252 free of 1024 total pages
25
26 Obviously the bitmap status before is incorrect.
27
28 Link: http://lkml.kernel.org/r/20190320060829.9144-1-zbestahu@gmail.com
29 Signed-off-by: Yue Hu <huyue2@yulong.com>
30 Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
31 Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
32 Cc: Ingo Molnar <mingo@kernel.org>
33 Cc: Vlastimil Babka <vbabka@suse.cz>
34 Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
35 Cc: Randy Dunlap <rdunlap@infradead.org>
36 Cc: Laura Abbott <labbott@redhat.com>
37 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
38 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
39 Signed-off-by: Sasha Levin <sashal@kernel.org>
40 ---
41 mm/cma.c | 19 +++++++++++--------
42 1 file changed, 11 insertions(+), 8 deletions(-)
43
44 diff --git a/mm/cma.c b/mm/cma.c
45 index 6ce6e22f82d9..476dfe13a701 100644
46 --- a/mm/cma.c
47 +++ b/mm/cma.c
48 @@ -371,23 +371,26 @@ err:
49 #ifdef CONFIG_CMA_DEBUG
50 static void cma_debug_show_areas(struct cma *cma)
51 {
52 - unsigned long next_zero_bit, next_set_bit;
53 + unsigned long next_zero_bit, next_set_bit, nr_zero;
54 unsigned long start = 0;
55 - unsigned int nr_zero, nr_total = 0;
56 + unsigned long nr_part, nr_total = 0;
57 + unsigned long nbits = cma_bitmap_maxno(cma);
58
59 mutex_lock(&cma->lock);
60 pr_info("number of available pages: ");
61 for (;;) {
62 - next_zero_bit = find_next_zero_bit(cma->bitmap, cma->count, start);
63 - if (next_zero_bit >= cma->count)
64 + next_zero_bit = find_next_zero_bit(cma->bitmap, nbits, start);
65 + if (next_zero_bit >= nbits)
66 break;
67 - next_set_bit = find_next_bit(cma->bitmap, cma->count, next_zero_bit);
68 + next_set_bit = find_next_bit(cma->bitmap, nbits, next_zero_bit);
69 nr_zero = next_set_bit - next_zero_bit;
70 - pr_cont("%s%u@%lu", nr_total ? "+" : "", nr_zero, next_zero_bit);
71 - nr_total += nr_zero;
72 + nr_part = nr_zero << cma->order_per_bit;
73 + pr_cont("%s%lu@%lu", nr_total ? "+" : "", nr_part,
74 + next_zero_bit);
75 + nr_total += nr_part;
76 start = next_zero_bit + nr_zero;
77 }
78 - pr_cont("=> %u free of %lu total pages\n", nr_total, cma->count);
79 + pr_cont("=> %lu free of %lu total pages\n", nr_total, cma->count);
80 mutex_unlock(&cma->lock);
81 }
82 #else
83 --
84 2.20.1
85