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.
| Event | Who triggers it | What happens to the thread |
|---|---|---|
| Quantum expiry | Timer interrupt | Moved back to the run queue |
| Blocking call | The thread itself | Moved to a wait queue until I/O completes |
| Voluntary yield | The thread itself | Placed behind peers of equal priority |
| Higher-priority wakeup | Scheduler on wakeup | Preempted early, quantum often preserved |
| Thread exit | The thread itself | Resources released, no requeue |
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.
| Scheduler | How the slice is set | Typical range |
|---|---|---|
| Windows client | Multiples of the clock interval, foreground boost | About 20-60 ms |
| Windows Server | Longer fixed quanta for throughput | About 120-180 ms |
| Linux CFS | Target latency divided among runnable tasks | About 0.75-6 ms per task |
| Linux EEVDF | Request size per task, default near 3 ms | Roughly 1-6 ms |
| Linux SCHED_RR | Fixed round-robin quantum for real-time tasks | 100 ms by default |
| Classic UNIX | Fixed ticks with priority decay | About 100 ms |
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.
| Property | Short quantum | Long quantum |
|---|---|---|
| Interactive response | Fast and smooth | Noticeable lag under load |
| Context switch rate | High | Low |
| Cache efficiency | Lower, frequent eviction | Higher, warm caches persist |
| Throughput for batch work | Reduced | Improved |
| Behavior in round-robin | Fair rotation | Approaches first-come, first-served |
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.
| Technique | Mechanism | Goal |
|---|---|---|
| Priority-based quanta | Longer slices at lower queue levels | Favor interactive tasks |
| Weight-proportional slices | Slice scales with nice or weight | Proportional fairness |
| Foreground boost | Active window gets a longer slice | Perceived responsiveness |
| Tickless operation | One-shot timers instead of periodic ticks | Lower power and jitter |
| Slice extension requests | Thread asks to finish a critical section | Avoid lock-holder preemption |
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.