English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Time Slice Extension: The Decade-Long Saga of a Linux Scheduler Patch

Forum topic · ✨步子哥 · 2026-01-28

Summary

The Time Slice Extension patch, recently merged into the tip.git sched/core branch, resolves a long-standing Linux kernel problem: unnecessary preemption of threads holding short user-space spinlocks, which causes throughput collapse and tail-latency spikes. Since the Completely Fair Scheduler (CFS) replaced fixed time slices with vruntime-based fairness in 2007, any mechanism to extend a running thread's slice has clashed with the scheduler's fairness model. Attempts since roughly 2010 failed over three issues: how user space can safely signal the kernel without a costly syscall, how to prevent abuse and starvation, and how to preserve CFS accounting. The breakthrough came from reusing RSEQ (Restartable Sequences): extension is offered only while a kernel-verified RSEQ critical section is active. Thomas Gleixner describes the mechanism as an "opportunistic priority ceiling"—best-effort, capped, and non-guaranteed, unlike traditional priority inheritance. Developed to v6 by RSEQ author Mathieu Desnoyers and Gleixner, the patch is expected to reach mainline in an upcoming merge window, quietly improving p99/p99.9 latency for Redis, PostgreSQL, allocators, and other high-concurrency workloads.

Time Slice Extension: The Decade-Long Saga of a Linux Scheduler Patch

Time Slices: CPU "Shift Schedule" or "Fair Referee"?

Imagine working as a waiter in a busy restaurant where the boss requires everyone to rotate every 10 minutes. This is the classic "time slice" concept—the core logic of Linux's early schedulers: give each process a fixed slice, forcibly switch it out when the slice expires, and let the next process run. Sounds perfectly fair.

But ask a real Linux kernel engineer "why does a process get switched out?" and they will shake their head: "Not because the time slice ran out, but because the scheduler decided that switching now is fairer for the system as a whole."

This is the fundamental shift brought by CFS (Completely Fair Scheduler), introduced in 2007. It is no longer a mechanical timer but a shrewd referee that uses each process's "virtual runtime" (vruntime) to decide who runs and who rests. The smaller the vruntime, the more CPU time the process is "owed," and the higher its priority to run.

Because CFS cares so much about overall fairness, any attempt to "sneakily extend a process's time slice" is like cheating under the referee's nose—it touches the entire scheduling system's nerves. That is why the Time Slice Extension patch has kept the Linux community busy for a full decade.

The Awkwardness of User-Space Locks: When "Brief" Becomes "Disaster"

A closer analogy: imagine a relay race where the baton has a million-dollar lottery ticket attached. You only need to run 10 meters to pass it on, but at meter 5 the referee blows the whistle: "Time's up! Swap!" You stop, the baton is confiscated, and the next runner finds no baton and just spins in place.

In high-concurrency Linux systems, this absurd scenario plays out daily—except the baton is a user-space spinlock.

Thread A holds the lock and is operating on shared data in an extremely short critical section—so short that entering the kernel or sleeping isn't worth it, typically hundreds of nanoseconds to a few microseconds. Thread B wakes up, finds the lock held, and spins waiting.

If the scheduler forcibly switches out A because its time slice happens to expire, disaster strikes: CPU cores are burned by B's useless spinning while A, the thread that would actually make progress, sits in the run queue. Throughput plummets and tail latency soars—everyone loses.

This isn't a theoretical edge case. User-space locks are widely used in modern multicore systems:

  • glibc's memory allocator
  • High-performance allocators like jemalloc/tcmalloc
  • User-space concurrency structures in various database engines
  • High-frequency trading systems
  • Game servers
  • All these scenarios share a trait: extremely short, highly deterministic critical sections where unnecessary preemption actually degrades overall performance.

    Thomas Gleixner's Precise Definition: An "Opportunistic Priority Ceiling"

    Thomas Gleixner, the kernel engineer at Intel's Linutronix famous as the "maintainer of the time subsystem," gave the patch an elegant definition in its cover letter:

    > Time Slice Extension is an "opportunistic priority ceiling."

    This statement is packed with information:

    First, it is not traditional priority inheritance. Traditional priority inheritance dynamically adjusts scheduling entity weights, modifies vruntime, reorders the red-black tree, or changes nice values—operations that are expensive, far-reaching, and can easily break CFS's fairness model.

    Time Slice Extension touches none of that. It only, when specific conditions are met, quietly extends the current time slice "a little," giving the thread a chance to finish its brief critical section.

    Second, it is "opportunistic"—extension happens only when it "just happens to be possible," with no promise of success and no real-time guarantee. Under heavy system load or severe vruntime deficit, the scheduler will still switch the thread out without mercy.

    This is the essence of Linux philosophy: best-effort optimization, not hard-realtime promises.

    A Decade of Failure: Why Did Previous Attempts Die?

    The need isn't new. Around 2010, similar ideas appeared on LKML (Linux Kernel Mailing List), but each round died in the same pits.

    Problem 1: How can user space safely tell the kernel "I'm critical right now"?

    A syscall like please_dont_preempt_me() is too expensive—one call could negate the entire benefit of the critical section, violating the syscall-free fast path's intent. Fully implicit signaling means the kernel has no idea what you're doing, user space can lie freely, and safety and fairness collapse.

    Problem 2: How to prevent abuse?

    If any process could declare "I'm important, don't preempt me," malicious or poorly written programs could easily starve others, rendering the scheduler useless.

    Problem 3: Inherent conflict with CFS's fairness model.

    CFS's core is precise vruntime accounting; any privileged extension requires extreme care. Even a few extra microseconds for one process can accumulate into unfairness over long timescales.

    These three mountains crushed attempt after attempt.

    RSEQ: The Quiet Turning Point That Changed the Game

    The real breakthrough came from a seemingly unrelated feature—RSEQ (Restartable Sequences).

    RSEQ is a user-space atomic operation mechanism provided by the kernel: users register a "restartable" code region, and if it's interrupted by preemption, CPU migration, or a signal, the kernel automatically rolls the program counter back to the start for re-execution.

    It is already widely adopted:

  • glibc uses it for faster getcpu() and user-space atomics
  • jemalloc uses it to accelerate allocation
  • Databases like PostgreSQL and Redis use it for concurrency control
  • Various high-performance locks and lock-free data structures
  • The key: once a critical section is registered via RSEQ, the kernel already "partially knows" the current thread is executing a special code segment requiring integrity.

    This transforms the problem from "user space arbitrarily demanding things from the kernel" into "slightly relaxing preemption conditions within a kernel-sanctioned, controlled, verifiable critical region."

    Time Slice Extension rides RSEQ's coattails: extension can only trigger while an RSEQ critical section is active. The extension is capped, condition-checked, and fully opportunistic.

    This design solves safety and abuse concerns while barely disturbing CFS's fairness model—a perfect Linux-style compromise.

    From Repeated Failure to tip/sched/core: A Long Victory

    Over the past decade-plus, the patch went through countless versions and rejections. But in 2025–2026, a new version driven jointly by Mathieu Desnoyers (RSEQ's original author) and Thomas Gleixner iterated to v6.

    The most exciting news: the latest version has been merged into tip.git's sched/core branch.

    For kernel developers, this is hugely significant. tip.git is Peter Zijlstra's main scheduler development repository, and sched/core is the "quasi-entrance" for all scheduler changes. Getting in means:

  • The design direction is endorsed by the scheduling subsystem maintainer
  • Code quality meets long-term maintainability standards
  • Risk has been assessed as acceptable
  • This is practically one foot in mainline. At the next merge window (likely for an odd-numbered release such as 6.21 or 7.0), it will likely be submitted to Linus Torvalds along with other scheduler changes.

    What Does This Mean for Ordinary Users and Operators?

    Time Slice Extension won't change the world overnight like eBPF, and you won't see dramatic changes in top. But it will quietly improve:

  • Tail latency (p99, p99.9) of high-concurrency applications
  • Throughput stability under user-space lock contention
  • "Inexplicable" jitter under multicore load
  • If you run Redis, PostgreSQL, game servers, microservice frameworks, or any datacenter workload relying on high-performance user-space concurrency, this patch will silently save you CPU cycles and electricity after a future kernel upgrade.

    This is what makes Linux so fascinating: behind a seemingly trivial scheduling optimization lies over a decade of engineers' debates, failures, retries, and compromises, finally landing in the most conservative, most elegant way. Once merged, it will become as foundational—and as irremovable—as CFS and RSEQ.

    Epilogue: Linux's Long-Termism

    The Time Slice Extension story is a microcosm of Linux kernel development philosophy:

  • The problem was often raised over a decade ago
  • Solutions go through countless failures and iterations
  • Short-term performance is never sacrificed for long-term maintainability and fairness
  • Final victories often come from clever reuse of existing mechanisms (here, RSEQ)
Next time a "waited ten years" patch finally lands, applaud the engineers who persisted on LKML. What they guard is not just code, but the soul of Linux as the world's most critical infrastructure—reliable, fair, never compromising.

------

References

1. Man Tan Jun. Why did a "time slice" trouble Linux for ten years? [EB/OL]. Yunwei Mantan WeChat public account, 2026-01-25. 2. Thomas Gleixner. [PATCH v6 0/6] sched: Time slice extension mechanism [R]. LKML, 2025. 3. Mathieu Desnoyers. Restartable Sequences (RSEQ) kernel ABI [R]. Linux Kernel Documentation, 2019–2025. 4. Peter Zijlstra. CFS Scheduler Documentation [R]. Linux Kernel source tree: Documentation/scheduler/sched-cfs.txt. 5. Ingo Molnar. Completely Fair Scheduler (CFS) introduction [R]. LKML announcement, 2007.

Tags

#linux-kernel#scheduler#cfs#rseq#time-slice-extension#thomas-gleixner#user-space-spinlock#tail-latency

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/176922617