]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.51/mm-cma.c-fix-the-bitmap-status-to-show-failed-alloca.patch
Linux 4.19.51
[thirdparty/kernel/stable-queue.git] / releases / 4.19.51 / mm-cma.c-fix-the-bitmap-status-to-show-failed-alloca.patch
CommitLineData
37554d48
SL
1From 9da1b4ca02dcc2d7059c9f615dcd317d8fb28dd0 Mon Sep 17 00:00:00 2001
2From: Yue Hu <huyue2@yulong.com>
3Date: Mon, 13 May 2019 17:17:41 -0700
4Subject: mm/cma.c: fix the bitmap status to show failed allocation reason
5
6[ Upstream commit 2b59e01a3aa665f751d1410b99fae9336bd424e1 ]
7
8Currently one bit in cma bitmap represents number of pages rather than
9one page, cma->count means cma size in pages. So to find available pages
10via find_next_zero_bit()/find_next_bit() we should use cma size not in
11pages but in bits although current free pages number is correct due to
12zero value of order_per_bit. Once order_per_bit is changed the bitmap
13status will be incorrect.
14
15The size input in cma_debug_show_areas() is not correct. It will
16affect the available pages at some position to debug the failure issue.
17
18This is an example with order_per_bit = 1
19
20Before 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
23After 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
26Obviously the bitmap status before is incorrect.
27
28Link: http://lkml.kernel.org/r/20190320060829.9144-1-zbestahu@gmail.com
29Signed-off-by: Yue Hu <huyue2@yulong.com>
30Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
31Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
32Cc: Ingo Molnar <mingo@kernel.org>
33Cc: Vlastimil Babka <vbabka@suse.cz>
34Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
35Cc: Randy Dunlap <rdunlap@infradead.org>
36Cc: Laura Abbott <labbott@redhat.com>
37Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
38Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
39Signed-off-by: Sasha Levin <sashal@kernel.org>
40---
41 mm/cma.c | 19 +++++++++++--------
42 1 file changed, 11 insertions(+), 8 deletions(-)
43
44diff --git a/mm/cma.c b/mm/cma.c
45index 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--
842.20.1
85