← Interview Prep

Linux Kernel — Process Scheduling

How Linux picks the next task: scheduling classes (deadline/RT/CFS/idle), CFS/EEVDF fairness via vruntime + nice weight & the red-black tree, preemption (need_resched, PREEMPT levels) and the context switch cost, per-CPU run queues, load balancing over scheduling domains, and CPU affinity/isolation.

How the kernel decides which task runs next on each CPU — priorities, fairness, preemption, and the context switch. Original, interview-focused notes on the Linux scheduler.

The scheduler picks the next task per-CPU from scheduling classes in priority order: stop → deadline → real-time → CFS (normal) → idle. Most tasks live in CFS, whose goal is fairness: give every runnable task a proportional share of CPU.

Scheduling classes

ClassForPolicy
Deadline (SCHED_DEADLINE)Hard timingEDF — earliest deadline first (runtime/period/deadline).
Real-time (SCHED_FIFO/SCHED_RR)Latency-criticalFixed priority 1–99; RT always beats normal tasks.
CFS / EEVDF (SCHED_NORMAL)Everything elseProportional fair share, weighted by nice.
Idle (SCHED_IDLE)BackgroundRuns only when nothing else is runnable.

A higher class always preempts a lower one, so a busy SCHED_FIFO task can starve normal tasks — why RT priorities are used sparingly.

CFS — the fair scheduler

The Completely Fair Scheduler (in recent kernels, refined by EEVDF) models an ideal "everyone runs at once" CPU and picks whoever is most behind:

Preemption & the context switch

Multiprocessor: run queues & balancing

Likely interview questions

Kernel Internals series. Related: Processes · Low-Latency.