Linux Internals
How the Linux CFS and EEVDF Schedulers Share CPU Time on a VPS
By NileVPS Team · Published · 5 min read
اقرأ المقال بالعربيEvery running Linux system has more runnable threads than CPUs at some point, and something has to decide who runs next and for how long. That something is the process scheduler. For more than fifteen years the default policy for normal tasks was the Completely Fair Scheduler (CFS); since kernel 6.6 it has been replaced by EEVDF, which keeps the same fairness goals but makes latency behaviour more predictable. Understanding how both work explains why a busy cron job slows down your web server, what nice really does, and why a VPS can feel slow even when top shows idle CPU.
The idea behind CFS
CFS models an "ideal multitasking CPU": if three equally important tasks are runnable, each should get exactly one third of the processor at every instant. Real hardware cannot do that, so CFS approximates it by tracking how much CPU time each task has received and always running the one that has received the least.
Virtual runtime
The central quantity is vruntime, a per-task counter of consumed CPU time scaled by the task's weight. A task with the default weight accumulates vruntime at wall-clock speed; a heavier (more important) task accumulates it more slowly, so it is picked more often. Runnable tasks sit in a red-black tree ordered by vruntime, and the leftmost node, the one with the smallest value, runs next. Picking the next task is effectively O(1) because the leftmost node is cached, and insertion is O(log n).
Weights and nice values
The weight comes from the nice value, which ranges from -20 to 19. Nice 0 maps to a weight of 1024, and every step changes the weight by roughly 25 percent. The practical result is that two CPU-bound tasks one nice level apart split the CPU about 55/45, and a task at nice 19 gets a tiny share when competing with nice 0 work. Nice is relative: a lone task at nice 19 still gets the whole CPU if nobody else wants it.
ps -eo pid,ni,pri,comm --sort=ni | head
renice -n 10 -p 12345
nice -n 15 tar czf backup.tgz /var/wwwEEVDF in kernel 6.6 and later
CFS used a set of heuristics, such as sched_latency_ns, sched_min_granularity_ns and wakeup preemption rules, to decide how long a task could run before being preempted. Those knobs interacted in ways that were hard to reason about. EEVDF (Earliest Eligible Virtual Deadline First) replaces most of them with a cleaner model:
- Lag measures how much service a task is owed compared with its fair share. A task with non-negative lag is *eligible* to run.
- Each task requests a slice of time and receives a virtual deadline equal to its eligible time plus the slice scaled by its weight.
- Among eligible tasks, the scheduler runs the one with the earliest virtual deadline.
Fairness over the long term is unchanged, but latency-sensitive tasks with short slices get earlier deadlines and therefore run sooner after waking. The default slice is exposed at /sys/kernel/debug/sched/base_slice_ns (debugfs must be mounted). Since kernel 5.13, the old CFS tunables also moved from /proc/sys/kernel/ to /sys/kernel/debug/sched/, so guides that tell you to sysctl kernel.sched_latency_ns are out of date on modern distributions.
Check which kernel you run with uname -r. Ubuntu 24.04 HWE kernels, Debian 13 and recent Fedora releases all ship EEVDF.
Groups: cgroups and cpu.weight
Fairness is applied hierarchically. With cgroup v2, which systemd uses by default, each service or container is a group, and the scheduler first shares CPU between groups, then between tasks inside each group. A container running 50 threads does not automatically beat a service running two.
The share is controlled by cpu.weight (range 1 to 10000, default 100). A hard ceiling is set by cpu.max, written as quota period in microseconds.
cat /sys/fs/cgroup/system.slice/nginx.service/cpu.weight
systemctl set-property backup.service CPUWeight=20
systemctl set-property worker.service CPUQuota=150%
cat /sys/fs/cgroup/system.slice/worker.service/cpu.statIn cpu.stat, nr_throttled and throttled_usec tell you whether a quota is actually biting. Docker's --cpus and --cpu-shares map onto the same controls.
How this affects your VPS
A VPS adds a second scheduler layer: the hypervisor schedules your vCPUs onto physical cores, and inside the guest the Linux scheduler schedules your threads onto those vCPUs. When the host gives a physical core to another guest while your vCPU wanted to run, the guest kernel records that time as steal.
top # look at the "st" value in the %Cpu(s) line
vmstat 1 5 # the "st" column
mpstat -P ALL 1 3
grep '^cpu ' /proc/stat # the 8th value is steal, in USER_HZ ticksA few percent of steal is normal on shared infrastructure; sustained double-digit steal means you are not getting the CPU time you expect, and no amount of tuning inside the guest fixes it. Choosing a plan with dedicated or less contended cores is the real fix, which is why the plans on our pricing page list vCPU allocation clearly.
Inside the guest, these tools show what the scheduler is doing:
cat /proc/loadavg # runnable plus uninterruptible tasks
pidstat -w 1 # voluntary and involuntary context switches
cat /proc/12345/sched # per-task vruntime, nr_switches, wait stats
sudo perf sched record -- sleep 5 && sudo perf sched latencyHigh involuntary context switches (nivcsw) on your application mean it is being preempted, usually by competing CPU-bound work. Move that work to a lower nice level or a lower CPUWeight cgroup. If wait times in perf sched latency are high while steal is also high, the bottleneck is the host, not your configuration. Interrupt handling also eats CPU time outside the scheduler's view; see our article on softirqs and ksoftirqd for that side of the picture.
FAQ
Is EEVDF faster than CFS?
Not in raw throughput; both aim to give each task its fair share. EEVDF mainly improves latency consistency, because a task's position is decided by an explicit virtual deadline instead of a pile of heuristics. Interactive and request-response workloads tend to benefit most.
Should I run my database at a negative nice value?
Usually it is better to lower the priority of background jobs than to raise the priority of the database. Negative nice values require root and can starve other services, including SSH, if the database misbehaves. A cgroup CPUWeight setting gives you the same effect with clearer limits.
Why is my load average high when CPU usage looks low?
Load average counts tasks in uninterruptible sleep, typically waiting on disk or network storage, as well as runnable tasks. Check vmstat 1 for the b and wa columns. On a VPS, high steal can also inflate load because runnable tasks wait longer for a vCPU.