Skip to contentSkip to conversation

mm/sparse: pass the __highest_present_section_nr + 1 to alloc_func()

PATCH In review Wei Yang 2 participants 10 messages Mar 26, 2018 – Apr 12, 2018

Subsystems (4)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/2 mm/sparse: pass the __highest_present_section_nr + 1 to alloc_func()

In 'commit c4e1be9ec113 ("mm, sparsemem: break out of loops early")', __highest_present_section_nr is introduced to reduce the loop counts for present section. This is also helpful for usemap and memmap allocation.

This patch uses __highest_present_section_nr + 1 to optimize the loop.

---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c +1 -1
index 7af5e7a92528..505050346249 100644
@@ -561,7 +561,7 @@ static void __init alloc_usemap_and_memmap(void (*alloc_func)
 		map_count = 1;
 	}
 	/* ok, last chunk */
-	alloc_func(data, pnum_begin, NR_MEM_SECTIONS,
+	alloc_func(data, pnum_begin, __highest_present_section_nr+1,
 						map_count, nodeid_begin);
 }
 
Signature · 1 line
2.15.1
author
#1 lore raw

PATCH 2/2 mm/sparse: check __highest_present_section_nr only for a present section

When searching a present section, there are two boundaries:

* __highest_present_section_nr
* NR_MEM_SECTIONS

And it is konwn, __highest_present_section_nr is a more strict boundary than NR_MEM_SECTIONS. This means it would be necessary to check __highest_present_section_nr only.

---
 mm/sparse.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/sparse.c +1 -3
index 505050346249..b6560029a16c 100644
@@ -190,15 +190,13 @@ static inline int next_present_section_nr(int section_nr)
 		section_nr++;
 		if (present_section_nr(section_nr))
 			return section_nr;
-	} while ((section_nr < NR_MEM_SECTIONS) &&
-		 (section_nr <= __highest_present_section_nr));
+	} while ((section_nr <= __highest_present_section_nr));
 
 	return -1;
 }
 #define for_each_present_section_nr(start, section_nr)		\
 	for (section_nr = next_present_section_nr(start-1);	\
 	     ((section_nr >= 0) &&				\
-	      (section_nr < NR_MEM_SECTIONS) &&			\
 	      (section_nr <= __highest_present_section_nr));	\
 	     section_nr = next_present_section_nr(section_nr))
 
Signature · 1 line
2.15.1
#3 lore raw
In reply to Wei Yang
Quoted 16 lines · Wei Yang

In 'commit c4e1be9ec113 ("mm, sparsemem: break out of loops early")', __highest_present_section_nr is introduced to reduce the loop counts for present section. This is also helpful for usemap and memmap allocation.

This patch uses __highest_present_section_nr + 1 to optimize the loop.

---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c +0 -0
index 7af5e7a92528..505050346249 100644

mm/sparse.c static void __init alloc_usemap_and_memmap(void (*alloc_func) · line 567

Quoted 8 lines
mm/sparse.c +1 -1
@@ -561,7 +561,7 @@ static void __init alloc_usemap_and_memmap(void (*alloc_func)
 		map_count = 1;
 	}
 	/* ok, last chunk */
-	alloc_func(data, pnum_begin, NR_MEM_SECTIONS,
+	alloc_func(data, pnum_begin, __highest_present_section_nr+1,
 						map_count, nodeid_begin);
 }
 

What happens if s/NR_MEM_SECTIONS/pnum/?

author
#4 lore raw
Quoted 13 lines · David Rientjes
Quoted 11 lines · Wei Yang

In 'commit c4e1be9ec113 ("mm, sparsemem: break out of loops early")', __highest_present_section_nr is introduced to reduce the loop counts for present section. This is also helpful for usemap and memmap allocation.

This patch uses __highest_present_section_nr + 1 to optimize the loop.

---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

mm/sparse.c static void __init alloc_usemap_and_memmap(void (*alloc_func) · line 567

Quoted 13 lines
mm/sparse.c +1 -1
index 7af5e7a92528..505050346249 100644
@@ -561,7 +561,7 @@ static void __init alloc_usemap_and_memmap(void (*alloc_func)
 		map_count = 1;
 	}
 	/* ok, last chunk */
-	alloc_func(data, pnum_begin, NR_MEM_SECTIONS,
+	alloc_func(data, pnum_begin, __highest_present_section_nr+1,
 						map_count, nodeid_begin);
 }
 

What happens if s/NR_MEM_SECTIONS/pnum/?

I have tried this :-)

The last pnum is -1 from next_present_section_nr().

Signature · 2 lines
Wei Yang
Help you, Help me
#5 lore raw
Quoted 27 lines · Wei Yang
Quoted 11 lines
Quoted 11 lines

In 'commit c4e1be9ec113 ("mm, sparsemem: break out of loops early")', __highest_present_section_nr is introduced to reduce the loop counts for present section. This is also helpful for usemap and memmap allocation.

This patch uses __highest_present_section_nr + 1 to optimize the loop.

---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

mm/sparse.c static void __init alloc_usemap_and_memmap(void (*alloc_func) · line 567

Quoted 13 lines
mm/sparse.c +1 -1
index 7af5e7a92528..505050346249 100644
@@ -561,7 +561,7 @@ static void __init alloc_usemap_and_memmap(void (*alloc_func)
 		map_count = 1;
 	}
 	/* ok, last chunk */
-	alloc_func(data, pnum_begin, NR_MEM_SECTIONS,
+	alloc_func(data, pnum_begin, __highest_present_section_nr+1,
 						map_count, nodeid_begin);
 }
 

What happens if s/NR_MEM_SECTIONS/pnum/?

Quoted 4 lines

I have tried this :-)

The last pnum is -1 from next_present_section_nr().

Lol. I think it would make more sense for the second patch to come before the first, but feel free to add

author
#6 lore raw
Quoted 29 lines · David Rientjes
Quoted 27 lines · Wei Yang
Quoted 26 lines
Quoted 16 lines

In 'commit c4e1be9ec113 ("mm, sparsemem: break out of loops early")', __highest_present_section_nr is introduced to reduce the loop counts for present section. This is also helpful for usemap and memmap allocation.

This patch uses __highest_present_section_nr + 1 to optimize the loop.

---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c +0 -0
index 7af5e7a92528..505050346249 100644

mm/sparse.c static void __init alloc_usemap_and_memmap(void (*alloc_func) · line 567

Quoted 8 lines
mm/sparse.c +1 -1
@@ -561,7 +561,7 @@ static void __init alloc_usemap_and_memmap(void (*alloc_func)
 		map_count = 1;
 	}
 	/* ok, last chunk */
-	alloc_func(data, pnum_begin, NR_MEM_SECTIONS,
+	alloc_func(data, pnum_begin, __highest_present_section_nr+1,
 						map_count, nodeid_begin);
 }
 

What happens if s/NR_MEM_SECTIONS/pnum/?

Quoted 8 lines
Quoted 4 lines

I have tried this :-)

The last pnum is -1 from next_present_section_nr().

Lol. I think it would make more sense for the second patch to come before the first, but feel free to add

Thanks for your comment.

Do I need to reorder the patch and send v2?

Quoted 1 line
Signature · 2 lines
Wei Yang
Help you, Help me
#7 lore raw
Quoted 7 lines · Wei Yang
Quoted 2 lines

Lol. I think it would make more sense for the second patch to come before the first

Thanks for your comment.

Do I need to reorder the patch and send v2?

I think we can just ask Andrew to apply backwards, but it's not crucial. The ordering of patch 2 before patch 1 simply helped me to understand the boundaries better.

author
#8 lore raw
Quoted 5 lines · David Rientjes
Quoted 3 lines · Wei Yang
Quoted 2 lines

Lol. I think it would make more sense for the second patch to come before the first

Quoted 8 lines
Quoted 4 lines

Thanks for your comment.

Do I need to reorder the patch and send v2?

I think we can just ask Andrew to apply backwards, but it's not crucial. The ordering of patch 2 before patch 1 simply helped me to understand the boundaries better.

Ah, got it.

Actually, the original order is what you expected. While for some mysterious reasons, I reordered them :-(

Maybe you are right, it would be more easy to understand with patch 2 before patch 1. :-)

Have a good day~

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

PATCH 1/1 mm: check __highest_present_sectioin_nr directly in memory_dev_init()

In reply to Wei Yang

__highest_present_section_nr is a more strict boundary than NR_MEM_SECTIONS. So check __highest_present_sectioin_nr directly is enough.

---
 drivers/base/memory.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/base/memory.c +2 -5
index fe4b24f05f6a..e79e3361f632 100644
@@ -833,11 +833,8 @@ int __init memory_dev_init(void)
 	 * during boot and have been initialized
 	 */
 	mutex_lock(&mem_sysfs_mutex);
-	for (i = 0; i < NR_MEM_SECTIONS; i += sections_per_block) {
-		/* Don't iterate over sections we know are !present: */
-		if (i > __highest_present_section_nr)
-			break;
-
+	for (i = 0; i <= __highest_present_section_nr;
+		i += sections_per_block) {
 		err = add_memory_block(i);
 		if (!ret)
 			ret = err;
Signature · 1 line
2.15.1
author
#9 lore raw
In reply to Wei Yang

Hi, Andrew

I saw you merged one related patch recently, not sure you would take these two?

Quoted 26 lines · Wei Yang

In 'commit c4e1be9ec113 ("mm, sparsemem: break out of loops early")', __highest_present_section_nr is introduced to reduce the loop counts for present section. This is also helpful for usemap and memmap allocation.

This patch uses __highest_present_section_nr + 1 to optimize the loop.

---
mm/sparse.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c +1 -1
index 7af5e7a92528..505050346249 100644
@@ -561,7 +561,7 @@ static void __init alloc_usemap_and_memmap(void (*alloc_func)
 		map_count = 1;
 	}
 	/* ok, last chunk */
-	alloc_func(data, pnum_begin, NR_MEM_SECTIONS,
+	alloc_func(data, pnum_begin, __highest_present_section_nr+1,
 						map_count, nodeid_begin);
 }
 
Signature · 1 line
2.15.1
Signature · 2 lines
Wei Yang
Help you, Help me