When CONFIG_ARCH_KEEP_MEMBLOCK not set, we expect to discard related
code and data. But it doesn't until CONFIG_MEMORY_HOTPLUG not set
neither.
This patch puts memblock's .text/.data into its own section, so that it
only depends on CONFIG_ARCH_KEEP_MEMBLOCK to discard related code and
data. After this, init size increase from 2420K to 2432K.
Signed-off-by: Wei Yang <[email protected]>
---
include/asm-generic/vmlinux.lds.h | 14 +++++++++++++-
include/linux/memblock.h | 8 ++++----
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index f7749d0f2562..775c5eedb9e6 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -147,6 +147,14 @@
#define MEM_DISCARD(sec) *(.mem##sec)
#endif
+#if defined(CONFIG_ARCH_KEEP_MEMBLOCK)
+#define MEMBLOCK_KEEP(sec) *(.mb##sec)
+#define MEMBLOCK_DISCARD(sec)
+#else
+#define MEMBLOCK_KEEP(sec)
+#define MEMBLOCK_DISCARD(sec) *(.mb##sec)
+#endif
+
#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
#define KEEP_PATCHABLE KEEP(*(__patchable_function_entries))
#define PATCHABLE_DISCARDS
@@ -356,6 +364,7 @@
*(.ref.data) \
*(.data..shared_aligned) /* percpu related */ \
MEM_KEEP(init.data*) \
+ MEMBLOCK_KEEP(init.data*) \
*(.data.unlikely) \
__start_once = .; \
*(.data.once) \
@@ -573,6 +582,7 @@
*(.ref.text) \
*(.text.asan.* .text.tsan.*) \
MEM_KEEP(init.text*) \
+ MEMBLOCK_KEEP(init.text*) \
/* sched.text is aling to function alignment to secure we have same
@@ -680,6 +690,7 @@
KEEP(*(SORT(___kentry+*))) \
*(.init.data .init.data.*) \
MEM_DISCARD(init.data*) \
+ MEMBLOCK_DISCARD(init.data*) \
KERNEL_CTORS() \
MCOUNT_REC() \
*(.init.rodata .init.rodata.*) \
@@ -706,7 +717,8 @@
#define INIT_TEXT \
*(.init.text .init.text.*) \
*(.text.startup) \
- MEM_DISCARD(init.text*)
+ MEM_DISCARD(init.text*) \
+ MEMBLOCK_DISCARD(init.text*)
#define EXIT_DATA \
*(.exit.data .exit.data.*) \
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index e2082240586d..3e1f1d42dde7 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -100,13 +100,13 @@ struct memblock {
extern struct memblock memblock;
+#define __init_memblock __section(".mbinit.text") __cold notrace \
+ __latent_entropy
+#define __initdata_memblock __section(".mbinit.data")
+
#ifndef CONFIG_ARCH_KEEP_MEMBLOCK
-#define __init_memblock __meminit
-#define __initdata_memblock __meminitdata
void memblock_discard(void);
#else
-#define __init_memblock
-#define __initdata_memblock
static inline void memblock_discard(void) {}
#endif
--
2.34.1
On 5/6/24 06:51, Wei Yang wrote:
> When CONFIG_ARCH_KEEP_MEMBLOCK not set, we expect to discard related
> code and data. But it doesn't until CONFIG_MEMORY_HOTPLUG not set
> neither.
When CONFIG_ARCH_KEEP_MEMBLOCK is not set memblock information both for
normal and reserved memory get freed up but should the memblock related
code and data also be freed up as well ? Then I would also believe such
memory saving will be very minimal given CONFIG_ARCH_KEEP_MEMBLOCK code
is too limited scoped in the tree.
Also could you please explain how it is related to CONFIG_MEMORY_HOTPLUG
config being set or not.
>
> This patch puts memblock's .text/.data into its own section, so that it
> only depends on CONFIG_ARCH_KEEP_MEMBLOCK to discard related code and
> data. After this, init size increase from 2420K to 2432K.
Is not this memory size saving some what insignificant to warrant a code
change ? Also is this problem applicable only to CONFIG_ARCH_KEEP_MEMBLOCK
config. Could you also provide details on how did you measure these numbers ?
>
> Signed-off-by: Wei Yang <[email protected]>
> ---
> include/asm-generic/vmlinux.lds.h | 14 +++++++++++++-
> include/linux/memblock.h | 8 ++++----
> 2 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index f7749d0f2562..775c5eedb9e6 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -147,6 +147,14 @@
> #define MEM_DISCARD(sec) *(.mem##sec)
> #endif
>
> +#if defined(CONFIG_ARCH_KEEP_MEMBLOCK)
> +#define MEMBLOCK_KEEP(sec) *(.mb##sec)
> +#define MEMBLOCK_DISCARD(sec)
> +#else
> +#define MEMBLOCK_KEEP(sec)
> +#define MEMBLOCK_DISCARD(sec) *(.mb##sec)
> +#endif
> +
> #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
> #define KEEP_PATCHABLE KEEP(*(__patchable_function_entries))
> #define PATCHABLE_DISCARDS
> @@ -356,6 +364,7 @@
> *(.ref.data) \
> *(.data..shared_aligned) /* percpu related */ \
> MEM_KEEP(init.data*) \
> + MEMBLOCK_KEEP(init.data*) \
> *(.data.unlikely) \
> __start_once = .; \
> *(.data.once) \
> @@ -573,6 +582,7 @@
> *(.ref.text) \
> *(.text.asan.* .text.tsan.*) \
> MEM_KEEP(init.text*) \
> + MEMBLOCK_KEEP(init.text*) \
>
>
> /* sched.text is aling to function alignment to secure we have same
> @@ -680,6 +690,7 @@
> KEEP(*(SORT(___kentry+*))) \
> *(.init.data .init.data.*) \
> MEM_DISCARD(init.data*) \
> + MEMBLOCK_DISCARD(init.data*) \
> KERNEL_CTORS() \
> MCOUNT_REC() \
> *(.init.rodata .init.rodata.*) \
> @@ -706,7 +717,8 @@
> #define INIT_TEXT \
> *(.init.text .init.text.*) \
> *(.text.startup) \
> - MEM_DISCARD(init.text*)
> + MEM_DISCARD(init.text*) \
> + MEMBLOCK_DISCARD(init.text*)
>
> #define EXIT_DATA \
> *(.exit.data .exit.data.*) \
> diff --git a/include/linux/memblock.h b/include/linux/memblock.h
> index e2082240586d..3e1f1d42dde7 100644
> --- a/include/linux/memblock.h
> +++ b/include/linux/memblock.h
> @@ -100,13 +100,13 @@ struct memblock {
>
> extern struct memblock memblock;
>
> +#define __init_memblock __section(".mbinit.text") __cold notrace \
> + __latent_entropy
> +#define __initdata_memblock __section(".mbinit.data")
> +
> #ifndef CONFIG_ARCH_KEEP_MEMBLOCK
> -#define __init_memblock __meminit
> -#define __initdata_memblock __meminitdata
> void memblock_discard(void);
> #else
> -#define __init_memblock
> -#define __initdata_memblock
> static inline void memblock_discard(void) {}
> #endif
>
Hi Wei,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/mm-memblock-discard-text-data-if-CONFIG_ARCH_KEEP_MEMBLOCK-not-set/20240506-092345
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20240506012104.10864-1-richard.weiyang%40gmail.com
patch subject: [PATCH] mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set
config: powerpc-allnoconfig
compiler: powerpc-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build):
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
On Mon, May 06, 2024 at 03:30:54PM +0530, Anshuman Khandual wrote:
>
>On 5/6/24 06:51, Wei Yang wrote:
>> When CONFIG_ARCH_KEEP_MEMBLOCK not set, we expect to discard related
>> code and data. But it doesn't until CONFIG_MEMORY_HOTPLUG not set
>> neither.
>
>When CONFIG_ARCH_KEEP_MEMBLOCK is not set memblock information both for
>normal and reserved memory get freed up but should the memblock related
>code and data also be freed up as well ? Then I would also believe such
If not freed, those functions would access unpredictable area.
>memory saving will be very minimal given CONFIG_ARCH_KEEP_MEMBLOCK code
>is too limited scoped in the tree.
Not very much, it shows 12K more in it.
>
>Also could you please explain how it is related to CONFIG_MEMORY_HOTPLUG
>config being set or not.
>
This is in file include/asm-generic/vmlinux.lds.h.
MEM_KEEP/MEM_DISCARD is conditionally defined by CONFIG_MEMORY_HOTPLUG.
So even __init_memblock is defined as __meminit when CONFIG_ARCH_KEEP_MEMBLOCK
not set, it is not discarded.
>>
>> This patch puts memblock's .text/.data into its own section, so that it
>> only depends on CONFIG_ARCH_KEEP_MEMBLOCK to discard related code and
>> data. After this, init size increase from 2420K to 2432K.
>
>Is not this memory size saving some what insignificant to warrant a code
>change ? Also is this problem applicable only to CONFIG_ARCH_KEEP_MEMBLOCK
Yes, this is not significant.
>config. Could you also provide details on how did you measure these numbers ?
>
Kernel print related info in mem_init_print_info(). One of is it
init size, which includes init_data and init_text.
>>
>> Signed-off-by: Wei Yang <[email protected]>
>> ---
>> include/asm-generic/vmlinux.lds.h | 14 +++++++++++++-
>> include/linux/memblock.h | 8 ++++----
>> 2 files changed, 17 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
>> index f7749d0f2562..775c5eedb9e6 100644
>> --- a/include/asm-generic/vmlinux.lds.h
>> +++ b/include/asm-generic/vmlinux.lds.h
>> @@ -147,6 +147,14 @@
>> #define MEM_DISCARD(sec) *(.mem##sec)
>> #endif
>>
>> +#if defined(CONFIG_ARCH_KEEP_MEMBLOCK)
>> +#define MEMBLOCK_KEEP(sec) *(.mb##sec)
>> +#define MEMBLOCK_DISCARD(sec)
>> +#else
>> +#define MEMBLOCK_KEEP(sec)
>> +#define MEMBLOCK_DISCARD(sec) *(.mb##sec)
>> +#endif
>> +
>> #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
>> #define KEEP_PATCHABLE KEEP(*(__patchable_function_entries))
>> #define PATCHABLE_DISCARDS
>> @@ -356,6 +364,7 @@
>> *(.ref.data) \
>> *(.data..shared_aligned) /* percpu related */ \
>> MEM_KEEP(init.data*) \
>> + MEMBLOCK_KEEP(init.data*) \
>> *(.data.unlikely) \
>> __start_once = .; \
>> *(.data.once) \
>> @@ -573,6 +582,7 @@
>> *(.ref.text) \
>> *(.text.asan.* .text.tsan.*) \
>> MEM_KEEP(init.text*) \
>> + MEMBLOCK_KEEP(init.text*) \
>>
>>
>> /* sched.text is aling to function alignment to secure we have same
>> @@ -680,6 +690,7 @@
>> KEEP(*(SORT(___kentry+*))) \
>> *(.init.data .init.data.*) \
>> MEM_DISCARD(init.data*) \
>> + MEMBLOCK_DISCARD(init.data*) \
>> KERNEL_CTORS() \
>> MCOUNT_REC() \
>> *(.init.rodata .init.rodata.*) \
>> @@ -706,7 +717,8 @@
>> #define INIT_TEXT \
>> *(.init.text .init.text.*) \
>> *(.text.startup) \
>> - MEM_DISCARD(init.text*)
>> + MEM_DISCARD(init.text*) \
>> + MEMBLOCK_DISCARD(init.text*)
>>
>> #define EXIT_DATA \
>> *(.exit.data .exit.data.*) \
>> diff --git a/include/linux/memblock.h b/include/linux/memblock.h
>> index e2082240586d..3e1f1d42dde7 100644
>> --- a/include/linux/memblock.h
>> +++ b/include/linux/memblock.h
>> @@ -100,13 +100,13 @@ struct memblock {
>>
>> extern struct memblock memblock;
>>
>> +#define __init_memblock __section(".mbinit.text") __cold notrace \
>> + __latent_entropy
>> +#define __initdata_memblock __section(".mbinit.data")
>> +
>> #ifndef CONFIG_ARCH_KEEP_MEMBLOCK
>> -#define __init_memblock __meminit
>> -#define __initdata_memblock __meminitdata
>> void memblock_discard(void);
>> #else
>> -#define __init_memblock
>> -#define __initdata_memblock
>> static inline void memblock_discard(void) {}
>> #endif
>>
--
Wei Yang
Help you, Help me
On Tue, May 07, 2024 at 01:13:05PM +0800, kernel test robot wrote:
>Hi Wei,
>
>kernel test robot noticed the following build warnings:
>
>[auto build test WARNING on akpm-mm/mm-everything]
>
>url: https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/mm-memblock-discard-text-data-if-CONFIG_ARCH_KEEP_MEMBLOCK-not-set/20240506-092345
>base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
>patch link: https://lore.kernel.org/r/20240506012104.10864-1-richard.weiyang%40gmail.com
>patch subject: [PATCH] mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set
>config: powerpc-allnoconfig
>compiler: powerpc-linux-gcc (GCC) 13.2.0
>reproduce (this is a W=1 build):
>
>If you fix the issue in a separate patch/commit (i.e. not just a new version of
>the same patch/commit), kindly add following tags
>| Reported-by: kernel test robot <[email protected]>
>| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>
>All warnings (new ones prefixed by >>):
>
>>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
>>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
>>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
>
>--
>0-DAY CI Kernel Test Service
>https://github.com/intel/lkp-tests/wiki
>reproduce (this is a W=1 build):
> git clone https://github.com/intel/lkp-tests.git ~/lkp-tests
> git remote add akpm-mm https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git
> git fetch akpm-mm mm-everything
> git checkout akpm-mm/mm-everything
> b4 shazam https://lore.kernel.org/r/[email protected]
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-13.2.0 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=powerpc olddefconfig
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-13.2.0 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash
Can I reproduce this on x86? I don't have a powerpc machine.
--
Wei Yang
Help you, Help me
On Tue, May 07, 2024 at 08:43:50AM +0000, Wei Yang wrote:
> On Tue, May 07, 2024 at 01:13:05PM +0800, kernel test robot wrote:
> >Hi Wei,
> >
> >kernel test robot noticed the following build warnings:
> >
> >[auto build test WARNING on akpm-mm/mm-everything]
> >
> >url: https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/mm-memblock-discard-text-data-if-CONFIG_ARCH_KEEP_MEMBLOCK-not-set/20240506-092345
> >base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
> >patch link: https://lore.kernel.org/r/20240506012104.10864-1-richard.weiyang%40gmail.com
> >patch subject: [PATCH] mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set
> >config: powerpc-allnoconfig
> >compiler: powerpc-linux-gcc (GCC) 13.2.0
> >reproduce (this is a W=1 build):
> >
> >If you fix the issue in a separate patch/commit (i.e. not just a new version of
> >the same patch/commit), kindly add following tags
> >| Reported-by: kernel test robot <[email protected]>
> >| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
> >
> >All warnings (new ones prefixed by >>):
> >
> >>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
> >>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
> >>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
> >
> >--
> >0-DAY CI Kernel Test Service
> >https://github.com/intel/lkp-tests/wiki
>
> >reproduce (this is a W=1 build):
> > git clone https://github.com/intel/lkp-tests.git ~/lkp-tests
> > git remote add akpm-mm https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git
> > git fetch akpm-mm mm-everything
> > git checkout akpm-mm/mm-everything
> > b4 shazam https://lore.kernel.org/r/[email protected]
> > # save the config file
> > mkdir build_dir && cp config build_dir/.config
> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-13.2.0 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=powerpc olddefconfig
> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-13.2.0 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash
>
> Can I reproduce this on x86? I don't have a powerpc machine.
The above steps are cross compiling for powerpc target on x86
machine, so you can just follow the steps to reproduce on x86.
Thanks,
Yujie
On Wed, May 08, 2024 at 11:06:45AM +0800, Yujie Liu wrote:
>On Tue, May 07, 2024 at 08:43:50AM +0000, Wei Yang wrote:
>> On Tue, May 07, 2024 at 01:13:05PM +0800, kernel test robot wrote:
>> >Hi Wei,
>> >
>> >kernel test robot noticed the following build warnings:
>> >
>> >[auto build test WARNING on akpm-mm/mm-everything]
>> >
>> >url: https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/mm-memblock-discard-text-data-if-CONFIG_ARCH_KEEP_MEMBLOCK-not-set/20240506-092345
>> >base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
>> >patch link: https://lore.kernel.org/r/20240506012104.10864-1-richard.weiyang%40gmail.com
>> >patch subject: [PATCH] mm/memblock: discard .text/.data if CONFIG_ARCH_KEEP_MEMBLOCK not set
>> >config: powerpc-allnoconfig
>> >compiler: powerpc-linux-gcc (GCC) 13.2.0
>> >reproduce (this is a W=1 build):
>> >
>> >If you fix the issue in a separate patch/commit (i.e. not just a new version of
>> >the same patch/commit), kindly add following tags
>> >| Reported-by: kernel test robot <[email protected]>
>> >| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>> >
>> >All warnings (new ones prefixed by >>):
>> >
>> >>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
>> >>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
>> >>> powerpc-linux-ld: warning: orphan section `.mbinit.text' from `mm/memblock.o' being placed in section `.mbinit.text'
>> >
>> >--
>> >0-DAY CI Kernel Test Service
>> >https://github.com/intel/lkp-tests/wiki
>>
>> >reproduce (this is a W=1 build):
>> > git clone https://github.com/intel/lkp-tests.git ~/lkp-tests
>> > git remote add akpm-mm https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git
>> > git fetch akpm-mm mm-everything
>> > git checkout akpm-mm/mm-everything
>> > b4 shazam https://lore.kernel.org/r/[email protected]
>> > # save the config file
>> > mkdir build_dir && cp config build_dir/.config
>> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-13.2.0 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=powerpc olddefconfig
>> > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-13.2.0 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash
>>
>> Can I reproduce this on x86? I don't have a powerpc machine.
>
>The above steps are cross compiling for powerpc target on x86
>machine, so you can just follow the steps to reproduce on x86.
>
Thanks, this one is helpful.
>Thanks,
>Yujie
--
Wei Yang
Help you, Help me