Skip to contentSkip to conversation

mm/cma: ise for_each_clear_bitrange() where appropriate

PATCH Applied Yury Norov 2 participants 5 messages Jul 19, 2025 – Jul 21, 2025

Subsystems (2)
lore
Share & tools
lore

Yury Norov

author
#0 lore raw

cover mm/cma: ise for_each_clear_bitrange() where appropriate

From: Yury Norov (NVIDIA) <[email protected]>

Hi Andrew,

Pleas pull a couple of simplifications for mm/cma.

Thanks,
Yury

Yury Norov (NVIDIA) (2):
mm: cma: simplify cma_debug_show_areas()
mm: cma: simplify cma_maxchunk_get()

 mm/cma.c       | 19 ++++---------------
 mm/cma_debug.c | 10 +---------
 2 files changed, 5 insertions(+), 24 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 mm: cma: simplify cma_debug_show_areas()

From: Yury Norov (NVIDIA) <[email protected]>

The function opencodes for_each_clear_bitrange(). Fix that and drop most of housekeeping code.

---
 mm/cma.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
mm/cma.c +4 -15
index 397567883a10..adc57bf7c68c 100644
@@ -739,8 +739,7 @@ static int __init __cma_declare_contiguous_nid(phys_addr_t *basep,
 
 static void cma_debug_show_areas(struct cma *cma)
 {
-	unsigned long next_zero_bit, next_set_bit, nr_zero;
-	unsigned long start;
+	unsigned long start, end;
 	unsigned long nr_part;
 	unsigned long nbits;
 	int r;
@@ -751,22 +750,12 @@ static void cma_debug_show_areas(struct cma *cma)
 	for (r = 0; r < cma->nranges; r++) {
 		cmr = &cma->ranges[r];
 
-		start = 0;
 		nbits = cma_bitmap_maxno(cma, cmr);
 
 		pr_info("range %d: ", r);
-		for (;;) {
-			next_zero_bit = find_next_zero_bit(cmr->bitmap,
-							   nbits, start);
-			if (next_zero_bit >= nbits)
-				break;
-			next_set_bit = find_next_bit(cmr->bitmap, nbits,
-						     next_zero_bit);
-			nr_zero = next_set_bit - next_zero_bit;
-			nr_part = nr_zero << cma->order_per_bit;
-			pr_cont("%s%lu@%lu", start ? "+" : "", nr_part,
-				next_zero_bit);
-			start = next_zero_bit + nr_zero;
+		for_each_clear_bitrange(start, end, cmr->bitmap, nbits) {
+			nr_part = (end - start) << cma->order_per_bit;
+			pr_cont("%s%lu@%lu", start ? "+" : "", nr_part, start);
 		}
 		pr_info("\n");
 	}
Signature · 1 line
2.43.0
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] mm: cma: simplify cma_debug_show_areas()

Quoted 4 lines · Yury Norov

From: Yury Norov (NVIDIA) <[email protected]>

The function opencodes for_each_clear_bitrange(). Fix that and drop most of housekeeping code.

Same comment regarding "fix" as for patch #2

Signature · 3 lines
Cheers,

David / dhildenb
author
#3 lore raw

PATCH 2/2 mm: cma: simplify cma_maxchunk_get()

In reply to Yury Norov

From: Yury Norov (NVIDIA) <[email protected]>

The function opencodes for_each_clear_bitrange(). Fix that and drop most of housekeeping code.

---
 mm/cma_debug.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
mm/cma_debug.c +1 -9
index fdf899532ca0..8c7d7f8e8fbd 100644
@@ -56,16 +56,8 @@ static int cma_maxchunk_get(void *data, u64 *val)
 	for (r = 0; r < cma->nranges; r++) {
 		cmr = &cma->ranges[r];
 		bitmap_maxno = cma_bitmap_maxno(cma, cmr);
-		end = 0;
-		for (;;) {
-			start = find_next_zero_bit(cmr->bitmap,
-						   bitmap_maxno, end);
-			if (start >= bitmap_maxno)
-				break;
-			end = find_next_bit(cmr->bitmap, bitmap_maxno,
-					    start);
+		for_each_clear_bitrange(start, end, cmr->bitmap, bitmap_maxno)
 			maxchunk = max(end - start, maxchunk);
-		}
 	}
 	spin_unlock_irq(&cma->lock);
 	*val = (u64)maxchunk << cma->order_per_bit;
Signature · 1 line
2.43.0
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] mm: cma: simplify cma_maxchunk_get()

Quoted 4 lines · Yury Norov

From: Yury Norov (NVIDIA) <[email protected]>

The function opencodes for_each_clear_bitrange(). Fix that and drop most of housekeeping code.

Not sure if talking about a "fix" it the right word here.

Quoted 28 lines
---
  mm/cma_debug.c | 10 +---------
  1 file changed, 1 insertion(+), 9 deletions(-)
mm/cma_debug.c +1 -9
index fdf899532ca0..8c7d7f8e8fbd 100644
@@ -56,16 +56,8 @@ static int cma_maxchunk_get(void *data, u64 *val)
  	for (r = 0; r < cma->nranges; r++) {
  		cmr = &cma->ranges[r];
  		bitmap_maxno = cma_bitmap_maxno(cma, cmr);
-		end = 0;
-		for (;;) {
-			start = find_next_zero_bit(cmr->bitmap,
-						   bitmap_maxno, end);
-			if (start >= bitmap_maxno)
-				break;
-			end = find_next_bit(cmr->bitmap, bitmap_maxno,
-					    start);
+		for_each_clear_bitrange(start, end, cmr->bitmap, bitmap_maxno)
  			maxchunk = max(end - start, maxchunk);
-		}
  	}
  	spin_unlock_irq(&cma->lock);
  	*val = (u64)maxchunk << cma->order_per_bit;
Signature · 3 lines
Cheers,

David / dhildenb