2006-12-07 03:43:00

by Michael Neuling

[permalink] [raw]
Subject: [PATCH] free initrds boot option

Add retain_initrd option to control freeing of initrd memory after
extraction. By default, free memory as previously.

Signed-off-by: Michael Neuling <[email protected]>
---
Updated based on comments from akpm.
Added documentation and changed option name to "retain_initrd"
Tested on POWERPC with CPIOs

Documentation/kernel-parameters.txt | 2 ++
init/initramfs.c | 18 ++++++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)

Index: linux-2.6-ozlabs/Documentation/kernel-parameters.txt
===================================================================
--- linux-2.6-ozlabs.orig/Documentation/kernel-parameters.txt
+++ linux-2.6-ozlabs/Documentation/kernel-parameters.txt
@@ -1366,6 +1366,8 @@ and is between 256 and 4096 characters.
resume= [SWSUSP]
Specify the partition device for software suspend

+ retain_initrd [RAM] Keep initrd memory after extraction
+
rhash_entries= [KNL,NET]
Set number of hash buckets for route cache

Index: linux-2.6-ozlabs/init/initramfs.c
===================================================================
--- linux-2.6-ozlabs.orig/init/initramfs.c
+++ linux-2.6-ozlabs/init/initramfs.c
@@ -487,6 +487,17 @@ static char * __init unpack_to_rootfs(ch
return message;
}

+static int do_retain_initrd = 0;
+
+static int __init retain_initrd_param(char *str)
+{
+ if (*str)
+ return 0;
+ do_retain_initrd = 1;
+ return 1;
+}
+__setup("retain_initrd", retain_initrd_param);
+
extern char __initramfs_start[], __initramfs_end[];
#ifdef CONFIG_BLK_DEV_INITRD
#include <linux/initrd.h>
@@ -494,10 +505,13 @@ extern char __initramfs_start[], __initr

static void __init free_initrd(void)
{
-#ifdef CONFIG_KEXEC
unsigned long crashk_start = (unsigned long)__va(crashk_res.start);
unsigned long crashk_end = (unsigned long)__va(crashk_res.end);

+ if (do_retain_initrd)
+ goto skip;
+
+#ifdef CONFIG_KEXEC
/*
* If the initrd region is overlapped with crashkernel reserved region,
* free only memory that is not part of crashkernel region.
@@ -515,7 +529,7 @@ static void __init free_initrd(void)
} else
#endif
free_initrd_mem(initrd_start, initrd_end);
-
+skip:
initrd_start = 0;
initrd_end = 0;
}


2006-12-07 05:06:54

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] free initrds boot option

On Thu, 07 Dec 2006 14:42:57 +1100 Michael Neuling wrote:

> Add retain_initrd option to control freeing of initrd memory after
> extraction. By default, free memory as previously.
>
> Signed-off-by: Michael Neuling <[email protected]>
> ---
> Updated based on comments from akpm.
> Added documentation and changed option name to "retain_initrd"
> Tested on POWERPC with CPIOs
>
> Documentation/kernel-parameters.txt | 2 ++
> init/initramfs.c | 18 ++++++++++++++++--
> 2 files changed, 18 insertions(+), 2 deletions(-)
>
> Index: linux-2.6-ozlabs/init/initramfs.c
> ===================================================================
> --- linux-2.6-ozlabs.orig/init/initramfs.c
> +++ linux-2.6-ozlabs/init/initramfs.c
> @@ -487,6 +487,17 @@ static char * __init unpack_to_rootfs(ch
> return message;
> }
>
> +static int do_retain_initrd = 0;
> +
> +static int __init retain_initrd_param(char *str)
> +{
> + if (*str)
> + return 0;
> + do_retain_initrd = 1;
> + return 1;
> +}
> +__setup("retain_initrd", retain_initrd_param);
> +
> extern char __initramfs_start[], __initramfs_end[];
> #ifdef CONFIG_BLK_DEV_INITRD
> #include <linux/initrd.h>
> @@ -494,10 +505,13 @@ extern char __initramfs_start[], __initr
>
> static void __init free_initrd(void)
> {
> -#ifdef CONFIG_KEXEC
> unsigned long crashk_start = (unsigned long)__va(crashk_res.start);
> unsigned long crashk_end = (unsigned long)__va(crashk_res.end);

How does this work when CONFIG_KEXEC=n ??

Tested?

> + if (do_retain_initrd)
> + goto skip;
> +
> +#ifdef CONFIG_KEXEC
> /*
> * If the initrd region is overlapped with crashkernel reserved region,
> * free only memory that is not part of crashkernel region.
> @@ -515,7 +529,7 @@ static void __init free_initrd(void)
> } else
> #endif
> free_initrd_mem(initrd_start, initrd_end);
> -
> +skip:
> initrd_start = 0;
> initrd_end = 0;
> }
> -

---
~Randy

2006-12-07 05:13:59

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] free initrds boot option

On Thu, 07 Dec 2006 14:42:57 +1100 Michael Neuling wrote:

> Index: linux-2.6-ozlabs/init/initramfs.c
> ===================================================================
> --- linux-2.6-ozlabs.orig/init/initramfs.c
> +++ linux-2.6-ozlabs/init/initramfs.c
> @@ -487,6 +487,17 @@ static char * __init unpack_to_rootfs(ch
> return message;
> }
>
> +static int do_retain_initrd = 0;

Don't init that to 0. That's done for us and it's a bit
wasteful in the object file(s), so we try not to do that.


> +static int __init retain_initrd_param(char *str)
> +{
> + if (*str)
> + return 0;
> + do_retain_initrd = 1;
> + return 1;
> +}
> +__setup("retain_initrd", retain_initrd_param);

---
~Randy