diff --git a/init/Kconfig b/init/Kconfig index 10d69a84c028..bf87ba67e336 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1142,6 +1142,11 @@ if BLK_DEV_INITRD source "usr/Kconfig" +config INITRD_ASYNC + bool "Initrd async" + help + Init ramdisk async, can reduce kernel init time. + endif choice diff --git a/init/initramfs.c b/init/initramfs.c index 3cccb9d51196..0cf533aeb832 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -673,4 +673,23 @@ static int __init populate_rootfs(void) return 0; } + +#if IS_BUILTIN(CONFIG_INITRD_ASYNC) +#include +#include + +static void __init unpack_rootfs_async(void *unused, async_cookie_t cookie) +{ + populate_rootfs(); +} + +static int __init populate_rootfs_async(void) +{ + async_schedule(unpack_rootfs_async, NULL); + return 0; +} + +pure_initcall(populate_rootfs_async); +#else rootfs_initcall(populate_rootfs); +#endif diff --git a/init/main.c b/init/main.c index 348d8e2f7dcd..9570c5b4f8d6 100644 --- a/init/main.c +++ b/init/main.c @@ -1160,6 +1160,10 @@ static noinline void __init kernel_init_freeable(void) do_basic_setup(); +#if IS_BUILTIN(CONFIG_INITRD_ASYNC) + async_synchronize_full(); +#endif + /* Open the /dev/console on the rootfs, this should never fail */ if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) pr_err("Warning: unable to open an initial console.\n");