core26 min studyLesson 135 in Engineering

Separate CPU fairness from response-time promises

Compare proportional CPU sharing, runnable latency, and real-time policy without assuming one universal scheduling quantum.

On this page

What you’ll understand

  • Explain why fairness must specify eligible tasks, weights, and a time interval.
  • Distinguish normal scheduling from FIFO, round-robin, and deadline policy.
  • Use an ideal weighted-share calculation while stating why it is not a latency guarantee.

Scheduling answers which eligible task receives a processor next, but different policies encode different promises. A development server, a batch compilation, and a deadline-sensitive control thread do not necessarily belong to the same policy class. Even the word fair is incomplete until you specify who competes, which weights apply, and over what interval service is compared. This lesson develops a proportional-sharing baseline, then separates that baseline from actual Linux policy, version-specific selection algorithms, and the resource constraints that determine whether a runnable task can execute.

Define the competition before dividing service

Begin with an idealized single CPU and two tasks that remain runnable for the entire observation interval. If they have equal weights and no other competitors, equal CPU service is a reasonable fairness target. If one task has three times the other's weight, the corresponding proportional target is three quarters versus one quarter. Weights describe relative allocation under competition; they are not reservations that create extra hardware capacity. When the lighter task sleeps, the heavier task may use otherwise idle service. When another competitor arrives, the denominator changes. A fair share therefore depends on the eligible competing set, not merely one task's configuration.

Linux normal scheduling includes details that prevent this arithmetic from being a universal prediction. CPU affinity restricts where a task may run, group scheduling distributes service through a hierarchy, and CPU quotas can throttle a group even when a thread remains eager to execute. Container CPU weight and maximum bandwidth describe different controls. A weight influences competition; a quota constrains total allowed consumption over its configured period. A task can have a large relative weight yet be periodically throttled by a small quota. Before diagnosing unfairness, identify its effective CPU set, scheduling policy, group hierarchy, and bandwidth restrictions, then ask which tasks actually competed.

Siideal=Twi∑j∈RwjS_i^{\mathrm{ideal}}=T\frac{w_i}{\sum_{j\in\mathcal R}w_j}
For a fixed continuously runnable competitor set R on one fully available CPU, ideal service S_i in seconds over interval T is proportional to positive dimensionless weight w_i. Overheads and policy interference are excluded.↔ Scroll wide equations horizontally.

Selection algorithms evolve while policies remain explicit

Historical explanations of Linux's Completely Fair Scheduler often describe ordering tasks by virtual runtime. Modern kernel documentation describes the transition toward Earliest Eligible Virtual Deadline First, or EEVDF, in the normal scheduling implementation. EEVDF combines eligibility based on service lag with selection using virtual deadlines. Treat these names as version-sensitive implementation concepts rather than assuming every deployed machine follows the same pick-next rule. A virtual deadline used inside a fairness algorithm is not automatically an application deadline guarantee. When investigating a specific kernel, consult the matching source, configuration, and documentation rather than repeating a timeless claim about one tree or one selection heuristic.

There is likewise no single universal Linux timeslice that explains every policy and workload. SCHED_FIFO uses fixed-priority real-time semantics without round-robin expiration at equal priority; SCHED_RR adds round-robin rotation among peers. Normal policies serve other responsiveness and fairness goals. SCHED_DEADLINE uses runtime, deadline, and period parameters with admission and bandwidth mechanisms; accepting its parameters is not a substitute for validating the workload's execution demand and blocking behavior. Changing a thread into a more privileged policy can move delay onto unrelated work. Specify the required timing property first, then choose and test policy rather than using priority as an unexplained performance knob.

Service fairness does not imply response-time fairness

Two tasks can each obtain half a CPU-second over one second while experiencing very different response times. One could run in short interleaved bursts; another pattern could postpone useful service until near the interval's end. Their accumulated shares match, but an interactive request distinguishes them immediately. Conversely, a sleeping task cannot demand service for time during which it was not runnable merely by comparing lifetime totals. Measure runnable waiting intervals, wakeup-to-dispatch delay, completed work, and accumulated CPU service separately. Decide whether your objective is bounded latency, proportional throughput, or isolation under contention, because a single average CPU percentage cannot establish all three properties.

The queue lab exposes only the capacity side of this discussion. Its arrival rate and service rate move a fluid backlog, starting from four work units; they do not assign tasks to scheduling classes or implement EEVDF. Compare smaller and larger assumed CPU allocations through separate fixed-rate runs: arrival 2 with service 1 versus arrival 2 with service 3. Before each run, press Reset, re-set both rates, predict whether its initial four work units grow or drain, then press Play or Step. These runs do not model a live allocation change applied to an accumulated backlog. The M/M/1 residence-time expression is a separate stochastic idealization valid only below saturation with its stated assumptions. Neither curve proves that a real task will meet a deadline. To connect the illustration to deployment, reproduce a controlled workload, observe per-task scheduling events and group throttling, and compare the evidence against the timing property you actually need.

ρ=λμ,ρ<1\rho=\frac{\lambda}{\mu},\qquad \rho<1
For the separate steady-state M/M/1 model, arrival and service rates have the same work-per-second units. Utilization below one is necessary for its finite mean residence time; it does not express a CPU scheduler deadline guarantee.↔ Scroll wide equations horizontally.

An ideal two-task service allocation

Assume one fully available CPU, two continuously runnable tasks, weights 3 and 1, and a 40 millisecond observation interval. Ignore overhead, sleeping, quotas, and higher-policy interference. Compute ideal service.

  1. Add the positive weights: 3 + 1 = 4.

  2. Allocate 40 milliseconds × 3/4 = 30 milliseconds of ideal CPU service to the first task.

  3. Allocate 40 milliseconds × 1/4 = 10 milliseconds to the second; verify the total remains 40 milliseconds.

(S1,S2)=40 ms(34,14)=(30,10) ms(S_1,S_2)=40\,\mathrm{ms}\left(\frac34,\frac14\right)=(30,10)\,\mathrm{ms}
This is a fixed-competitor fluid sharing calculation, not a trace of a particular Linux scheduler.↔ Scroll wide equations horizontally.
The result

The ideal allocation is 30 ms and 10 ms. This proportional baseline does not determine the exact execution order or either task's worst dispatch delay.

Explore the model

Interactive lab

Interactive lab · queue

Allocation becomes service capacity

Compare separate fixed-rate runs with λ=2, μ=1 and λ=2, μ=3. For each: Reset, re-set both rates, predict growth or drainage from four work units, then Play or Step. Changing a rate alone retains elapsed time rather than starting a new capacity phase. A CPU allocation can motivate an assumed capacity, but the lab has no runnable tasks, scheduling classes, or EEVDF selection.

Allocation becomes service capacityFluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Current readings: Fluid backlog: 4; Net rate · λ − μ: −1 /s; M/M/1 mean residence: 1 s. All parameters are adjustable with the labeled controls below.02.557.51001.534.56Elapsed time · sFluid backlogλ < μ
Fluid backlogCurrent time
Fluid backlog
4
Net rate · λ − μ
−1 /s
M/M/1 mean residence
1 s
t = 0 s

Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forCapacity and timing policy answer different questions. A draining aggregate backlog alone cannot prove fair per-task service or deadline compliance.

Check your understanding

Two continuously runnable tasks have weights 3 and 1 in an ideal isolated single-CPU sharing model. What can the 3:1 ratio establish?

Try it yourself

Three tasks have ideal weights 2, 1, and 1 on one CPU for 80 ms, all continuously runnable with no overhead or other interference. Compute service and explain why the answer is not a response-time bound.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Normalize each weight by four. Accumulated service does not specify when that service occurs.

Compare with the solution

Ideal service is 40 ms, 20 ms, and 20 ms. These totals alone leave the order and spacing of dispatches unspecified, so they cannot bound an individual request's waiting time.

(S1,S2,S3)=80 ms(24,14,14)=(40,20,20) ms(S_1,S_2,S_3)=80\,\mathrm{ms}\left(\frac24,\frac14,\frac14\right)=(40,20,20)\,\mathrm{ms}
The shares are conditional on a fixed continuously runnable set and a fully available processor.↔ Scroll wide equations horizontally.

Take it with you

  • Fairness needs an eligible competitor set, relative weights, and an observation interval.
  • Normal scheduling implementation evolves; EEVDF virtual deadlines differ from application deadline contracts.
  • Separate service shares, quotas, and runnable latency when evaluating a scheduling configuration.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.