AboutBlogContact
System EngineeringDecember 28, 2003 2 min read 22

Linux 2.6: The O(1) Scheduler Revolution (2003)

AunimedaAunimeda
📋 Table of Contents

Linux 2.6: The O(1) Scheduler Revolution

In the old 2.4 kernel, the scheduler had a dirty secret: it was $O(n)$. Every time the kernel needed to pick a new process to run, it had to iterate through every runnable process. If you had 10,000 processes, your system spent more time thinking about what to do than actually doing it.

Ingo Molnar's new $O(1)$ scheduler in Kernel 2.6.0 fixes this once and for all.

How it Works: Two Arrays

The scheduler maintains two "priority arrays" per CPU: active and expired.

  1. It picks the highest priority task from the active array.
  2. When a task uses up its time slice, it's moved to the expired array.
  3. When the active array is empty, the two arrays are swapped (a simple pointer flip).

Since the kernel uses bitfields to track which priority levels have tasks, finding the next task takes the same amount of time whether you have 10 processes or 10,000.

Interactive "Bonus"

The scheduler also tries to be smart about "interactivity." If a process sleeps a lot (like a text editor waiting for keystrokes), it gets a priority "bonus." If it's a CPU-hogging compile job, it gets penalized. This makes the 2.6 desktop feel incredibly snappy compared to 2.4.

Preemption is Here

For the first time, the Linux kernel is now "preemptible." This means even if the kernel is busy doing a system call, a high-priority user process can kick it off the CPU. This is a massive win for audio processing and real-time applications.

If you're still running 2.4 on your production web servers, it's time to plan the migration. The 2.6 kernel isn't just an update; it's a fundamental shift in how Linux handles massive scale.

Read Also

Kafka: Zero-Copy and Why It's Fast (2015)aunimeda
System Engineering

Kafka: Zero-Copy and Why It's Fast (2015)

How does Kafka push gigabits of data on commodity hardware? The secret isn't in the code; it's in the Linux kernel's sendfile() call.

Apache 2.0: Prefork vs. Worker MPM (2002)aunimeda
System Engineering

Apache 2.0: Prefork vs. Worker MPM (2002)

The multi-processing revolution is here. Should you stick with the stable prefork model or risk the high-concurrency worker threads?

Hunting Memory Leaks: Glibc Malloc Tuning (2001)aunimeda
System Engineering

Hunting Memory Leaks: Glibc Malloc Tuning (2001)

Is your long-running C daemon slowly consuming the entire server's RAM? Learn how to use MALLOC_CHECK_ and mallopt to keep glibc under control.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles