linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/cma: fix the bitmap status to show failed allocation reason
@ 2019-03-20  6:08 Yue Hu
  2019-03-20 22:12 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Yue Hu @ 2019-03-20  6:08 UTC (permalink / raw)
  To: akpm, iamjoonsoo.kim, mingo, vbabka, rppt, rdunlap; +Cc: linux-mm, huyue2

From: Yue Hu <huyue2@yulong.com>

Currently one bit in cma bitmap represents number of pages rather than
one page, cma->count means cma size in pages. So to find available pages
via find_next_zero_bit()/find_next_bit() we should use cma size not in
pages but in bits although current free pages number is correct due to
zero value of order_per_bit. Once order_per_bit is changed the bitmap
status will be incorrect.

Signed-off-by: Yue Hu <huyue2@yulong.com>
---
 mm/cma.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/mm/cma.c b/mm/cma.c
index 5809bbe..6a7aa05 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -367,23 +367,26 @@ int __init cma_declare_contiguous(phys_addr_t base,
 #ifdef CONFIG_CMA_DEBUG
 static void cma_debug_show_areas(struct cma *cma)
 {
-	unsigned long next_zero_bit, next_set_bit;
+	unsigned long next_zero_bit, next_set_bit, nr_zero;
 	unsigned long start = 0;
-	unsigned int nr_zero, nr_total = 0;
+	unsigned long nr_part, nr_total = 0;
+	unsigned long nbits = cma_bitmap_maxno(cma);
 
 	mutex_lock(&cma->lock);
 	pr_info("number of available pages: ");
 	for (;;) {
-		next_zero_bit = find_next_zero_bit(cma->bitmap, cma->count, start);
-		if (next_zero_bit >= cma->count)
+		next_zero_bit = find_next_zero_bit(cma->bitmap, nbits, start);
+		if (next_zero_bit >= nbits)
 			break;
-		next_set_bit = find_next_bit(cma->bitmap, cma->count, next_zero_bit);
+		next_set_bit = find_next_bit(cma->bitmap, nbits, next_zero_bit);
 		nr_zero = next_set_bit - next_zero_bit;
-		pr_cont("%s%u@%lu", nr_total ? "+" : "", nr_zero, next_zero_bit);
-		nr_total += nr_zero;
+		nr_part = nr_zero << cma->order_per_bit;
+		pr_cont("%s%lu@%lu", nr_total ? "+" : "", nr_part,
+			next_zero_bit);
+		nr_total += nr_part;
 		start = next_zero_bit + nr_zero;
 	}
-	pr_cont("=> %u free of %lu total pages\n", nr_total, cma->count);
+	pr_cont("=> %lu free of %lu total pages\n", nr_total, cma->count);
 	mutex_unlock(&cma->lock);
 }
 #else
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/cma: fix the bitmap status to show failed allocation reason
  2019-03-20  6:08 [PATCH] mm/cma: fix the bitmap status to show failed allocation reason Yue Hu
@ 2019-03-20 22:12 ` Andrew Morton
  2019-03-21  2:17   ` Yue Hu
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2019-03-20 22:12 UTC (permalink / raw)
  To: Yue Hu; +Cc: iamjoonsoo.kim, mingo, vbabka, rppt, rdunlap, linux-mm, huyue2

On Wed, 20 Mar 2019 14:08:29 +0800 Yue Hu <zbestahu@gmail.com> wrote:

> Currently one bit in cma bitmap represents number of pages rather than
> one page, cma->count means cma size in pages. So to find available pages
> via find_next_zero_bit()/find_next_bit() we should use cma size not in
> pages but in bits although current free pages number is correct due to
> zero value of order_per_bit. Once order_per_bit is changed the bitmap
> status will be incorrect.

When fixing a bug, please always describe the end-user visible runtime
effects of that bug?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/cma: fix the bitmap status to show failed allocation reason
  2019-03-20 22:12 ` Andrew Morton
@ 2019-03-21  2:17   ` Yue Hu
  2019-03-21  2:58     ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Yue Hu @ 2019-03-21  2:17 UTC (permalink / raw)
  To: Andrew Morton
  Cc: iamjoonsoo.kim, mingo, vbabka, rppt, rdunlap, linux-mm, huyue2

On Wed, 20 Mar 2019 15:12:45 -0700
Andrew Morton <akpm@linux-foundation.org> wrote:

> On Wed, 20 Mar 2019 14:08:29 +0800 Yue Hu <zbestahu@gmail.com> wrote:
> 
> > Currently one bit in cma bitmap represents number of pages rather than
> > one page, cma->count means cma size in pages. So to find available pages
> > via find_next_zero_bit()/find_next_bit() we should use cma size not in
> > pages but in bits although current free pages number is correct due to
> > zero value of order_per_bit. Once order_per_bit is changed the bitmap
> > status will be incorrect.  
> 
> When fixing a bug, please always describe the end-user visible runtime
> effects of that bug?
> 

Hi Andrew,

From perspective of bitmap function, the size input is not correct. It will
affect the available pages at some position to debug the failure issue.

This is an example with order_per_bit = 1

Before this change:
[    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

After this change:
[    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

Obviously the bitmap status before is incorrect, i can add this effect describtion
in v2, but seems the patch has been merged?

Thx.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/cma: fix the bitmap status to show failed allocation reason
  2019-03-21  2:17   ` Yue Hu
@ 2019-03-21  2:58     ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2019-03-21  2:58 UTC (permalink / raw)
  To: Yue Hu; +Cc: iamjoonsoo.kim, mingo, vbabka, rppt, rdunlap, linux-mm, huyue2

On Thu, 21 Mar 2019 10:17:21 +0800 Yue Hu <zbestahu@gmail.com> wrote:

> >From perspective of bitmap function, the size input is not correct. It will
> affect the available pages at some position to debug the failure issue.
> 
> This is an example with order_per_bit = 1
> 
> Before this change:
> [    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
> 
> After this change:
> [    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
> 
> Obviously the bitmap status before is incorrect, i can add this effect describtion
> in v2, but seems the patch has been merged?

Thanks, I updated the changelog.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-21  2:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-20  6:08 [PATCH] mm/cma: fix the bitmap status to show failed allocation reason Yue Hu
2019-03-20 22:12 ` Andrew Morton
2019-03-21  2:17   ` Yue Hu
2019-03-21  2:58     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).