Skip to content

Commit 0a7b35c

Browse files
mikeyLinus Torvalds
authored and
Linus Torvalds
committed
[PATCH] Add retain_initrd boot option
Add retain_initrd option to control freeing of initrd memory after extraction. By default, free memory as previously. The first boot will need to hold a copy of the in memory fs for the second boot. This image can be large (much larger than the kernel), hence we can save time when the memory loader is slow. Also, it reduces the memory footprint while extracting the first boot since you don't need another copy of the fs. Signed-off-by: Michael Neuling <[email protected]> Cc: "Randy.Dunlap" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 70e8404 commit 0a7b35c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Documentation/kernel-parameters.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,8 @@ and is between 256 and 4096 characters. It is defined in the file
13961396
in <PAGE_SIZE> units (needed only for swap files).
13971397
See Documentation/power/swsusp-and-swap-files.txt
13981398

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

init/initramfs.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,17 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
491491
return message;
492492
}
493493

494+
static int __initdata do_retain_initrd;
495+
496+
static int __init retain_initrd_param(char *str)
497+
{
498+
if (*str)
499+
return 0;
500+
do_retain_initrd = 1;
501+
return 1;
502+
}
503+
__setup("retain_initrd", retain_initrd_param);
504+
494505
extern char __initramfs_start[], __initramfs_end[];
495506
#ifdef CONFIG_BLK_DEV_INITRD
496507
#include <linux/initrd.h>
@@ -501,7 +512,11 @@ static void __init free_initrd(void)
501512
#ifdef CONFIG_KEXEC
502513
unsigned long crashk_start = (unsigned long)__va(crashk_res.start);
503514
unsigned long crashk_end = (unsigned long)__va(crashk_res.end);
515+
#endif
516+
if (do_retain_initrd)
517+
goto skip;
504518

519+
#ifdef CONFIG_KEXEC
505520
/*
506521
* If the initrd region is overlapped with crashkernel reserved region,
507522
* free only memory that is not part of crashkernel region.
@@ -519,7 +534,7 @@ static void __init free_initrd(void)
519534
} else
520535
#endif
521536
free_initrd_mem(initrd_start, initrd_end);
522-
537+
skip:
523538
initrd_start = 0;
524539
initrd_end = 0;
525540
}

0 commit comments

Comments
 (0)