Skip to contentSkip to conversation

mm/mm_init.c: use round_up() to align movable range

PATCH Applied Wei Yang 4 participants 5 messages Feb 7, 2025 – Feb 13, 2025

Subsystems (2)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/mm_init.c: use round_up() to align movable range

Since MAX_ORDER_NR_PAGES is power of 2, let's use a faster version.

---
 mm/mm_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mm_init.c +2 -2
index dec4084fe15a..99ef70a8b63c 100644
@@ -438,7 +438,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		 * was requested by the user
 		 */
 		required_movablecore =
-			roundup(required_movablecore, MAX_ORDER_NR_PAGES);
+			round_up(required_movablecore, MAX_ORDER_NR_PAGES);
 		required_movablecore = min(totalpages, required_movablecore);
 		corepages = totalpages - required_movablecore;
 
@@ -549,7 +549,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		unsigned long start_pfn, end_pfn;
 
 		zone_movable_pfn[nid] =
-			roundup(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
+			round_up(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
 
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		if (zone_movable_pfn[nid] >= end_pfn)
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Wei Yang

Since MAX_ORDER_NR_PAGES is power of 2, let's use a faster version.

Makes sense to me.

I noticed two similar instances in the same file
where round_up() might also be applicable:

  mm_init.c (usemap_size):
    usemapsize = roundup(zonesize, pageblock_nr_pages);
    usemapsize = roundup(usemapsize, BITS_PER_LONG);

Since both pageblock_nr_pages (1UL << pageblock_order) and BITS_PER_LONG (32 or 64) are powers of 2, these could potentially use round_up() as well. Perhaps worth considering in a follow-up patch?

Thanks,
Shivank

Quoted 28 lines
---
 mm/mm_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mm_init.c +2 -2
index dec4084fe15a..99ef70a8b63c 100644
@@ -438,7 +438,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		 * was requested by the user
 		 */
 		required_movablecore =
-			roundup(required_movablecore, MAX_ORDER_NR_PAGES);
+			round_up(required_movablecore, MAX_ORDER_NR_PAGES);
 		required_movablecore = min(totalpages, required_movablecore);
 		corepages = totalpages - required_movablecore;
 
@@ -549,7 +549,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		unsigned long start_pfn, end_pfn;
 
 		zone_movable_pfn[nid] =
-			roundup(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
+			round_up(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
 
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		if (zone_movable_pfn[nid] >= end_pfn)
author
#2 lore raw
Quoted 9 lines · Shivank Garg
Quoted 1 line · Wei Yang

Since MAX_ORDER_NR_PAGES is power of 2, let's use a faster version.

Makes sense to me.

Thanks for taking a look.

Quoted 11 lines

I noticed two similar instances in the same file
where round_up() might also be applicable:

mm_init.c (usemap_size):

   usemapsize = roundup(zonesize, pageblock_nr_pages);
   usemapsize = roundup(usemapsize, BITS_PER_LONG);

Since both pageblock_nr_pages (1UL << pageblock_order) and BITS_PER_LONG (32 or 64) are powers of 2, these could potentially use round_up() as well. Perhaps worth considering in a follow-up patch?

It looks reasonable to me. I would prepare one.

Thanks.

Quoted 34 lines

Thanks,
Shivank

Quoted 28 lines
---
 mm/mm_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mm_init.c +2 -2
index dec4084fe15a..99ef70a8b63c 100644
@@ -438,7 +438,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		 * was requested by the user
 		 */
 		required_movablecore =
-			roundup(required_movablecore, MAX_ORDER_NR_PAGES);
+			round_up(required_movablecore, MAX_ORDER_NR_PAGES);
 		required_movablecore = min(totalpages, required_movablecore);
 		corepages = totalpages - required_movablecore;
 
@@ -549,7 +549,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		unsigned long start_pfn, end_pfn;
 
 		zone_movable_pfn[nid] =
-			roundup(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
+			round_up(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
 
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		if (zone_movable_pfn[nid] >= end_pfn)
Signature · 2 lines
Wei Yang
Help you, Help me
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Wei Yang
Quoted 3 lines · Wei Yang

Since MAX_ORDER_NR_PAGES is power of 2, let's use a faster version.

Quoted 29 lines
---
 mm/mm_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mm_init.c +2 -2
index dec4084fe15a..99ef70a8b63c 100644
@@ -438,7 +438,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		 * was requested by the user
 		 */
 		required_movablecore =
-			roundup(required_movablecore, MAX_ORDER_NR_PAGES);
+			round_up(required_movablecore, MAX_ORDER_NR_PAGES);
 		required_movablecore = min(totalpages, required_movablecore);
 		corepages = totalpages - required_movablecore;
 
@@ -549,7 +549,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		unsigned long start_pfn, end_pfn;
 
 		zone_movable_pfn[nid] =
-			roundup(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
+			round_up(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
 
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		if (zone_movable_pfn[nid] >= end_pfn)
Signature · 1 line
2.34.1
Signature · 2 lines
Sincerely yours,
Mike.
Reviewed-by on v1 1/1
#4 lore raw
In reply to Wei Yang
Quoted 21 lines · Wei Yang

Since MAX_ORDER_NR_PAGES is power of 2, let's use a faster version.

---
 mm/mm_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mm_init.c +1 -1
index dec4084fe15a..99ef70a8b63c 100644
@@ -438,7 +438,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		 * was requested by the user
 		 */
 		required_movablecore =
-			roundup(required_movablecore, MAX_ORDER_NR_PAGES);
+			round_up(required_movablecore, MAX_ORDER_NR_PAGES);
 		required_movablecore = min(totalpages, required_movablecore);
 		corepages = totalpages - required_movablecore;
 

mm/mm_init.c static void __init find_zone_movable_pfns_for_nodes(void) · line 555

Quoted 8 lines
mm/mm_init.c +1 -1
@@ -549,7 +549,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 		unsigned long start_pfn, end_pfn;
 
 		zone_movable_pfn[nid] =
-			roundup(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
+			round_up(zone_movable_pfn[nid], MAX_ORDER_NR_PAGES);
 
 		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
 		if (zone_movable_pfn[nid] >= end_pfn)