Skip to contentSkip to conversation

mm/page_alloc: break on the first hit of mem range

PATCH In review Wei Yang 3 participants 13 messages Mar 27, 2018 – Mar 28, 2018

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/page_alloc: break on the first hit of mem range

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

This patch returns the fist hit instead of iterating the whole regions.

---
 mm/page_alloc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/page_alloc.c +5 -5
index 635d7dd29d7f..a65de1ec4b91 100644
@@ -6365,14 +6365,14 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
+	unsigned long min_pfn;
 	int i;
 
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	for_each_mem_pfn_range(i, nid, &min_pfn, NULL, NULL) {
+		break;
+	}
 
-	if (min_pfn == ULONG_MAX) {
+	if (i == -1) {
 		pr_warn("Could not find start_pfn for node %d\n", nid);
 		return 0;
 	}
Signature · 1 line
2.15.1
#1 lore raw
Quoted 3 lines · Wei Yang

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

I haven't looked at the code yet but the changelog should contain the motivation why it exists. It seems like this is an optimization. If so, what is the impact?

Quoted 34 lines

This patch returns the fist hit instead of iterating the whole regions.

---
 mm/page_alloc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/page_alloc.c +5 -5
index 635d7dd29d7f..a65de1ec4b91 100644
@@ -6365,14 +6365,14 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
+	unsigned long min_pfn;
 	int i;
 
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	for_each_mem_pfn_range(i, nid, &min_pfn, NULL, NULL) {
+		break;
+	}
 
-	if (min_pfn == ULONG_MAX) {
+	if (i == -1) {
 		pr_warn("Could not find start_pfn for node %d\n", nid);
 		return 0;
 	}
Signature · 1 line
2.15.1
Signature · 2 lines
Michal Hocko
SUSE Labs
maintainer
#5 lore raw
In reply to Wei Yang
Quoted 14 lines · On Tue, 27 Mar 2018 11:57:07 +0800 Wei Yang <[email protected]> wrote:

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

This patch returns the fist hit instead of iterating the whole regions.

...

mm/page_alloc.c +0 -0
@@ -6365,14 +6365,14 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {

mm/page_alloc.c unsigned long __init node_map_pfn_alignment(void) · line 6373

Quoted 10 lines
mm/page_alloc.c +4 -4
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
+	unsigned long min_pfn;
 	int i;
 
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	for_each_mem_pfn_range(i, nid, &min_pfn, NULL, NULL) {
+		break;
+	}

That would be the weirdest-looking code snippet in mm/!

Can't we just use a single and simple call to __next_mem_pfn_range(), or something like that?

Quoted 3 lines

...

author
#2 lore raw
In reply to Michal Hocko
Quoted 9 lines · Michal Hocko
Quoted 3 lines · Wei Yang

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

I haven't looked at the code yet but the changelog should contain the motivation why it exists. It seems like this is an optimization. If so, what is the impact?

Yep, this is a trivial optimization on searching the minimal pfn on a special node. It would be better for audience to understand if I put some words in change log.

The impact of this patch is it would accelerate the searching process when there are many memory ranges in memblock.

For example, in the case https://lkml.org/lkml/2018/3/25/291, there are around 30 memory ranges on node 0. The original code need to iterate all those ranges to find the minimal pfn, while after optimization it just need once.

The more memory ranges there are, the more impact this patch has.

Quoted 38 lines
Quoted 34 lines

This patch returns the fist hit instead of iterating the whole regions.

---
 mm/page_alloc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
mm/page_alloc.c +5 -5
index 635d7dd29d7f..a65de1ec4b91 100644
@@ -6365,14 +6365,14 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
+	unsigned long min_pfn;
 	int i;
 
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	for_each_mem_pfn_range(i, nid, &min_pfn, NULL, NULL) {
+		break;
+	}
 
-	if (min_pfn == ULONG_MAX) {
+	if (i == -1) {
 		pr_warn("Could not find start_pfn for node %d\n", nid);
 		return 0;
 	}
Signature · 1 line
2.15.1
Signature · 2 lines
Michal Hocko
SUSE Labs
Signature · 2 lines
Wei Yang
Help you, Help me
author
#6 lore raw
In reply to Andrew Morton
Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Tue, 27 Mar 2018 11:57:07 +0800 Wei Yang <[email protected]> wrote:

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

This patch returns the fist hit instead of iterating the whole regions.

...

mm/page_alloc.c +1 -2
@@ -6365,14 +6365,14 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
+	unsigned long min_pfn;
 	int i;
 
Quoted 8 lines

mm/page_alloc.c unsigned long __init node_map_pfn_alignment(void) · line 6373

Quoted 5 lines
mm/page_alloc.c +3 -2
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	for_each_mem_pfn_range(i, nid, &min_pfn, NULL, NULL) {
+		break;
+	}

That would be the weirdest-looking code snippet in mm/!

You mean the only break in a for_each loop? Hmm..., this is really not that nice. Haven't noticed could get a "best" in this way :-)

Quoted 3 lines

Can't we just use a single and simple call to __next_mem_pfn_range(), or something like that?

Sounds a better choice, if you like this version, I would rearrange the patch and send v2.

Have a nice day~

Quoted 3 lines
Quoted 3 lines

...

Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#7 lore raw
Quoted 31 lines · On Wed, 28 Mar 2018 08:51:42 +0800 Wei Yang <[email protected]> wrote:
Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Tue, 27 Mar 2018 11:57:07 +0800 Wei Yang <[email protected]> wrote:

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

This patch returns the fist hit instead of iterating the whole regions.

...

mm/page_alloc.c +1 -2
@@ -6365,14 +6365,14 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
+	unsigned long min_pfn;
 	int i;
 
Quoted 8 lines

mm/page_alloc.c unsigned long __init node_map_pfn_alignment(void) · line 6373

Quoted 5 lines
mm/page_alloc.c +3 -2
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	for_each_mem_pfn_range(i, nid, &min_pfn, NULL, NULL) {
+		break;
+	}

That would be the weirdest-looking code snippet in mm/!

Quoted 2 lines

You mean the only break in a for_each loop? Hmm..., this is really not that nice. Haven't noticed could get a "best" in this way :-)

I guess we can make it nicer by adding a comment along the lines of

/*
* Use for_each_mem_pfn_range() to locate the lowest valid pfn in the
* range. We only need to iterate a single time, as the pfn's are
* sorted in ascending order.
*/

Because adding a call to the obviously-internal __next_mem_pfn_range() isn't very nice either.

Anyway, please have a think, see what we can come up with.

author
#8 lore raw
Quoted 38 lines · Andrew Morton
Quoted 31 lines · On Wed, 28 Mar 2018 08:51:42 +0800 Wei Yang <[email protected]> wrote:
Quoted 21 lines · Andrew Morton
Quoted 19 lines · On Tue, 27 Mar 2018 11:57:07 +0800 Wei Yang <[email protected]> wrote:

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

This patch returns the fist hit instead of iterating the whole regions.

...

mm/page_alloc.c +1 -2
@@ -6365,14 +6365,14 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
+	unsigned long min_pfn;
 	int i;
 
Quoted 8 lines

mm/page_alloc.c unsigned long __init node_map_pfn_alignment(void) · line 6373

Quoted 5 lines
mm/page_alloc.c +3 -2
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	for_each_mem_pfn_range(i, nid, &min_pfn, NULL, NULL) {
+		break;
+	}

That would be the weirdest-looking code snippet in mm/!

Quoted 2 lines

You mean the only break in a for_each loop? Hmm..., this is really not that nice. Haven't noticed could get a "best" in this way :-)

I guess we can make it nicer by adding a comment along the lines of

Quoted 8 lines

/*
* Use for_each_mem_pfn_range() to locate the lowest valid pfn in the
* range. We only need to iterate a single time, as the pfn's are
* sorted in ascending order.
*/

Because adding a call to the obviously-internal __next_mem_pfn_range() isn't very nice either.

Yep, you are right.

Quoted 2 lines

Anyway, please have a think, see what we can come up with.

My approach is to add a macro fist_mem_pfn() as a self-explain wrapper of __next_mem_pfn_range().

Hope you would like this :-)

Signature · 2 lines
Wei Yang
Help you, Help me
author
#9 lore raw

PATCH 1/1 mm/page_alloc: optimize find_min_pfn_for_node() by geting the minimal pfn directly

In reply to Andrew Morton

find_min_pfn_for_node() iterates on pfn range to find the minimum pfn for a node, while this process could be optimized. The memblock_region in memblock_type are already in ascending order, so the first one is the minimal one.

For example, if there are 30 memory regions, the original version would iterate all 30 regions, while the new version just need iterate a single time.

This patch does a trivial optimization by adding first_mem_pfn() and use this to get the minimal pfn directly.

---
v2:
* add first_mem_pfn() and use it to replace for_each_mem_pfn_ragne()
* some more meaningful words in change log

---
 include/linux/memblock.h |  9 +++++++++
 mm/page_alloc.c          | 14 ++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)
include/linux/memblock.h +9 -0
index 8be5077efb5f..22932f45538f 100644
@@ -189,6 +189,15 @@ void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
 			  unsigned long *out_end_pfn, int *out_nid);
 unsigned long memblock_next_valid_pfn(unsigned long pfn, unsigned long max_pfn);
 
+/**
+ * first_mem_pfn - get the first memory pfn
+ * @i: an integer used as an indicator
+ * @nid: node selector, %MAX_NUMNODES for all nodes
+ * @p_first: ptr to ulong for first pfn of the range, can be %NULL
+ */
+#define first_mem_pfn(i, nid, p_first)				\
+	__next_mem_pfn_range(&i, nid, p_first, NULL, NULL)
+
 /**
  * for_each_mem_pfn_range - early memory pfn range iterator
  * @i: an integer used as loop variable
mm/page_alloc.c +8 -6
index 635d7dd29d7f..8c964dcc3a9e 100644
@@ -6365,14 +6365,16 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
-	int i;
+	unsigned long min_pfn;
+	int i = -1;
 
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	/*
+	 * The first pfn on nid node is the minimal one, as the pfn's are
+	 * stored in ascending order.
+	 */
+	first_mem_pfn(i, nid, &min_pfn);
 
-	if (min_pfn == ULONG_MAX) {
+	if (i == -1) {
 		pr_warn("Could not find start_pfn for node %d\n", nid);
 		return 0;
 	}
Signature · 1 line
2.15.1
#3 lore raw
In reply to Wei Yang
Quoted 15 lines · Wei Yang
Quoted 9 lines · Michal Hocko
Quoted 3 lines · Wei Yang

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

I haven't looked at the code yet but the changelog should contain the motivation why it exists. It seems like this is an optimization. If so, what is the impact?

Yep, this is a trivial optimization on searching the minimal pfn on a special node. It would be better for audience to understand if I put some words in change log.

Quoted 6 lines

The impact of this patch is it would accelerate the searching process when there are many memory ranges in memblock.

For example, in the case https://lkml.org/lkml/2018/3/25/291, there are around 30 memory ranges on node 0. The original code need to iterate all those ranges to find the minimal pfn, while after optimization it just need once.

Then show us some numbers to justify the change.

Signature · 2 lines
Michal Hocko
SUSE Labs
Acked-by on v1 1/1
#10 lore raw

Re: [PATCH] mm/page_alloc: optimize find_min_pfn_for_node() by geting the minimal pfn directly

In reply to Wei Yang

On Wed 28-03-18 11:47:52, Wei Yang wrote:
[...]

include/linux/memblock.h void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, · line 200

Quoted 9 lines
include/linux/memblock.h +9 -0
+/**
+ * first_mem_pfn - get the first memory pfn
+ * @i: an integer used as an indicator
+ * @nid: node selector, %MAX_NUMNODES for all nodes
+ * @p_first: ptr to ulong for first pfn of the range, can be %NULL
+ */
+#define first_mem_pfn(i, nid, p_first)				\
+	__next_mem_pfn_range(&i, nid, p_first, NULL, NULL)
+

Is this really something that we want to export to all users? And if that is the case is the documenation really telling user how to use it?

Quoted 20 lines

/**
* for_each_mem_pfn_range - early memory pfn range iterator
* @i: an integer used as loop variable

mm/page_alloc.c +3 -5
index 635d7dd29d7f..8c964dcc3a9e 100644
@@ -6365,14 +6365,16 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
-	int i;
+	unsigned long min_pfn;
+	int i = -1;
 
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	/*

mm/page_alloc.c unsigned long __init node_map_pfn_alignment(void) · line 6380

Quoted 10 lines
mm/page_alloc.c +5 -1
+	 * The first pfn on nid node is the minimal one, as the pfn's are
+	 * stored in ascending order.
+	 */
+	first_mem_pfn(i, nid, &min_pfn);
 
-	if (min_pfn == ULONG_MAX) {
+	if (i == -1) {
 		pr_warn("Could not find start_pfn for node %d\n", nid);
 		return 0;
 	}

I would just open code it. Other than that I strongly suspect this will not have any measurable impact becauser we usually only have handfull of memory ranges but why not. Just make the new implementation less ugly than it is cuurrently - e.g. opencode first_mem_pfn and you can add

Signature · 2 lines
Michal Hocko
SUSE Labs
author
#4 lore raw
In reply to Michal Hocko
Quoted 16 lines · Michal Hocko
Quoted 15 lines · Wei Yang
Quoted 9 lines · Michal Hocko
Quoted 3 lines · Wei Yang

find_min_pfn_for_node() iterate on pfn range to find the minimum pfn for a node. The memblock_region in memblock_type are already ordered, which means the first hit in iteration is the minimum pfn.

I haven't looked at the code yet but the changelog should contain the motivation why it exists. It seems like this is an optimization. If so, what is the impact?

Yep, this is a trivial optimization on searching the minimal pfn on a special node. It would be better for audience to understand if I put some words in change log.

Quoted 8 lines
Quoted 6 lines

The impact of this patch is it would accelerate the searching process when there are many memory ranges in memblock.

For example, in the case https://lkml.org/lkml/2018/3/25/291, there are around 30 memory ranges on node 0. The original code need to iterate all those ranges to find the minimal pfn, while after optimization it just need once.

Then show us some numbers to justify the change.

Oops, I don't have any data to prove this.

My test machine just has 7 memory regions and only one node. So it reduce iteration from 7 to 1, which I don't think will have some visible effect.

While we can do some calculation to estimate the effect.

Assume there are N memory regions and M nodes and each node has equal number of memory regions.

So before the change, there are

N * M iterations

After this optimization, there are

(N / 2) * M iterations

So the expected improvement of this change is half the iterations for finding the minimal pfn.

Last but not the least, as I know, usually there are less than 100 memory regions on a machine. This improvement is really limited on current systems. The more memory regions and node a system has, the more improvement it will has.

Quoted 3 lines
Signature · 2 lines
Michal Hocko
SUSE Labs
Signature · 2 lines
Wei Yang
Help you, Help me
author
#11 lore raw

Re: [PATCH] mm/page_alloc: optimize find_min_pfn_for_node() by geting the minimal pfn directly

In reply to Michal Hocko
Quoted 15 lines · Michal Hocko

On Wed 28-03-18 11:47:52, Wei Yang wrote:
[...]

include/linux/memblock.h void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, · line 200

Quoted 9 lines
include/linux/memblock.h +9 -0
+/**
+ * first_mem_pfn - get the first memory pfn
+ * @i: an integer used as an indicator
+ * @nid: node selector, %MAX_NUMNODES for all nodes
+ * @p_first: ptr to ulong for first pfn of the range, can be %NULL
+ */
+#define first_mem_pfn(i, nid, p_first)				\
+	__next_mem_pfn_range(&i, nid, p_first, NULL, NULL)
+

Is this really something that we want to export to all users? And if that is the case is the documenation really telling user how to use it?

Yep, I am not good at the documentation. I really struggled a while on it, but you know it still looks not that good.

How about changing the document to the following in case this macro is still alive.

/**
* first_mem_pfn - get the first memory pfn after index i on node nid
* @i: index to memblock.memory.regions
* @nid: node selector, %MAX_NUMNODES for all nodes
* @p_first: ptr to ulong for first pfn of the range, can be %NULL */

Quoted 25 lines
Quoted 25 lines

/**
* for_each_mem_pfn_range - early memory pfn range iterator
* @i: an integer used as loop variable

mm/page_alloc.c +7 -5
index 635d7dd29d7f..8c964dcc3a9e 100644
@@ -6365,14 +6365,16 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
-	int i;
+	unsigned long min_pfn;
+	int i = -1;
 
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	/*
+	 * The first pfn on nid node is the minimal one, as the pfn's are
+	 * stored in ascending order.
+	 */
+	first_mem_pfn(i, nid, &min_pfn);
 
Quoted 10 lines

mm/page_alloc.c unsigned long __init node_map_pfn_alignment(void) · line 6380

Quoted 5 lines
mm/page_alloc.c +1 -1
-	if (min_pfn == ULONG_MAX) {
+	if (i == -1) {
 		pr_warn("Could not find start_pfn for node %d\n", nid);
 		return 0;
 	}

I would just open code it. Other than that I strongly suspect this will not have any measurable impact becauser we usually only have handfull of memory ranges but why not. Just make the new implementation less ugly than it is cuurrently - e.g. opencode first_mem_pfn and you can add

Open code here means use __next_mem_pfn_range() directly instead of using first_mem_pfn()?

Quoted 4 lines
Signature · 2 lines
Michal Hocko
SUSE Labs
Signature · 2 lines
Wei Yang
Help you, Help me
#12 lore raw

Re: [PATCH] mm/page_alloc: optimize find_min_pfn_for_node() by geting the minimal pfn directly

Quoted 3 lines · Wei Yang
Quoted 2 lines · Michal Hocko

On Wed 28-03-18 11:47:52, Wei Yang wrote:
[...]

[...]

Quoted 29 lines
Quoted 18 lines
Quoted 18 lines
mm/page_alloc.c +7 -5
@@ -6365,14 +6365,16 @@ unsigned long __init node_map_pfn_alignment(void)
 /* Find the lowest pfn for a node */
 static unsigned long __init find_min_pfn_for_node(int nid)
 {
-	unsigned long min_pfn = ULONG_MAX;
-	unsigned long start_pfn;
-	int i;
+	unsigned long min_pfn;
+	int i = -1;
 
-	for_each_mem_pfn_range(i, nid, &start_pfn, NULL, NULL)
-		min_pfn = min(min_pfn, start_pfn);
+	/*
+	 * The first pfn on nid node is the minimal one, as the pfn's are
+	 * stored in ascending order.
+	 */
+	first_mem_pfn(i, nid, &min_pfn);
 
Quoted 10 lines

mm/page_alloc.c unsigned long __init node_map_pfn_alignment(void) · line 6380

Quoted 5 lines
mm/page_alloc.c +1 -1
-	if (min_pfn == ULONG_MAX) {
+	if (i == -1) {
 		pr_warn("Could not find start_pfn for node %d\n", nid);
 		return 0;
 	}

I would just open code it. Other than that I strongly suspect this will not have any measurable impact becauser we usually only have handfull of memory ranges but why not. Just make the new implementation less ugly than it is cuurrently - e.g. opencode first_mem_pfn and you can add

Quoted 2 lines

Open code here means use __next_mem_pfn_range() directly instead of using first_mem_pfn()?

Yes with the comment explaining how we rely on sorted ranges the way you did.

Signature · 2 lines
Michal Hocko
SUSE Labs