diff --git a/init/Kconfig b/init/Kconfig index cd402972fc2f..5acb8ec84bf6 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1310,6 +1310,11 @@ if BLK_DEV_INITRD source "usr/Kconfig" +config INITRD_ASYNC + bool "Initrd async" + help + Init ramdisk async, can reduce kernel init time. + endif config BOOT_CONFIG diff --git a/init/initramfs.c b/init/initramfs.c index 55b74d7e5260..46429e8ffe27 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -639,4 +639,23 @@ done: flush_delayed_fput(); 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 e8633b6d5752..04a07c2633a2 100644 --- a/init/main.c +++ b/init/main.c @@ -1550,6 +1550,10 @@ static noinline void __init kernel_init_freeable(void) kunit_run_all_tests(); +#if IS_BUILTIN(CONFIG_INITRD_ASYNC) + async_synchronize_full(); +#endif + console_on_rootfs(); /*