Linux – Which process scheduling algorithm is used by Linux

linuxprocessscheduling

The Linux operating system switches between running processes to enable multi-tasking.

What algorithm is used to determine when to suspend the execution of the currently running process and which process should run next?

Best Answer

In newer kernels, the Completely Fair Scheduler is used (it replaces the O(1) scheduler of older kernels).

The CFS stores the planned task in a red-black tree and uses the spent CPU time amount for the process has run as a key. This allows the scheduler to pick the process with the least amount of run-time (which is stored in the left-mode node of the tree) efficiently.

Once the task is about to be run, it is removed from the tree, and then when it runs, it is re-added with the new CPU time used.

Processes that are "sleeping" for a long time will automatically get a priority boost, since they don't have a large spent CPU time.

Therefore, it is "fair", since processes that are sleeping get as much CPU time as processes that are constantly running

Related Question