Stop being nice !

In Linux, nice guys (tasks) finish last.

Literally.

On systems supporting multiple runnable tasks, each task is assigned a priority. Higher priority runnable tasks get CPU before the lower priority ones and tasks with the same priority get CPU in a round robin way.

Linux uses separate priority ranges for normal and real time tasks.

For normal tasks a priority range (or nice value) of -20 to +19 is
used. For real time tasks a priority range of 0 to 99 is used.
A higher number indicates higher priority.

Internally, the Linux kernel uses a single range (0-139) that maps each of the above 2 ranges (as shown in picture below). In this range lower value
means higher priority.

Before looking at task priorities, I will briefly describe different scheduling
classes/policies supported in the Linux kernel. Because, tracking and managing
a task's priority is quite complicated since Linux kernel needs to accommodate different use cases.

Lower nice corresponds to higher priority.

This makes your task less "nice" to other tasks, meaning it gets more CPU time.

In short,

Respect yourself at times by knowing when to be not nice.

Originally shared on LinkedIn

Subscribe to Vishnu Santhosh – Engineer, Writer, Technologist, YouTuber

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe