Skip to contentSkip to conversation

mm: make __paginginit based on CONFIG_MEMORY_HOTPLUG

PATCH In review [email protected] 3 participants 15 messages Jul 31, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: make __paginginit based on CONFIG_MEMORY_HOTPLUG

From: Oscar Salvador <[email protected]>

__pagininit macro is being used to mark functions for:

a) Functions that we do not need to keep once the system is fully initialized with regard to memory.
b) Functions that will be needed for the memory-hotplug code, and because of that we need to keep them after initialization.

Right now, the condition to choose between one or the other is based on CONFIG_SPARSEMEM, but I think that this should be changed to be based on CONFIG_MEMORY_HOTPLUG.

The reason behind this is that it can very well be that we have CONFIG_SPARSEMEM enabled, but not CONFIG_MEMORY_HOTPLUG, and thus, we will not need the functions marked as __paginginit to stay around, since no memory-hotplug code will call them.

Although the amount of freed bytes is not that big, I think it will become more clear what __paginginit is used for.

---
 mm/internal.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/internal.h +4 -3
index 33c22754d282..c9170b4f7699 100644
@@ -392,10 +392,11 @@ static inline struct page *mem_map_next(struct page *iter,
 /*
  * FLATMEM and DISCONTIGMEM configurations use alloc_bootmem_node,
  * so all functions starting at paging_init should be marked __init
- * in those cases. SPARSEMEM, however, allows for memory hotplug,
- * and alloc_bootmem_node is not used.
+ * in those cases.
+ * In case that MEMORY_HOTPLUG is enabled, we need to keep those
+ * functions around since they can be called when hot-adding memory.
  */
-#ifdef CONFIG_SPARSEMEM
+#ifdef CONFIG_MEMORY_HOTPLUG
 #define __paginginit __meminit
 #else
 #define __paginginit __init
Signature · 1 line
2.13.6
#1 lore raw

Hi Oscar,

Have you looked into replacing __paginginit via __meminit ? What is the reason to keep both?

Thank you,
Pavel

Quoted 49 lines · On Tue, Jul 31, 2018 at 8:45 AM <[email protected]> wrote:

From: Oscar Salvador <[email protected]>

__pagininit macro is being used to mark functions for:

a) Functions that we do not need to keep once the system is fully initialized with regard to memory.
b) Functions that will be needed for the memory-hotplug code, and because of that we need to keep them after initialization.

Right now, the condition to choose between one or the other is based on CONFIG_SPARSEMEM, but I think that this should be changed to be based on CONFIG_MEMORY_HOTPLUG.

The reason behind this is that it can very well be that we have CONFIG_SPARSEMEM enabled, but not CONFIG_MEMORY_HOTPLUG, and thus, we will not need the functions marked as __paginginit to stay around, since no memory-hotplug code will call them.

Although the amount of freed bytes is not that big, I think it will become more clear what __paginginit is used for.

---
 mm/internal.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
mm/internal.h +4 -4
index 33c22754d282..c9170b4f7699 100644
@@ -392,10 +392,11 @@ static inline struct page *mem_map_next(struct page *iter,
 /*
  * FLATMEM and DISCONTIGMEM configurations use alloc_bootmem_node,
  * so all functions starting at paging_init should be marked __init
- * in those cases. SPARSEMEM, however, allows for memory hotplug,
- * and alloc_bootmem_node is not used.
+ * in those cases.
+ * In case that MEMORY_HOTPLUG is enabled, we need to keep those
+ * functions around since they can be called when hot-adding memory.
  */
-#ifdef CONFIG_SPARSEMEM
+#ifdef CONFIG_MEMORY_HOTPLUG
 #define __paginginit __meminit
 #else
 #define __paginginit __init
--

2.13.6

#2 lore raw
Quoted 4 lines · Pavel Tatashin

Hi Oscar,

Have you looked into replacing __paginginit via __meminit ? What is the reason to keep both?

All these init variants make my head spin so reducing their number is certainly a desirable thing to do. b5a0e01132943 has added this variant so it might give a clue about the dependencies.

Signature · 2 lines
Michal Hocko
SUSE Labs
#3 lore raw
Quoted 9 lines · Michal Hocko
Quoted 4 lines · Pavel Tatashin

Hi Oscar,

Have you looked into replacing __paginginit via __meminit ? What is the reason to keep both?

All these init variants make my head spin so reducing their number is certainly a desirable thing to do. b5a0e01132943 has added this variant so it might give a clue about the dependencies.

Looking at b5a0e011329431b90d315eaf6ca5fdb41df7a117, I cannot really see why this was not done in init.h
Maybe the comitter did not want to hack directly into __meminit.

I think that __paginginit was a way to abstract the whole thing without having to modify init.h directly.

I guess we could get rid of it and so something like:

#ifdef CONFIG_MEMORY_HOTPLUG
#define __meminit __section(.meminit.text) __cold notrace \
__latent_entropy
#else
#define __meminit __init
#endif

And then we would have to replace __paginginit with __meminit.

But honestly, puting an #ifdef in init.h feels a bit wierd to me, although I do not really have a strong opinion here.

Thanks

Signature · 2 lines
Oscar Salvador
SUSE L3
#4 lore raw
In reply to Pavel Tatashin
Quoted 4 lines · Pavel Tatashin

Hi Oscar,

Have you looked into replacing __paginginit via __meminit ? What is the reason to keep both?

Hi Pavel,

Actually, thinking a bit more about this, it might make sense to remove __paginginit altogether and keep only __meminit.
Looking at the original commit, I think that it was put as a way to abstract it.

After the patchset [1] has been applied, only two functions marked as __paginginit remain, so it will be less hassle to replace that with __meminit.

I will send a v2 tomorrow to be applied on top of [1].

[1] https://patchwork.kernel.org/patch/10548861/

Thanks

Signature · 2 lines
Oscar Salvador
SUSE L3
#5 lore raw

Hi Oscar,

There is a simpler way. I will send it out in a bit. No need for your first function, only setup_usemap() needs to be changed to __ref.

Pavel

Quoted 24 lines · Oscar Salvador
Quoted 4 lines · Pavel Tatashin

Hi Oscar,

Have you looked into replacing __paginginit via __meminit ? What is the reason to keep both?

Hi Pavel,

Actually, thinking a bit more about this, it might make sense to remove __paginginit altogether and keep only __meminit.
Looking at the original commit, I think that it was put as a way to abstract it.

After the patchset [1] has been applied, only two functions marked as __paginginit remain, so it will be less hassle to replace that with __meminit.

I will send a v2 tomorrow to be applied on top of [1].

[1] https://patchwork.kernel.org/patch/10548861/

Thanks
--
Oscar Salvador
SUSE L3

#6 lore raw
Quoted 4 lines · Pavel Tatashin

Hi Oscar,

There is a simpler way. I will send it out in a bit. No need for your first function, only setup_usemap() needs to be changed to __ref.

I meant first patch not function :)

Quoted 27 lines

Pavel

Quoted 24 lines · Oscar Salvador
Quoted 4 lines · Pavel Tatashin

Hi Oscar,

Have you looked into replacing __paginginit via __meminit ? What is the reason to keep both?

Hi Pavel,

Actually, thinking a bit more about this, it might make sense to remove __paginginit altogether and keep only __meminit.
Looking at the original commit, I think that it was put as a way to abstract it.

After the patchset [1] has been applied, only two functions marked as __paginginit remain, so it will be less hassle to replace that with __meminit.

I will send a v2 tomorrow to be applied on top of [1].

[1] https://patchwork.kernel.org/patch/10548861/

Thanks
--
Oscar Salvador
SUSE L3

#7 lore raw
In reply to Oscar Salvador
Quoted 11 lines · Oscar Salvador
Quoted 4 lines · Pavel Tatashin

Hi Oscar,

Have you looked into replacing __paginginit via __meminit ? What is the reason to keep both?

Hi Pavel,

Actually, thinking a bit more about this, it might make sense to remove __paginginit altogether and keep only __meminit.
Looking at the original commit, I think that it was put as a way to abstract it.

Quoted 12 lines

After the patchset [1] has been applied, only two functions marked as __paginginit remain, so it will be less hassle to replace that with __meminit.

I will send a v2 tomorrow to be applied on top of [1].

[1] https://patchwork.kernel.org/patch/10548861/

Thanks

Signature · 2 lines
Oscar Salvador
SUSE L3

Here the patch would look like this:

#8 lore raw
Quoted 7 lines · Pavel Tatashin

Here the patch would look like this:

From e640b32dbd329bba5a785cc60050d5d7e1ca18ce Mon Sep 17 00:00:00 2001
From: Pavel Tatashin <[email protected]>
Date: Tue, 31 Jul 2018 10:37:44 -0400
Subject: [PATCH] mm: remove __paginginit

Quoted 7 lines

__paginginit is the same thing as __meminit except for platforms without sparsemem, there it is defined as __init.

Remove __paginginit and use __meminit. Use __ref in one single function that merges __meminit and __init sections: setup_usemap().

Uhm, I am probably missing something, but with this change, the functions will not be freed up while freeing init memory, right?

Thanks

Signature · 2 lines
Oscar Salvador
SUSE L3
#9 lore raw

Thats correct on arches where no sparsemem setup_usemap() will not be freed up. It is a tiny function, just a few instructions. Not a big deal.

Pavel

Quoted 25 lines · Oscar Salvador
Quoted 7 lines · Pavel Tatashin

Here the patch would look like this:

From e640b32dbd329bba5a785cc60050d5d7e1ca18ce Mon Sep 17 00:00:00 2001
From: Pavel Tatashin <[email protected]>
Date: Tue, 31 Jul 2018 10:37:44 -0400
Subject: [PATCH] mm: remove __paginginit

Quoted 7 lines

__paginginit is the same thing as __meminit except for platforms without sparsemem, there it is defined as __init.

Remove __paginginit and use __meminit. Use __ref in one single function that merges __meminit and __init sections: setup_usemap().

Uhm, I am probably missing something, but with this change, the functions will not be freed up while freeing init memory, right?

Thanks
--
Oscar Salvador
SUSE L3

#10 lore raw
Quoted 22 lines · Pavel Tatashin

Thats correct on arches where no sparsemem setup_usemap() will not be freed up. It is a tiny function, just a few instructions. Not a big deal.

Pavel

Quoted 15 lines · Oscar Salvador
Quoted 13 lines · Pavel Tatashin

Here the patch would look like this:

From e640b32dbd329bba5a785cc60050d5d7e1ca18ce Mon Sep 17 00:00:00 2001
From: Pavel Tatashin <[email protected]>
Date: Tue, 31 Jul 2018 10:37:44 -0400
Subject: [PATCH] mm: remove __paginginit

__paginginit is the same thing as __meminit except for platforms without sparsemem, there it is defined as __init.

Remove __paginginit and use __meminit. Use __ref in one single function that merges __meminit and __init sections: setup_usemap().

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Uhm, I am probably missing something, but with this change, the functions will not be freed up while freeing init memory, right?

Thats correct on arches where no sparsemem setup_usemap() will not be freed up. It is a tiny function, just a few instructions. Not a big deal.

I must be missing something.

What about:

calc_memmap_size
free_area_init_node
free_area_init_core

These functions are marked with __meminit now.
If we have CONFIG_PARSEMEM but not CONFIG_MEMORY_HOTPLUG, these functions will be left there.

I mean, it is not that it is a big amount, but still.

Do not we need something like:

include/linux/init.h +4 -0
index 2538d176dd1f..3b3a88ba80ed 100644
@@ -83,8 +83,12 @@
 #define __exit          __section(.exit.text) __exitused __cold notrace
 
 /* Used for MEMORY_HOTPLUG */
+#ifdef CONFIG_MEMORY_HOTPLUG
 #define __meminit        __section(.meminit.text) __cold notrace \
 						  __latent_entropy
+#else
+#define __meminit	 __init
+#endif
 #define __meminitdata    __section(.meminit.data)
 #define __meminitconst   __section(.meminit.rodata)
 #define __memexit        __section(.memexit.text) __exitused __cold notrace

on top?

Thanks

Signature · 2 lines
Oscar Salvador
SUSE L3
#11 lore raw
Quoted 36 lines · Oscar Salvador
Quoted 22 lines · Pavel Tatashin

Thats correct on arches where no sparsemem setup_usemap() will not be freed up. It is a tiny function, just a few instructions. Not a big deal.

Pavel

Quoted 15 lines · Oscar Salvador
Quoted 13 lines · Pavel Tatashin

Here the patch would look like this:

From e640b32dbd329bba5a785cc60050d5d7e1ca18ce Mon Sep 17 00:00:00 2001
From: Pavel Tatashin <[email protected]>
Date: Tue, 31 Jul 2018 10:37:44 -0400
Subject: [PATCH] mm: remove __paginginit

__paginginit is the same thing as __meminit except for platforms without sparsemem, there it is defined as __init.

Remove __paginginit and use __meminit. Use __ref in one single function that merges __meminit and __init sections: setup_usemap().

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Uhm, I am probably missing something, but with this change, the functions will not be freed up while freeing init memory, right?

Thats correct on arches where no sparsemem setup_usemap() will not be freed up. It is a tiny function, just a few instructions. Not a big deal.

I must be missing something.

What about:

Quoted 7 lines

calc_memmap_size
free_area_init_node
free_area_init_core

These functions are marked with __meminit now.
If we have CONFIG_PARSEMEM but not CONFIG_MEMORY_HOTPLUG, these functions will be left there.

I hope we free meminit section if no hotplug configured. If not, than sure we should have something like what you suggest not only for these functions, but for all other meminit functions in kernel.

Quoted 30 lines

I mean, it is not that it is a big amount, but still.

Do not we need something like:

include/linux/init.h +4 -0
index 2538d176dd1f..3b3a88ba80ed 100644
@@ -83,8 +83,12 @@
 #define __exit          __section(.exit.text) __exitused __cold notrace
 
 /* Used for MEMORY_HOTPLUG */
+#ifdef CONFIG_MEMORY_HOTPLUG
 #define __meminit        __section(.meminit.text) __cold notrace \
                                                  __latent_entropy
+#else
+#define __meminit       __init
+#endif
 #define __meminitdata    __section(.meminit.data)
 #define __meminitconst   __section(.meminit.rodata)
 #define __memexit        __section(.memexit.text) __exitused __cold notrace

on top?

Thanks
--
Oscar Salvador
SUSE L3

#12 lore raw

Yes we free meminit when no CONFIG_MEMORY_HOTPLUG
See here:
http://src.illumos.org/source/xref/linux-master/include/asm-generic/vmlinux.lds.h#107

Pavel

Quoted 81 lines · Pavel Tatashin
Quoted 36 lines · Oscar Salvador
Quoted 22 lines · Pavel Tatashin

Thats correct on arches where no sparsemem setup_usemap() will not be freed up. It is a tiny function, just a few instructions. Not a big deal.

Pavel

Quoted 15 lines · Oscar Salvador
Quoted 13 lines · Pavel Tatashin

Here the patch would look like this:

From e640b32dbd329bba5a785cc60050d5d7e1ca18ce Mon Sep 17 00:00:00 2001
From: Pavel Tatashin <[email protected]>
Date: Tue, 31 Jul 2018 10:37:44 -0400
Subject: [PATCH] mm: remove __paginginit

__paginginit is the same thing as __meminit except for platforms without sparsemem, there it is defined as __init.

Remove __paginginit and use __meminit. Use __ref in one single function that merges __meminit and __init sections: setup_usemap().

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Uhm, I am probably missing something, but with this change, the functions will not be freed up while freeing init memory, right?

Thats correct on arches where no sparsemem setup_usemap() will not be freed up. It is a tiny function, just a few instructions. Not a big deal.

I must be missing something.

What about:

Quoted 7 lines

calc_memmap_size
free_area_init_node
free_area_init_core

These functions are marked with __meminit now.
If we have CONFIG_PARSEMEM but not CONFIG_MEMORY_HOTPLUG, these functions will be left there.

I hope we free meminit section if no hotplug configured. If not, than sure we should have something like what you suggest not only for these functions, but for all other meminit functions in kernel.

Quoted 30 lines

I mean, it is not that it is a big amount, but still.

Do not we need something like:

include/linux/init.h +4 -0
index 2538d176dd1f..3b3a88ba80ed 100644
@@ -83,8 +83,12 @@
 #define __exit          __section(.exit.text) __exitused __cold notrace
 
 /* Used for MEMORY_HOTPLUG */
+#ifdef CONFIG_MEMORY_HOTPLUG
 #define __meminit        __section(.meminit.text) __cold notrace \
                                                  __latent_entropy
+#else
+#define __meminit       __init
+#endif
 #define __meminitdata    __section(.meminit.data)
 #define __meminitconst   __section(.meminit.rodata)
 #define __memexit        __section(.memexit.text) __exitused __cold notrace

on top?

Thanks
--
Oscar Salvador
SUSE L3

#13 lore raw
Quoted 3 lines · Pavel Tatashin

Yes we free meminit when no CONFIG_MEMORY_HOTPLUG
See here:
http://src.illumos.org/source/xref/linux-master/include/asm-generic/vmlinux.lds.h#107

Oh, I got the point now.
Somehow I missed that we were freeing up the memory when CONFIG_MEMORY_HOTPLUG was not in place.

So your patch makes sense to me now, sorry.

Since my patchset [1] + cleanup patch [2] remove almost all __paginginit, leaving only pgdat_init_internals() and zone_init_internals(), I think it would be great if you base your patch on top of that.
Or since the patchset has some cleanups already, I could add your patch into it (as we did for the zone_to/set_nid() patch) and send a v6 with it.

What do you think?

[1] https://patchwork.kernel.org/patch/10548861/
[2] <[email protected]>

Thanks

Signature · 2 lines
Oscar Salvador
SUSE L3
#14 lore raw
Quoted 11 lines · Oscar Salvador
Quoted 3 lines · Pavel Tatashin

Yes we free meminit when no CONFIG_MEMORY_HOTPLUG
See here:
http://src.illumos.org/source/xref/linux-master/include/asm-generic/vmlinux.lds.h#107

Oh, I got the point now.
Somehow I missed that we were freeing up the memory when CONFIG_MEMORY_HOTPLUG was not in place.

So your patch makes sense to me now, sorry.

Quoted 7 lines

Since my patchset [1] + cleanup patch [2] remove almost all __paginginit, leaving only pgdat_init_internals() and zone_init_internals(), I think it would be great if you base your patch on top of that.
Or since the patchset has some cleanups already, I could add your patch into it (as we did for the zone_to/set_nid() patch) and send a v6 with it.

What do you think?

Sure, please go ahead include it in v6. Let me know if you need any help. Thank you for this work, I really like how this improves hotplug/memory-init code.

Pavel

Quoted 6 lines

[1] https://patchwork.kernel.org/patch/10548861/
[2] <[email protected]>

Thanks