Search code examples
linux-kernelbootsmp

Kernel initialization on SMP system


When we start kernel on a SMP system, CPU0 starts kernel code where in main memory, cache and MMU specific to CPU0 is nitialized while CPUx are in WFI state. When cpu_up(x) is sent from CPU0, each of CPUx is then initialized and calls secondary_startup where again the main memory, cache and MMU specific to CPUx is initialized.

Now I know abut cache which can be different for different core but do we have main memory and MMU for different core too? I have never heard of it. What exactly happens here and how do the division of main memory and MMU happen between CPUs?


Solution

  • In an SMP system (or a NUMA system like today's x86 CPUs), all memory is accessible to all CPUs. So CPU0 can initialize all the memory.

    There's still room for CPU specific initialization:

    1. Each CPU may allocate a small memory pool for itself, for efficient allocation.
    2. The control register that directs the hardware to the paging tables should be set on each CPU.
    3. A setup or flush of the TLBs (the hardware's address translation cache) may be needed.