From: Ingo Molnar <mingo@kernel.org>
To: Alexander Kuleshov <kuleshovmail@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
"H . Peter Anvin" <hpa@zytor.com>, Borislav Petkov <bp@suse.de>,
Joerg Roedel <jroedel@suse.de>, Dave Young <dyoung@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Jiri Kosina <jkosina@suse.cz>, Baoquan He <bhe@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Mark Salter <msalter@redhat.com>,
linux-kernel@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function
Date: Tue, 9 Feb 2016 10:16:26 +0100 [thread overview]
Message-ID: <20160209091626.GA12570@gmail.com> (raw)
In-Reply-To: <1454954546-23074-1-git-send-email-kuleshovmail@gmail.com>
* 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
next prev parent reply other threads:[~2016-02-09 9:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-08 18:02 [PATCH v2] x86/setup: Merge {early_,}reserve_initrd() to one function Alexander Kuleshov
2016-02-09 9:16 ` Ingo Molnar [this message]
2016-02-09 11:35 ` Alexander Kuleshov
2016-02-09 12:10 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160209091626.GA12570@gmail.com \
--to=mingo@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=bp@suse.de \
--cc=dyoung@redhat.com \
--cc=hpa@zytor.com \
--cc=jkosina@suse.cz \
--cc=jroedel@suse.de \
--cc=kuleshovmail@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=msalter@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).