Skip to contentSkip to conversation

free initrds boot option

PATCH In review Michael Neuling 2 participants 3 messages Dec 7, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 free initrds boot option

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

---
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(-)
Documentation/kernel-parameters.txt +2 -0
Index: 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
 
init/initramfs.c +16 -2
Index: 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;
 }
#1 lore raw
Quoted 36 lines · 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.

---
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
===================================================================

init/initramfs.c +11 -0
@@ -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>

init/initramfs.c extern char __initramfs_start[], __initr · line 509

Quoted 6 lines
init/initramfs.c +0 -1
@@ -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?

Quoted 8 lines
init/initramfs.c +4 -0
+	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.

init/initramfs.c static void __init free_initrd(void)

Quoted 9 lines
init/initramfs.c +1 -2
@@ -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

#2 lore raw
In reply to Michael Neuling

init/initramfs.c static char * __init unpack_to_rootfs(ch · line 490

Quoted 9 lines · On Thu, 07 Dec 2006 14:42:57 +1100 Michael Neuling wrote:

Index: linux-2.6-ozlabs/init/initramfs.c
===================================================================

init/initramfs.c +1 -0
@@ -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.

init/initramfs.c static char * __init unpack_to_rootfs(ch · line 499

Quoted 8 lines
init/initramfs.c +8 -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);

---
~Randy