Search code examples
linuxlinux-kernelcpucpu-usage

What happens to a process running in a CPU when it goes offline


I make certain CPUs to go offline using the command

echo 0 > /sys/devices/system/cpu/cpu$cpu/online

Post which my nproc, grep "processor" /proc/cpuinfo and lscpu confirms that the CPU is offline. In such a scenario:

  1. What happens to a process pinned to that CPU (is the expectation a kill / migration to another CPU ?)
  2. What happens to a process that was running in that CPU (will it get migrated to another CPU?)

Solution

  • No process is killed, that would be a disservice.
    When a CPU is put offline, its tasks are migrated:

    All processes are migrated away from this outgoing CPU to new CPUs. The new CPU is chosen from each process’ current cpuset, which may be a subset of all online CPUs.

    from Official Kernel documentation

    This leaves open the question of tasks that were pinned to that specific CPU. You can dig into the kernel to see that the fallback is to unpin those task from the offlined CPU.
    Their new affinity mask is set to all the possible CPUs.