Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1329443 > unrolled thread
| Started by | Alexander Kuleshov <kuleshovmail@gmail.com> |
|---|---|
| First post | 2016-02-08 19:10 +0100 |
| Last post | 2016-02-09 13:20 +0100 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function Alexander Kuleshov <kuleshovmail@gmail.com> - 2016-02-08 19:10 +0100
Re: [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function Ingo Molnar <mingo@kernel.org> - 2016-02-09 10:20 +0100
Re: [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function Alexander Kuleshov <kuleshovmail@gmail.com> - 2016-02-09 13:00 +0100
Re: [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function Ingo Molnar <mingo@kernel.org> - 2016-02-09 13:20 +0100
| From | Alexander Kuleshov <kuleshovmail@gmail.com> |
|---|---|
| Date | 2016-02-08 19:10 +0100 |
| Subject | [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function |
| Message-ID | <qZYq8-qH-43@gated-at.bofh.it> |
The check and definitions related to ramdisk are similar in the
early_reserve_initrd() and reserve_initrd(). So we can get rid of
early_reserve_initrd() and and use late or early algorithm for
initrd reservation depends on reserve_initrd() parameter value.
Save 396 bytes of code:
text data bss dec hex filename
9281618 5010736 15474688 29767042 1c63582 vmlinux.orig
text data bss dec hex filename
9281222 5010672 15474688 29766582 1c633b6 vmlinux.new
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
Changelog:
v2: parameter of reserve_initrd() - int -> bool.
commit message updated.
arch/x86/kernel/setup.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index d3d80e6..0a2fa55 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -349,20 +349,7 @@ static void __init relocate_initrd(void)
relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
}
-static void __init early_reserve_initrd(void)
-{
- /* Assume only end is not page aligned */
- u64 ramdisk_image = get_ramdisk_image();
- u64 ramdisk_size = get_ramdisk_size();
- u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
-
- if (!boot_params.hdr.type_of_loader ||
- !ramdisk_image || !ramdisk_size)
- return; /* No initrd provided by bootloader */
-
- memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
-}
-static void __init reserve_initrd(void)
+static void __init reserve_initrd(bool early)
{
/* Assume only end is not page aligned */
u64 ramdisk_image = get_ramdisk_image();
@@ -374,6 +361,11 @@ static void __init reserve_initrd(void)
!ramdisk_image || !ramdisk_size)
return; /* No initrd provided by bootloader */
+ if (early) {
+ memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
+ return;
+ }
+
initrd_start = 0;
mapped_size = memblock_mem_size(max_pfn_mapped);
@@ -398,10 +390,7 @@ static void __init reserve_initrd(void)
memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
}
#else
-static void __init early_reserve_initrd(void)
-{
-}
-static void __init reserve_initrd(void)
+static void __init reserve_initrd(bool early)
{
}
#endif /* CONFIG_BLK_DEV_INITRD */
@@ -850,7 +839,7 @@ void __init setup_arch(char **cmdline_p)
memblock_reserve(__pa_symbol(_text),
(unsigned long)__bss_stop - (unsigned long)_text);
- early_reserve_initrd();
+ reserve_initrd(true);
/*
* At this point everything still needed from the boot loader
@@ -1135,7 +1124,7 @@ void __init setup_arch(char **cmdline_p)
/* Allocate bigger log buffer */
setup_log_buf(1);
- reserve_initrd();
+ reserve_initrd(false);
#if defined(CONFIG_ACPI) && defined(CONFIG_BLK_DEV_INITRD)
acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start);
--
2.7.0.25.gfc10eb5
[toc] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2016-02-09 10:20 +0100 |
| Subject | Re: [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function |
| Message-ID | <r0cCK-21t-11@gated-at.bofh.it> |
| In reply to | #1329443 |
* Alexander Kuleshov <kuleshovmail@gmail.com> wrote:
> The check and definitions related to ramdisk are similar in the
> early_reserve_initrd() and reserve_initrd(). So we can get rid of
> early_reserve_initrd() and and use late or early algorithm for
> initrd reservation depends on reserve_initrd() parameter value.
>
> Save 396 bytes of code:
>
> text data bss dec hex filename
> 9281618 5010736 15474688 29767042 1c63582 vmlinux.orig
>
> text data bss dec hex filename
> 9281222 5010672 15474688 29766582 1c633b6 vmlinux.new
>
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
> Changelog:
>
> v2: parameter of reserve_initrd() - int -> bool.
> commit message updated.
>
> arch/x86/kernel/setup.c | 29 +++++++++--------------------
> 1 file changed, 9 insertions(+), 20 deletions(-)
>
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index d3d80e6..0a2fa55 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -349,20 +349,7 @@ static void __init relocate_initrd(void)
> relocated_ramdisk, relocated_ramdisk + ramdisk_size - 1);
> }
>
> -static void __init early_reserve_initrd(void)
> -{
> - /* Assume only end is not page aligned */
> - u64 ramdisk_image = get_ramdisk_image();
> - u64 ramdisk_size = get_ramdisk_size();
> - u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
> -
> - if (!boot_params.hdr.type_of_loader ||
> - !ramdisk_image || !ramdisk_size)
> - return; /* No initrd provided by bootloader */
> -
> - memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
> -}
> -static void __init reserve_initrd(void)
> +static void __init reserve_initrd(bool early)
> {
> /* Assume only end is not page aligned */
> u64 ramdisk_image = get_ramdisk_image();
> @@ -374,6 +361,11 @@ static void __init reserve_initrd(void)
> !ramdisk_image || !ramdisk_size)
> return; /* No initrd provided by bootloader */
>
> + if (early) {
> + memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image);
> + return;
> + }
> +
> initrd_start = 0;
>
> mapped_size = memblock_mem_size(max_pfn_mapped);
> @@ -398,10 +390,7 @@ static void __init reserve_initrd(void)
> memblock_free(ramdisk_image, ramdisk_end - ramdisk_image);
> }
> #else
> -static void __init early_reserve_initrd(void)
> -{
> -}
> -static void __init reserve_initrd(void)
> +static void __init reserve_initrd(bool early)
> {
> }
> #endif /* CONFIG_BLK_DEV_INITRD */
> @@ -850,7 +839,7 @@ void __init setup_arch(char **cmdline_p)
> memblock_reserve(__pa_symbol(_text),
> (unsigned long)__bss_stop - (unsigned long)_text);
>
> - early_reserve_initrd();
> + reserve_initrd(true);
>
> /*
> * At this point everything still needed from the boot loader
> @@ -1135,7 +1124,7 @@ void __init setup_arch(char **cmdline_p)
> /* Allocate bigger log buffer */
> setup_log_buf(1);
>
> - reserve_initrd();
> + reserve_initrd(false);
>
> #if defined(CONFIG_ACPI) && defined(CONFIG_BLK_DEV_INITRD)
> acpi_initrd_override((void *)initrd_start, initrd_end - initrd_start);
So I don't think the code got easier to understand - in particular the
memblock_reserve()/free() pattern, depending on a flag value, is confusing.
The duplication is there - but please factor it out into a helper structure
('struct ramdisk') and a helper function that sets up the structure.
Thanks,
Ingo
[toc] | [prev] | [next] | [standalone]
| From | Alexander Kuleshov <kuleshovmail@gmail.com> |
|---|---|
| Date | 2016-02-09 13:00 +0100 |
| Message-ID | <r0f7z-3uX-5@gated-at.bofh.it> |
| In reply to | #1329983 |
Hello Ingo,
On Tue, Feb 9, 2016 at 3:16 PM, Ingo Molnar <mingo@kernel.org> wrote:
>
> So I don't think the code got easier to understand - in particular the
> memblock_reserve()/free() pattern, depending on a flag value, is confusing.
>
> The duplication is there - but please factor it out into a helper structure
> ('struct ramdisk') and a helper function that sets up the structure.
What if instead of `struct ramdisk`, we will move all definitions/check from
the early_reserve_initrd to the setup_arch() and than will pass these values
to the reserve_initrd()?
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2016-02-09 13:20 +0100 |
| Subject | Re: [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function |
| Message-ID | <r0fqY-3Sj-59@gated-at.bofh.it> |
| In reply to | #1330131 |
* Alexander Kuleshov <kuleshovmail@gmail.com> wrote:
> Hello Ingo,
>
> On Tue, Feb 9, 2016 at 3:16 PM, Ingo Molnar <mingo@kernel.org> wrote:
> >
> > So I don't think the code got easier to understand - in particular the
> > memblock_reserve()/free() pattern, depending on a flag value, is confusing.
> >
> > The duplication is there - but please factor it out into a helper structure
> > ('struct ramdisk') and a helper function that sets up the structure.
>
> What if instead of `struct ramdisk`, we will move all definitions/check from
> the early_reserve_initrd to the setup_arch() and than will pass these values
> to the reserve_initrd()?
There's too many of them, putting them into 'struct ramdisk' cleans up and
documents the whole code.
And yes, 'struct ramdisk' state should be defined in setup_arch(), that way it
does not have to be calculated twice: so the patch becomes not just a code size
reduction but a (small) runtime reduction as well.
Should be tested with a real ramdisk, to make sure everything still works fine.
Thanks,
Ingo
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web