Fundamentals 19 min read

Why Process Priority Matters: Understanding Nice, Priority, and Linux Schedulers

This article explains the concepts of nice and priority values in Linux, how they differ, their impact on process scheduling, and compares historic O(1) and modern CFS schedulers, including real‑time scheduling policies, providing practical command examples for administrators.

Efficient Ops
Efficient Ops
Efficient Ops
Why Process Priority Matters: Understanding Nice, Priority, and Linux Schedulers

Why Process Priority Exists

Since the advent of multitasking operating systems, controlling how much CPU time a process can consume has been essential because some processes are more important than others.

Process priority works the same way on single‑CPU and multi‑core systems: a higher‑priority process receives a longer slice of CPU time within each scheduling cycle.

Do not confuse the two concepts nice (NI) and priority (PR) ; they are related but not identical in modern Linux.

What Is a NICE Value?

A NICE value ranges from -20 to 19 (40 levels). The smaller the value, the higher the process’s priority. Lower NICE values mean the process is less "nice" and can pre‑empt the CPU more aggressively.

Example of setting a NICE value:

<code>[root@zorrozou-pc0 zorro]# nice -n 10 bash</code>

Viewing the current NICE value:

<code>[root@zorrozou-pc0 zorro]# nice
10</code>

Exiting the NICE‑10 shell and checking a normal shell shows a NICE value of 0.

<code>[root@zorrozou-pc0 zorro]# bash
[root@zorrozou-pc0 zorro]# nice
0</code>

The

renice

command can adjust the NICE value of a running process;

top

and

ps

also display it.

What Is Priority and Real‑Time Process?

In the kernel, the

PRI

(or

PR

) column shown by

ps

or

top

represents the dynamic priority value.

We will use nice value (NI) to denote static priority.

We will use priority value (PRI/PR) to denote dynamic priority.

From now on, the term "priority" refers to the dynamic priority.

The macro

MAX_PRIO

defines the total range of priority values (0‑139). It is composed of

NICE_WIDTH

(the range of nice values) and

MAX_RT_PRIO

(the range for real‑time processes).

Linux therefore supports 140 priority levels: 0‑99 for real‑time processes (higher priority) and 100‑139 for normal processes. A default nice value of 0 maps to priority 120.

What Is a Real‑Time Operating System?

Real‑time OSes guarantee that real‑time processes respond within a short, bounded time, with minimal interrupt and context‑switch latency.

Linux provides five scheduling policies; only

SCHED_FIFO

and

SCHED_RR

are usable by real‑time processes, while

SCHED_OTHER

,

SCHED_BATCH

, and

SCHED_IDLE

are for normal processes.

Real‑time processes always run before any normal process, and they are assigned priorities in the 1‑99 range.

<code>[root@zorrozou-pc0 zorro]# chrt 10 bash
[root@zorrozou-pc0 zorro]# chrt -p $$
pid 14840's current scheduling policy: SCHED_RR
pid 14840's current scheduling priority: 10</code>

Changing the policy to FIFO:

<code>[root@zorrozou-pc0 zorro]# chrt -f 10 bash
[root@zorrozou-pc0 zorro]# chrt -p $$
pid 14843's current scheduling policy: SCHED_FIFO
pid 14843's current scheduling priority: 10</code>

Both FIFO and RR are real‑time policies; the one with the smaller numeric priority (higher priority) always runs first.

What Is the O(1) Scheduler?

The O(1) scheduler was introduced in Linux 2.6 and replaced by CFS after 2.6.23. It allocated time slices of different lengths based on priority: higher‑priority processes received larger slices.

It also distinguished between CPU‑bound and I/O‑bound processes, giving I/O‑bound processes higher effective priority to improve interactive responsiveness.

What Is the Completely Fair Scheduler (CFS)?

CFS, the default scheduler for normal processes, aims to give each runnable process an equal share of CPU time over a scheduling period (the

sched_latency_ns

interval).

Priority in CFS is expressed as the rate at which a process’s virtual runtime (

vruntime

) grows: higher‑priority processes increase their

vruntime

more slowly.

For adjacent nice values, the CPU time share differs by roughly 10 % (a ratio of about 1.25). The kernel stores a lookup table mapping the 40 nice levels to their corresponding weight factors.

How Does CFS Work on Multi‑CPU Systems?

CFS maintains a separate run‑queue for each CPU core, avoiding a global lock and improving scalability. Periodic load‑balancing moves tasks between queues to keep CPU utilization balanced.

Conclusion

The article provides a comprehensive overview of Linux process priority, covering static nice values, dynamic priority, real‑time scheduling, and the evolution from O(1) to CFS. Understanding these concepts helps administrators interpret

top

,

ps

, and related commands, and make informed performance‑tuning decisions.

real-timeLinuxprocess schedulingCFSprioritynice
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.