0
votes

As per my understanding init process which is the first user-space process starting in Linux is created staticall in arch/ia64/kernel/init_task.c.

Why we can't create this init process also dynamically? slab allocator is available once the kernel is up, so we can get a task_struct from slab allocator and create init process?

1

1 Answers

1
votes

Actually, the init_task with type struct task_struct * is defined in arch/*/kernel/init_task.c files. This struct is used early in start_kernel: http://lxr.free-electrons.com/source/init/main.c?v=3.10#L471

471 asmlinkage void __init start_kernel(void)
472 {

481         smp_setup_processor_id();

489         cgroup_init_early();

498         boot_cpu_init();
499         page_address_init();
500         pr_notice("%s", linux_banner);
501         setup_arch(&command_line);
502         mm_init_owner(&init_mm, &init_task);

So, slab allocator may be available at moment of init starting, but the task_struct of the init is used earlier, both in start_kernel and in other places (http://lxr.free-electrons.com/ident?v=3.10&i=init_task) e.g. to statically init the current_task pointer on other CPUs.

http://lxr.free-electrons.com/source/arch/x86/kernel/cpu/common.c?v=3.10#L1080

1084 DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
1085         &init_task;