x86 : add init BSS sections
Subsystems (2)
PATCH 1/2 x86 : add init BSS sections
Init BSS sections are added for uninitialized init DATA sections to reduce kernel image size.
--- arch/x86/kernel/head64.c | 2 ++ arch/x86/kernel/head_32.S | 5 +++++ arch/x86/kernel/vmlinux_32.lds.S | 9 +++++++-- arch/x86/kernel/vmlinux_64.lds.S | 24 ++++++++++++++---------- include/asm-generic/sections.h | 1 + include/linux/init.h | 1 + 6 files changed, 30 insertions(+), 12 deletions(-)
arch/x86/kernel/vmlinux_32.lds.S +7 -2
@@ -189,10 +189,15 @@ SECTIONS __per_cpu_end = .; } . = ALIGN(PAGE_SIZE); - /* freed after init ends here */ .bss : AT(ADDR(.bss) - LOAD_OFFSET) { - __init_end = .; + __init_bss_start = .; + *(.bss.init.page_aligned) + *(.bss.init) + . = ALIGN(4); + __init_bss_stop = .; + . = ALIGN(PAGE_SIZE); + __init_end = .; /* freed after init ends here */ __bss_start = .; /* BSS */ *(.bss.page_aligned) *(.bss)
arch/x86/kernel/vmlinux_64.lds.S +14 -10
@@ -150,6 +150,12 @@ SECTIONS . = ALIGN(PAGE_SIZE); __smp_alt_end = .; + . = ALIGN(PAGE_SIZE); + __nosave_begin = .; + .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) } + . = ALIGN(PAGE_SIZE); + __nosave_end = .; + . = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
@@ -219,17 +225,15 @@ SECTIONS PERCPU(PAGE_SIZE) - . = ALIGN(PAGE_SIZE); - __init_end = .; - - . = ALIGN(PAGE_SIZE); - __nosave_begin = .; - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) } - . = ALIGN(PAGE_SIZE); - __nosave_end = .; - - __bss_start = .; /* BSS */ + . = ALIGN(PAGE_SIZE); /* BSS */ .bss : AT(ADDR(.bss) - LOAD_OFFSET) { + __init_bss_start = .; + *(.bss.init.page_aligned) + *(.bss.init) + __init_bss_stop = .; + . = ALIGN(PAGE_SIZE); + __init_end = .; + __bss_start = .; *(.bss.page_aligned) *(.bss) }
arch/x86/kernel/head_32.S +5 -0
@@ -105,6 +105,11 @@ ENTRY(startup_32) */ cld xorl %eax,%eax + movl $pa(__init_bss_start),%edi + movl $pa(__init_bss_stop), %ecx + subl %edi,%ecx + shrl $2,%ecx + rep ; stosl movl $pa(__bss_start),%edi movl $pa(__bss_stop),%ecx subl %edi,%ecx
include/asm-generic/sections.h +1 -0
@@ -5,6 +5,7 @@extern char _text[], _stext[], _etext[];extern char _data[], _sdata[], _edata[]; +extern char __init_bss_start[], __init_bss_stop[];extern char __bss_start[], __bss_stop[];extern char __init_begin[], __init_end[];extern char _sinittext[], _einittext[];
arch/x86/kernel/head64.c +2 -0
@@ -34,6 +34,8 @@ static void __init zap_identity_mappingsyet. */ static void __init clear_bss (void ) { +memset (__init_bss_start,0 , (unsigned long ) __init_bss_stop - + (unsigned long ) __init_bss_start);memset (__bss_start,0 , (unsigned long ) __bss_stop - (unsigned long ) __bss_start); }
include/linux/init.h +1 -0
@@ -43,6 +43,7 @@#define __init __section(.init.text) __cold#define __initdata __section(.init.data)#define __initconst __section(.init.rodata) +#define __initbss __section(.bss.init)#define __exitdata __section(.exit.data)#define __exit_call __used __section(.exitcall.exit)
Hi Huang.
A few comments..
Quoted 2 lines
Init BSS sections are added for uninitialized init DATA sections to reduce kernel image size.
- If this is relevant for more than just x86 then the definition of the section should be in include/asm-generic/vmlinux.lds.h
- Please add a comment along the definitions in the .lds file explaning the use of the section.
- Same goes for init.h
- Is this concept restricted to __init or is it relevant for __devinit etc (I hope we can avoid that)
- Can we do any kind of build time check to catch accidental misuse?
Sam
Quoted 15 lines
Signed-off-by Huang Ying <[email protected]>--- arch/x86/kernel/head64.c | 2 ++ arch/x86/kernel/head_32.S | 5 +++++ arch/x86/kernel/vmlinux_32.lds.S | 9 +++++++-- arch/x86/kernel/vmlinux_64.lds.S | 24 ++++++++++++++---------- include/asm-generic/sections.h | 1 + include/linux/init.h | 1 + 6 files changed, 30 insertions(+), 12 deletions(-)
arch/x86/kernel/vmlinux_32.lds.S SECTIONS · line 191
Quoted 3 lines
arch/x86/kernel/vmlinux_32.lds.S +0
-0@@ -189,10 +189,15 @@ SECTIONS __per_cpu_end = .; } . = ALIGN(PAGE_SIZE);
Do we really need to aling this to PAGE_SIZE - I assume we free everything in one go - or?
arch/x86/kernel/vmlinux_32.lds.S SECTIONS · line 195
Quoted 6 lines
arch/x86/kernel/vmlinux_32.lds.S +2
-2- /* freed after init ends here */ .bss : AT(ADDR(.bss) - LOAD_OFFSET) { - __init_end = .; + __init_bss_start = .; + *(.bss.init.page_aligned)
I do not see this section used anywhere. At least init.h does not define it.
arch/x86/kernel/vmlinux_32.lds.S SECTIONS · line 199
Quoted 4 lines
arch/x86/kernel/vmlinux_32.lds.S +4
-0+ *(.bss.init) + . = ALIGN(4); + __init_bss_stop = .; + . = ALIGN(PAGE_SIZE);
Why do we have these two ALIGN() following each other? The latter should be enough.
Quoted 7 lines
arch/x86/kernel/vmlinux_32.lds.S +1
-0+ __init_end = .; /* freed after init ends here */ __bss_start = .; /* BSS */ *(.bss.page_aligned) *(.bss)
arch/x86/kernel/vmlinux_64.lds.S SECTIONS · line 158
Quoted 9 lines
arch/x86/kernel/vmlinux_64.lds.S +6
-0@@ -150,6 +150,12 @@ SECTIONS . = ALIGN(PAGE_SIZE); __smp_alt_end = .; + . = ALIGN(PAGE_SIZE); + __nosave_begin = .; + .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) } + . = ALIGN(PAGE_SIZE); + __nosave_end = .; +
This change looks unrelated - it is not in the changelog. Or is it just diff that fools me?
Quoted 33 lines
arch/x86/kernel/vmlinux_64.lds.S +8
-10. = ALIGN(PAGE_SIZE); /* Init code and data */ __init_begin = .; .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {@@ -219,17 +225,15 @@ SECTIONS PERCPU(PAGE_SIZE) - . = ALIGN(PAGE_SIZE); - __init_end = .; - - . = ALIGN(PAGE_SIZE); - __nosave_begin = .; - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) } - . = ALIGN(PAGE_SIZE); - __nosave_end = .; - - __bss_start = .; /* BSS */ + . = ALIGN(PAGE_SIZE); /* BSS */ .bss : AT(ADDR(.bss) - LOAD_OFFSET) { + __init_bss_start = .; + *(.bss.init.page_aligned) + *(.bss.init) + __init_bss_stop = .; + . = ALIGN(PAGE_SIZE); + __init_end = .; + __bss_start = .; *(.bss.page_aligned) *(.bss) }arch/x86/kernel/head_32.S +0
-0@@ -105,6 +105,11 @@ ENTRY(startup_32) */
arch/x86/kernel/head_32.S ENTRY(startup_32) · line 115
Quoted 10 lines
arch/x86/kernel/head_32.S +5
-0cld xorl %eax,%eax + movl $pa(__init_bss_start),%edi + movl $pa(__init_bss_stop), %ecx + subl %edi,%ecx + shrl $2,%ecx + rep ; stosl movl $pa(__bss_start),%edi movl $pa(__bss_stop),%ecx subl %edi,%ecx
How about introducing head32.c and do this in a similar way that 64 bit does?
Then we could later move more stuff to said file.
Sam