Time slice

Also known as: time quantum

On this page 7

A time slice, also called a time quantum, is the maximum interval of processor time that a preemptive scheduler grants a thread before it may hand the CPU to another runnable thread. In the field of Processes & scheduling within operating systems, the time slice is the basic unit of CPU time sharing: it determines how often the kernel interrupts a running task, how quickly interactive programs respond and how much time is lost to context switches.

The idea dates back to the time-sharing systems of the 1960s and remains central in every modern general-purpose kernel. Choosing its length is a classic trade-off between responsiveness and throughput, and modern schedulers increasingly compute it dynamically rather than using one fixed value.

How a time slice is enforced

A time slice is enforced by the timer interrupt, which lets the kernel regain control from a running thread at regular intervals. When a thread is dispatched, the scheduler records its remaining quantum; on each timer tick, or at a programmed one-shot deadline, the kernel subtracts elapsed time and checks whether the quantum has expired.

When the quantum runs out, the kernel sets a reschedule flag and, on the return path from the interrupt, performs preemption: it saves the thread’s registers in its control block, places the thread back in the run queue and selects the next candidate. A thread that blocks on I/O or calls a yield function before its quantum ends gives up the CPU voluntarily, so the slice is an upper bound, not a guaranteed allocation.

The following table lists the main events that end or shorten a running slice.

EventWho triggers itWhat happens to the thread
Quantum expiryTimer interruptMoved back to the run queue
Blocking callThe thread itselfMoved to a wait queue until I/O completes
Voluntary yieldThe thread itselfPlaced behind peers of equal priority
Higher-priority wakeupScheduler on wakeupPreempted early, quantum often preserved
Thread exitThe thread itselfResources released, no requeue
Events that end a running time slice

Typical time slice lengths in real kernels

Typical time slice lengths range from about 1 ms to 100 ms, and the exact value depends on the scheduler design, the priority class and whether the system targets desktops or servers. Older kernels used a fixed number of clock ticks; newer designs derive the slice from the number of runnable tasks and their weights.

The table below summarizes representative approaches. Values are approximate and change with configuration, so they should be read as orders of magnitude rather than constants.

SchedulerHow the slice is setTypical range
Windows clientMultiples of the clock interval, foreground boostAbout 20-60 ms
Windows ServerLonger fixed quanta for throughputAbout 120-180 ms
Linux CFSTarget latency divided among runnable tasksAbout 0.75-6 ms per task
Linux EEVDFRequest size per task, default near 3 msRoughly 1-6 ms
Linux SCHED_RRFixed round-robin quantum for real-time tasks100 ms by default
Classic UNIXFixed ticks with priority decayAbout 100 ms
Representative quantum policies in common kernels

In the Linux Completely Fair Scheduler, a minimum granularity prevents slices from shrinking below a floor when hundreds of tasks are runnable, because extremely short slices would spend more time switching than computing.

The responsiveness and overhead trade-off

The length of a time slice trades interactive latency against switching overhead. A short quantum lets the scheduler cycle through runnable threads quickly, so a keystroke handler or audio thread waits less; a long quantum keeps each thread on the CPU longer, so fewer cycles are lost to saving state and refilling caches.

The direct cost of a context switch is typically a few microseconds, but the indirect cost is often larger: the incoming thread finds cold caches and TLB entries and may run slowly for a while. The table shows how the effects shift with slice length.

PropertyShort quantumLong quantum
Interactive responseFast and smoothNoticeable lag under load
Context switch rateHighLow
Cache efficiencyLower, frequent evictionHigher, warm caches persist
Throughput for batch workReducedImproved
Behavior in round-robinFair rotationApproaches first-come, first-served
Effects of short and long quanta

A common rule of thumb for round-robin scheduling is that roughly 80 percent of CPU bursts should finish within one quantum. If the slice is far shorter than typical bursts, nearly every burst is cut, and the system wastes time on switching without improving responsiveness.

How schedulers adapt the quantum

Modern schedulers adapt the quantum to the workload instead of applying one value to all threads. In a multilevel feedback queue, high-priority levels receive short slices for interactive work, while lower levels receive progressively longer slices for CPU-bound processes that repeatedly exhaust their quantum.

Windows applies a foreground quantum boost, stretching the slice of threads belonging to the active window. Linux fair schedulers compute a slice proportional to a task’s weight, which derives from its nice value, so a task with higher priority receives a larger share within each scheduling period. The table maps common policies to their purpose.

TechniqueMechanismGoal
Priority-based quantaLonger slices at lower queue levelsFavor interactive tasks
Weight-proportional slicesSlice scales with nice or weightProportional fairness
Foreground boostActive window gets a longer slicePerceived responsiveness
Tickless operationOne-shot timers instead of periodic ticksLower power and jitter
Slice extension requestsThread asks to finish a critical sectionAvoid lock-holder preemption
Ways schedulers vary the time slice

Limitations and common misconceptions

Several misunderstandings about the time slice persist even among experienced developers. Recognizing them helps when diagnosing latency spikes or tuning servers.

  • A thread is not guaranteed its full slice; a higher-priority wakeup or an interrupt can preempt it at any moment.
  • The quantum is not the scheduling latency; with many runnable threads, a task may wait several slices before running again.
  • Shortening the slice does not speed up I/O-bound processes, which already block long before their quantum expires.
  • Preempting a thread that holds a spinlock can stall other cores, a problem known as lock-holder preemption, common in virtual machines.
  • Time spent in interrupt handlers may be charged to the running thread, so accounting can be imprecise on busy systems.

For real-time scheduling, quanta matter only within the round-robin class; strict priority or earliest deadline first policies rely on deadlines and priorities rather than equal slices.

Stripped to the essentials

A computer usually has more programs to run than it has processor cores. The operating system solves this by taking turns. Each program gets a short turn on the processor, and that turn is the time slice.

Think of a teacher answering questions from a line of students. Each student gets two minutes, then steps to the back of the line. Nobody waits forever, and everyone gets help. If turns are too short, the teacher spends most of the time switching students. If turns are too long, the others wait too much. The right length keeps the computer both fast and fair.

Where it is applied

A systems administrator runs a build server that compiles large software projects on 16 cores while developers also use it over remote desktop sessions. Under full load, remote typing feels sluggish, with visible delays of 100 ms or more between a keystroke and the echoed character.

Investigation shows that the compiler processes are CPU-bound and consume their entire quantum, while the interactive sessions are queued behind them. The administrator lowers the priority of the build jobs with a higher nice value, so the fair scheduler assigns them smaller weight-proportional slices, and pins the interactive services to two reserved cores.

After the change, keystroke echo drops to a few milliseconds, while total build time rises by only about 3 percent. The case shows that the time slice is rarely tuned directly; it is usually shaped through priorities, weights and core placement.