Not All Processes Are Equal
Before diving into the default scheduler, it helps to understand that Linux does not use a single scheduling algorithm for all processes. Instead, it uses a layered system of scheduling classes, each with its own policy and priority level.
Think of it like a hospital emergency room. Walk-in patients (normal processes) are seen in order of need. But if a trauma patient (real-time process) arrives, they immediately jump the queue regardless of how long others have been waiting.
Linux scheduling classes, from highest to lowest priority:
| Class | Policy | Use Case |
|---|---|---|
SCHED_DEADLINE |
Earliest Deadline First (EDF) | Hard real-time with known deadlines |
SCHED_FIFO |
First-In, First-Out | Real-time, runs until done or blocked |
SCHED_RR |
Round-Robin | Real-time, with time slices |
SCHED_OTHER |
CFS (Completely Fair Scheduler) | Default for all normal processes |
SCHED_BATCH |
CFS variant | CPU-intensive batch jobs |
SCHED_IDLE |
Lowest possible | Background tasks, only when CPU is idle |
The kernel always runs the highest-priority runnable task. A SCHED_FIFO task will always preempt a SCHED_OTHER task. A SCHED_DEADLINE task will preempt everything else. This hierarchy is the foundation on which all other scheduling decisions are built.