9.3. CPU Scheduling and Placement
One CPU core executes one task at a time. Everything else that looks
concurrent - a web server, a compile, a music player - is the kernel's
scheduler switching tasks hundreds of times a second, and the scheduler's
policy for a task decides both how much CPU it gets and, in some cases,
whether it is guaranteed to get any. This section covers the policies, the
tools that set them (nice, renice, chrt, taskset), and the systemd
layer that applies them to whole services. The example machine has two CPUs
(/proc/cpuinfo counts two processors), which keeps every experiment small
enough to reason about.
9.3.1. Scheduling Classes and Normal, Batch, Idle, FIFO, Round-Robin, and Deadline Policies
Linux groups scheduling policies into three classes. The fair class -
SCHED_OTHER (the default), SCHED_BATCH, and SCHED_IDLE - divides each
CPU among all runnable tasks by weight. The real-time class -
SCHED_FIFO and SCHED_RR - always beats the fair class: an RT task that
never blocks never yields the CPU voluntarily to a fair task. Above both,
SCHED_DEADLINE gives a task a fixed slice of CPU per period using earliest
deadline first, and the kernel admits such tasks only if their guarantees
still fit on the CPU. Figure 9.2 shows the ordering and the safety margin
that keeps RT load from owning the machine outright.
Figure 9.2. Conceptual view of the scheduling classes on Debian 13. Higher tiers preempt lower ones; the RT bandwidth reserve throttles real-time tasks so kernel housekeeping keeps running.
| Policy | Set with | Priority or parameters | Who may set it | Behaviour |
|---|---|---|---|---|
SCHED_OTHER |
default | nice 19 to -20 | anyone, for own tasks | Fair share by weight; interactive tasks get fast wakeups. |
SCHED_BATCH |
chrt -b 0 |
nice, as above | anyone, for own tasks | Fair share, but treated as CPU-bound: no interactive wakeup boost. |
SCHED_IDLE |
chrt -i 0 |
none | anyone, for own tasks | Runs only when nothing else needs the CPU. |
SCHED_FIFO |
chrt -f 1..99 |
fixed RT priority | root (CAP_SYS_NICE) | Runs until it blocks or yields; preempts everything below its priority. |
SCHED_RR |
chrt -r 1..99 |
fixed RT priority | root (CAP_SYS_NICE) | Like FIFO, but equal-priority RT tasks share the CPU in slices. |
SCHED_DEADLINE |
chrt -d --sched-runtime --sched-period --sched-deadline |
runtime/period in ns | root (CAP_SYS_NICE) | Guaranteed slice per period if the kernel admits the task. |
The kernel publishes each policy's valid priority range; ask chrt itself:
$ chrt -m
SCHED_OTHER min/max priority : 0/0
SCHED_FIFO min/max priority : 1/99
SCHED_RR min/max priority : 1/99
SCHED_BATCH min/max priority : 0/0
SCHED_IDLE min/max priority : 0/0
SCHED_DEADLINE min/max priority : 0/0
Only FIFO and RR use the priority number, 1 to 99; the fair policies and
DEADLINE have no priority knob - their "importance" is the nice value and
the runtime/period parameters respectively. The tabs in the output are
chrt's own formatting.
9.3.2. Fair Scheduling, EEVDF, and the Difference Between Priority and Latency
Debian 13's 6.12 kernel schedules the fair class with EEVDF - Earliest Eligible Virtual Deadline First - which replaced the older CFS algorithm in kernel 6.6. The mechanism is worth one paragraph because it explains everything the tools report. Each runnable task carries a weight derived from its nice value. The scheduler advances each task's virtual time faster the lower its weight, so a light task "consumes" its entitlement quickly. A task whose virtual time is behind its entitlement is eligible; among eligible tasks, the one with the earliest virtual deadline is picked first. The consequences in practice: CPU time is shared in proportion to weight; a task that sleeps loses no ground because its virtual time does not advance while it sleeps; and each task's response interval follows from its own weight instead of a fixed system-wide epoch.
The weight table maps nice values to weights multiplicatively - each step down in nice multiplies the weight by about 1.25:
| Nice | Weight |
|---|---|
| -20 | 88761 |
| 0 | 1024 |
| 10 | 110 |
| 19 | 15 |
A nice-19 task therefore weighs about 1/68 of a nice-0 task - the ratio measured directly in Section 9.3.8. Your own login shell is a fair-class task like any other:
$ chrt -p $$
pid 9088's current scheduling policy: SCHED_OTHER
pid 9088's current scheduling priority: 0
pid 9088's current runtime parameter: 1400000
$$ expands to the shell's own PID, so this inspects the shell running the
command: SCHED_OTHER, priority 0 - the defaults. The third line reports
the timeslice the fair class currently uses for this task, in nanoseconds; a
kernel-managed value, not something you configured.
Priority and latency are different currencies, and mixing them up is the
most common scheduling mistake. Nice (and weight) buys a share: under
contention, a heavier task gets more CPU seconds per second. It buys no
latency: a fair-class task must still wait for the scheduler to pick it,
and no nice value makes the kernel respond to it within microseconds.
Conversely, SCHED_BATCH and SCHED_IDLE are not "lower latency made
worse" - they mark a task as non-interactive so the scheduler stops giving
it the fast wakeups that interactive tasks get, which is exactly right for
a backup or index rebuild that should never pre-empt a user's editor. When a
task genuinely must run now, the answer is an RT policy or
SCHED_DEADLINE, not a bigger nice.
9.3.3. Inspecting and Changing Niceness with nice and renice
The nice value runs from 19 (lowest share) to -20 (highest); 0 is the default. Positive values are the polite ones: any user may raise their own task's nice, and child processes inherit it. Lowering nice - raising the task's entitlement - needs root, because on a shared machine it is taking something from everyone else.
| Command | Description |
|---|---|
nice -n N command |
Run command starting at nice N (19 to -20; negative needs root). |
renice -n N -p PID |
Change the nice of a running process to N. |
renice -n N -u user |
Change every process of user. |
ps -o pid,ni,cls,rtprio,cmd |
Show nice (NI), class (CLS), and RT priority columns. |
Start a sleep at nice 10 and confirm:
$ nohup nice -n 10 sleep 120 >/dev/null 2>&1 &
$ echo $! > nice.pid
$ ps -o pid,ni,cls,rtprio,cmd -p $(cat nice.pid)
PID NI CLS RTPRIO CMD
9108 10 TS - sleep 120
The first two commands print nothing (a background start plus a PID saved to
nice.pid). NI 10 is the nice value just requested; CLS TS is the
scheduling class - TS (time-sharing) is how ps labels SCHED_OTHER;
RTPRIO - means "not an RT task". Now change it while it runs. Lowering a
task's priority is a courtesy anyone may perform for their own processes,
but this change runs as root to show the general form - in the root shell
(sudo -i from john's shell; leave it with exit when done):
# renice -n 15 -p 9108
9108 (process ID) old priority 10, new priority 15
renice reports the change it made. Verify from john's shell that the
process really runs at nice 15 now:
$ ps -o pid,ni,cmd -p 9108
PID NI CMD
9108 15 sleep 120
The process is the same one - PID 9108 - with its weight lowered a second
time. To go the other way (renice -n 5 -p 9108, a higher priority), root
is mandatory; as john it fails with Permission denied.
9.3.4. Inspecting and Selecting Scheduling Policies with chrt
chrt reads and sets the policy itself, where nice only adjusts the
weight inside the fair class. Its options:
| Option | Description |
|---|---|
-p PID |
Print the policy and priority of a running process. |
-m |
List the valid priority ranges for each policy. |
-b 0 / -i 0 |
Start a command under SCHED_BATCH / SCHED_IDLE. |
-f N / -r N |
Start a command under SCHED_FIFO / SCHED_RR at priority N. |
-d --sched-runtime --sched-period --sched-deadline |
Start a command under SCHED_DEADLINE with ns parameters. |
The fair-class variants are unprivileged - they only ever lower a task's standing. From john's shell:
$ chrt -b 0 sleep 120 &
$ echo $! > batch.pid
$ sleep 0.2
$ chrt -p $(cat batch.pid)
pid 9219's current scheduling policy: SCHED_BATCH
pid 9219's current scheduling priority: 0
pid 9219's current runtime parameter: 1400000
$ kill -TERM $(cat batch.pid)
Everything except the chrt -p output is silent: the sleep starts in the
background under SCHED_BATCH, its PID is recorded, and kill ends it when
the check is done. The readback confirms the policy and that batch is a
fair-class policy - priority 0 and the same timeslice hint as before. The
idle variant works the same way:
$ chrt -i 0 sleep 120 &
$ echo $! > idle.pid
$ sleep 0.2
$ chrt -p $(cat idle.pid)
pid 9241's current scheduling policy: SCHED_IDLE
pid 9241's current scheduling priority: 0
$ kill -TERM $(cat idle.pid)
The real-time policies are different: they can starve the system, so the
kernel requires CAP_SYS_NICE - root in practice. Try it as john first:
$ chrt -f 20 sleep 5
chrt: failed to set pid 0's policy: Operation not permitted
chrt reports the kernel's refusal - Operation not permitted, the
EPERM from the missing capability. In the root shell, the same request
succeeds; the bounded sequence starts an RT sleep in the background,
inspects it, and terminates it:
# chrt -f 20 sleep 20 &
# p=$!
# sleep 0.3
# chrt -p $p
pid 9199's current scheduling policy: SCHED_FIFO
pid 9199's current scheduling priority: 20
# kill -TERM $p
The readback shows SCHED_FIFO at priority 20 - the task that would run
until it chose to stop. Round-robin is identical from the administrator's
point of view, except equal-priority RT tasks rotate:
# chrt -r 10 sleep 20 &
# p=$!
# sleep 0.3
# chrt -p $p
pid 9265's current scheduling policy: SCHED_RR
pid 9265's current scheduling priority: 10
# kill -TERM $p
SCHED_DEADLINE takes three parameters in nanoseconds: a runtime of CPU
to guarantee within each period, with a deadline by which the runtime
must be delivered. In the root shell:
# chrt -d --sched-runtime 900000 --sched-period 3000000 --sched-deadline 0 0 sleep 20 &
# p=$!
# sleep 0.3
# chrt -p $p
pid 9287's current scheduling policy: SCHED_DEADLINE
pid 9287's current scheduling priority: 0
pid 9287's current runtime/deadline/period parameters: 900000/3000000/3000000
# kill -TERM $p
The trailing 0 before the command is the priority field, which deadline
does not use. The readback spells out the contract: 900000 ns of CPU per
3000000 ns period, with the deadline equal to the period because 0 was
given. This is the only policy that guarantees anything: the kernel admits
a deadline task only if the guarantees of all deadline tasks on that CPU
still fit, refusing the request otherwise (man 7 sched documents the
admission rules). A short sleep exercises the mechanics; it does not
demonstrate a deadline workload under sustained load.
9.3.5. CPU Affinity with taskset and the Limits of Affinity as Isolation
Affinity is a different knob: not how much CPU a task may use, but which CPUs it may run on. Every process carries a mask of allowed CPUs; the kernel may move a task within the mask freely but never outside it.
| Option | Description |
|---|---|
taskset -c LIST command |
Run command pinned to the listed CPUs (0, 0,1, 0-3). |
taskset -p PID |
Print the affinity mask of a running process. |
taskset -pc LIST PID |
Change the affinity of a running process. |
Pin a sleep to CPU 0 and confirm:
$ nohup taskset -c 0 sleep 120 >/dev/null 2>&1 &
$ echo $! > affinity.pid
$ taskset -pc $(cat affinity.pid)
pid 9307's current affinity list: 0
$ ps -o pid,psr,cmd -p $(cat affinity.pid)
PID PSR CMD
9307 0 sleep 120
The first two commands are silent setup as before. taskset -pc reports the
allowed set - just CPU 0 - and PSR 0 (the CPU the task last ran on) agrees
that it is staying put. An ordinary user may narrow their own task's mask;
widening it, or touching anyone else's, needs root:
# taskset -pc 1 9307
pid 9307's current affinity list: 0
pid 9307's new affinity list: 1
# taskset -pc 9307
pid 9307's current affinity list: 1
Root re-pinned john's process to CPU 1; the second command confirms the new mask. Two things follow from this little experiment. First, affinity is a request recorded in the kernel, not a property the process defends - root can always change it. Second, and more important: pinning task A to CPU 0 isolates it from nothing, because every other task on the system is also allowed to run on CPU 0. Affinity narrows where a task runs; it does not reserve the CPU, and it does not steer interrupts away from it. Real isolation - dedicating CPUs to one workload - needs the cpuset cgroup controller together with interrupt routing, and is a specialized exercise; for ordinary administration, affinity is a cache-locality and contention tool, while the amount of CPU is better managed with the controls in the next subsection.
9.3.6. Systemd CPU Weights, Quotas, Allowed CPUs, and Cgroup Hierarchies
Everything so far attached to one process at a time. Systemd applies the
same controls to whole units through control groups - cgroups - which the
kernel maintains as a hierarchy in /sys/fs/cgroup; every service, scope,
and slice the manager starts lands in its own cgroup, and the kernel
enforces CPU, memory, and I/O rules on the group. Chapter 8
introduced slices as unit types; here they do their job. Three properties
cover CPU control:
| Property | Meaning |
|---|---|
CPUWeight=N |
Relative share under contention, 1 to 10000, default 100. The cgroup analogue of nice. |
CPUQuota=N% |
Hard ceiling on total CPU time, e.g. 50% is half of one CPU; 200% is both CPUs of this machine. |
AllowedCPUs=list |
The cpuset the unit's processes may run on, as with taskset, but managed and inherited. |
systemd-run starts a transient unit - no unit file, everything from the
command line - which is ideal for exercises. In the root shell:
# systemd-run --unit=handbook-cpu --slice=handbook.slice -p CPUQuota=50% -p CPUWeight=80 -p AllowedCPUs=0,1 sleep 60
Running as unit: handbook-cpu.service; invocation ID: 7d4e25c90bb044d7afaacfc8f9139105
--unit names it, --slice=handbook.slice places it in a fresh slice (the
kernel creates handbook.slice on first use), and each -p sets one
property. The manager reports the unit name and invocation ID. Read the
properties back:
# systemctl show handbook-cpu -p CPUQuotaPerSecUSec -p CPUWeight -p AllowedCPUs -p Slice
Slice=handbook.slice
CPUWeight=80
CPUQuotaPerSecUSec=500ms
AllowedCPUs=0-1
Systemd normalizes what you asked for: CPUQuota=50% becomes
CPUQuotaPerSecUSec=500ms - half a second of CPU per second - and the
allowed list prints in range form. The slice itself carries no CPU settings
of its own:
# systemctl show handbook.slice -p CPUWeight -p CPUQuotaPerSecUSec
CPUWeight=[not set]
CPUQuotaPerSecUSec=infinity
[not set] and infinity are the same statement twice: without an
ancestor limit, the unit's ceiling is the whole machine. See the resulting
hierarchy for yourself - systemd-cgls prints the cgroup tree under a path:
# systemd-cgls --no-pager /handbook.slice
CGroup /handbook.slice:
└─handbook-cpu.service
└─9368 /usr/bin/sleep 60
The slice contains the service, and the service contains its one process. Anything the service later forks joins the same cgroup, which is what makes group limits robust against runaways: a child cannot escape by forking.
The same settings can persist. A slice's configuration lives in a drop-in
(Chapter 8 covered the drop-in mechanism), so create
/etc/systemd/system/handbook.slice.d/50-cpu.conf with this content:
[Slice]
CPUQuota=25%
CPUWeight=50
AllowedCPUs=0
Then load it and start a unit under the slice - in the root shell, three silent steps followed by the run:
# mkdir -p /etc/systemd/system/handbook.slice.d
# systemctl daemon-reload
# systemd-run --unit=handbook-persist --slice=handbook.slice sleep 60
Running as unit: handbook-persist.service; invocation ID: 25eda2bd8fd74c8d8a5c11d1c1470dbb
daemon-reload re-reads unit files and drop-ins; it prints nothing. The
new unit inherits the slice's settings:
# systemctl show handbook-persist -p CPUQuotaPerSecUSec -p CPUWeight -p Slice
Slice=handbook.slice
CPUWeight=[not set]
CPUQuotaPerSecUSec=infinity
The service still sets nothing of its own - the limits live on the slice:
# systemctl show handbook.slice -p CPUQuotaPerSecUSec -p CPUWeight -p AllowedCPUs -p EffectiveCPUs
EffectiveCPUs=0
CPUWeight=50
CPUQuotaPerSecUSec=250ms
AllowedCPUs=0
The slice now shows a quarter of one CPU, weight 50, and a single allowed
CPU. EffectiveCPUs=0 is the computed result along the hierarchy: even a
unit that asked for both CPUs could not escape the slice's cpuset - the
same "nearest ancestor wins" rule that Section 9.6.2 demonstrates with
memory and task limits. Undo the exercise:
# systemctl stop handbook-persist handbook.slice
# rm -rf /etc/systemd/system/handbook.slice.d
# systemctl daemon-reload
All three commands are silent. Stopping the slice stops the service; the
drop-in directory is removed and the manager forgets the settings. Nothing
CPU-related remains of the exercise (the handbook-cpu.service unit ends by
itself when its sleep 60 finishes).
9.3.7. Real-Time Privileges, Runtime Limits, Starvation, and Bounded Recovery
An RT task with a high priority and a tight loop can make a machine unresponsive to everything fair - including the shell you would use to fix it. The kernel therefore caps real-time scheduling globally:
# cat /proc/sys/kernel/sched_rt_runtime_us /proc/sys/kernel/sched_rt_period_us
950000
1000000
Read together: within every 1000000 µs (one second), all RT tasks together
may run for at most 950000 µs. An RT task that exhausts its 95% is
throttled - it cannot run again until the next period - so at least 5% of
every second remains for the fair class and for kernel threads: the
scheduler that must run to kill a runaway, the writeback threads, the
watchdogs. This is the bounded recovery: even a misbehaving FIFO loop leaves
the administrator five percent of each second to act, and a SIGKILL
delivered during it takes effect the next time the task is scheduled.
Writing -1 into sched_rt_runtime_us disables the safety margin; do not do
that outside dedicated, tested RT systems. As with other kernel
parameters, a permanent change belongs in a file under
/etc/sysctl.d (Chapter 7).
Who may schedule RT at all is separate from the cap. Unprivileged requests
fail, as Section 9.3.4 demonstrated with chrt -f 20's
Operation not permitted. Root bypasses it via CAP_SYS_NICE; a normal
user can be granted a bounded amount instead, through the
RLIMIT_RTPRIO limit - visible in the ulimit -a output of
Section 9.6.1 as real-time priority (-r) 0, meaning john currently may
not raise RT priority at all - and capped in duration by RLIMIT_RTTIME.
On a shared server, prefer those bounded grants to blanket RT privilege.
Starvation is the failure mode all of this guards against, and it has
degrees. A FIFO task at priority 50 starves every RT task below 50 and
every fair task while it spins; the bandwidth reserve converts that into
5%-duty-cycle starvation, which is survivable. A system dedicated to audio
or industrial control goes further: it dedicates CPUs via cpuset, keeps the
RT workload out of the general scheduler's way, and uses SCHED_DEADLINE
where the work is periodic, because deadline tasks carry their guarantee in
their parameters and the kernel enforces admission. For an administrator
meeting RT for the first time, the guidance is short: measure before
granting, use the smallest priority that meets the deadline, and keep the
bandwidth reserve enabled.
9.3.8. Comparing Competing Workloads and Verifying Temporary and Persistent Settings
The claims of the last five subsections can be watched happening. This subsection runs two controlled comparisons - nice against nice, quota against quota - and finishes with the verification checklist that tells you where each setting lives and how to check it.
The first experiment needs a CPU-bound counter that stops on TERM and
reports its work. Save this as cpu_counter.py in the workspace
(chmod +x cpu_counter.py):
#!/usr/bin/env python3
"""Count CPU-bound iterations until SIGTERM/SIGINT, then report progress."""
import signal
import sys
import time
stop = False
def request_stop(_signum, _frame):
global stop
stop = True
signal.signal(signal.SIGTERM, request_stop)
signal.signal(signal.SIGINT, request_stop)
iterations = 0
started = time.monotonic()
while not stop:
iterations += 1
elapsed = time.monotonic() - started
usage = time.process_time()
print(f"iterations={iterations} wall={elapsed:.2f}s cpu={usage:.2f}s")
The loop increments until a signal flips stop, then prints its iteration
count, wall-clock time, and CPU time. Run two of them on the same CPU -
pinned with taskset - one at nice 0, one at nice 19, for five seconds:
$ taskset -c 0 nice -n 0 python3 cpu_counter.py > nice-0.out &
$ p0=$!
$ taskset -c 0 nice -n 19 python3 cpu_counter.py > nice-19.out &
$ p19=$!
$ sleep 5
$ kill -TERM $p0 $p19
$ wait
$ cat nice-0.out nice-19.out
iterations=78214937 wall=4.97s cpu=4.92s
iterations=865490 wall=3.79s cpu=0.08s
Line by line: two counters start in the background, both pinned to CPU 0 so
they compete for exactly one CPU; their PIDs go into p0 and p19; five
seconds pass; both get TERM (the script's own signal handler, from
Section 9.2.1's pattern); wait collects them; cat shows both reports.
The nice-0 counter used 4.92 s of CPU in its 4.97 s of life; the nice-19
counter, launched and stopped at the same moments, got 0.08 s - about 1.6% as
much, matching the 1024-to-15 weight ratio from Section 9.3.2. Its shorter
wall time is the same starvation once more: the script starts its clock only
after the Python interpreter has booted, and a boot that needs a few tens of
milliseconds of CPU took over a second of wall time to obtain it. Figure 9.3
charts the two runs.
Figure 9.3. Observed on the chapter's 2-vCPU virtual guest: CPU seconds of two pinned counters (left) and stress-ng bogo-ops under two quotas (right). The ratios are the lesson, not the absolute numbers.
The second comparison measures quotas instead of weights. stress-ng --cpu 2
starts two CPU-burning workers; --metrics-brief prints a one-line summary
of completed work. Run it with a quota of both CPUs first - in the root
shell:
# systemd-run --wait --pipe --unit=handbook-cpu-full --slice=handbook.slice -p CPUQuota=200% stress-ng --cpu 2 --timeout 4 --metrics-brief --no-rand-seed
Running as unit: handbook-cpu-full.service; invocation ID: 4853950d408f4470a459402a7943aa8e
stress-ng: info: [9447] setting to a 4 secs run per stressor
stress-ng: info: [9447] dispatching hogs: 2 cpu
stress-ng: info: [9447] note: /proc/sys/kernel/sched_autogroup_enabled is 1 and this can impact scheduling throughput for processes not attached to a tty. Setting this to 0 may improve performance metrics
stress-ng: metrc: [9447] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s
stress-ng: metrc: [9447] (secs) (secs) (secs) (real time) (usr+sys time)
stress-ng: metrc: [9447] cpu 11647 4.00 8.00 0.00 2910.39 1456.47
stress-ng: info: [9447] skipped: 0
stress-ng: info: [9447] passed: 2: cpu (2)
stress-ng: info: [9447] failed: 0
stress-ng: info: [9447] metrics untrustworthy: 0
stress-ng: info: [9447] successful run completed in 4.01 secs
Finished with result: success
Main processes terminated with: code=exited, status=0/SUCCESS
Service runtime: 4.058s
CPU time consumed: 8.028s
Memory peak: 24M (swap: 0B)
--wait makes systemd-run block until the unit ends, and --pipe
connects its output to this terminal. The stressor line is the measurement:
11647 bogo-ops ("bogus operations", stress-ng's unit of make-work) in a 4
second run with 8.00 s of user CPU - both workers ran flat out, and the
manager's own summary agrees (CPU time consumed: 8.028s). The
sched_autogroup_enabled note is stress-ng reminding you that the kernel
groups each session's tasks for fair scheduling; it is noise for this quota
comparison because the quota caps the whole cgroup either way. Now the same
run under half a CPU:
# systemd-run --wait --pipe --unit=handbook-cpu-quota --slice=handbook.slice -p CPUQuota=50% stress-ng --cpu 2 --timeout 4 --metrics-brief --no-rand-seed
Running as unit: handbook-cpu-quota.service; invocation ID: 227cd98f3edf48be854f10e5240ca27a
stress-ng: info: [9473] setting to a 4 secs run per stressor
stress-ng: info: [9473] dispatching hogs: 2 cpu
stress-ng: info: [9473] note: /proc/sys/kernel/sched_autogroup_enabled is 1 and this can impact scheduling throughput for processes not attached to a tty. Setting this to 0 may improve performance metrics
stress-ng: metrc: [9473] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s
stress-ng: metrc: [9473] (secs) (secs) (secs) (real time) (usr+sys time)
stress-ng: metrc: [9473] cpu 2713 4.04 2.02 0.00 670.82 1338.30
stress-ng: info: [9473] skipped: 0
stress-ng: info: [9473] passed: 2: cpu (2)
stress-ng: info: [9473] failed: 0
stress-ng: info: [9473] metrics untrustworthy: 0
stress-ng: info: [9473] successful run completed in 4.05 secs
Finished with result: success
Main processes terminated with: code=exited, status=0/SUCCESS
Service runtime: 4.112s
CPU time consumed: 2.070s
Memory peak: 24.9M (swap: 0B)
Same wall time, quarter of the CPU: 2.02 s of user time, 2713 bogo-ops,
CPU time consumed: 2.070s - the quota did not slow the clock, it slowed
the work. Collected:
| Run | bogo ops | user CPU | CPU consumed |
|---|---|---|---|
CPUQuota=200% |
11647 | 8.00 s | 8.028 s |
CPUQuota=50% |
2713 | 2.02 s | 2.070 s |
These are observations on one small virtual machine, not benchmarks; the point is the method - pin or cap the contenders, run both sides for the same wall time, and compare the work done.
Finally, the settings themselves. Every CPU control in this section lives somewhere specific, and each has one inspection command:
| Setting | Lifetime | Verify with |
|---|---|---|
nice / renice |
The process, until it exits. | ps -o pid,ni -p PID |
chrt policy |
The process, until it exits. | chrt -p PID |
taskset mask |
The process, until it exits. | taskset -pc PID |
systemd-run -p |
The transient unit, until it stops. | systemctl show UNIT -p ... |
set-property --runtime |
Until reboot or systemctl revert. |
systemctl show UNIT -p Effective... |
Slice drop-in under /etc |
Across reboots, until removed. | systemctl show SLICE -p ..., EffectiveCPUs= |
The pattern generalizes to the memory, task, and I/O limits of the rest of
the chapter: a temporary change proves a diagnosis, then the persistent
form - a drop-in or a unit file in /etc - is what survives the reboot.
Chapter 28 builds on exactly this
distinction when it instruments production systems.