System information
Tuning the Task Scheduler 169
As a result, CFS brings more optimized scheduling for both servers and desktops.
14.4.1 How CFS Works
CFS tries to guarantee a fair approach to each runnable task. To find the most bal-
anced way of task scheduling, it uses the concept of red-black tree. A red-black tree
is a type of self-balancing data search tree which provides inserting and remov-
ing entries in a reasonable way so that it remains well balanced. For more informa-
tion, see the wiki pages of Red-black tree [http://en.wikipedia.org/wi
ki/Red_black_tree].
When a task enters into the run queue (a planned time line of processes to be execut-
ed next), the scheduler records the current time. While the process waits for processor
time, its “wait” value gets incremented by an amount derived from the total number
of tasks currently in the run queue and the process priority. As soon as the processor
runs the task, its “wait” value gets decremented. If the value drops below a certain lev-
el, the task is preempted by the scheduler and other tasks get closer to the processor.
By this algorithm, CFS tries to reach the ideal state where the “wait” value is always
zero.
14.4.2 Grouping Processes
Since the Linux kernel version 2.6.24, CFS can be tuned to be fair to users or groups
rather than to tasks only. Runnable tasks are then grouped to form entities, and CFS
tries to be fair to these entities instead of individual runnable tasks. The scheduler also
tries to be fair to individual tasks within these entities.
Tasks can be grouped in two mutually exclusive ways:
• By user IDs
• By kernel control groups.
The way the kernel scheduler lets you group the runnable tasks depends on set-
ting the kernel compile-time options CONFIG_FAIR_USER_SCHED and
CONFIG_FAIR_CGROUP_SCHED. The default setting in SUSE® Linux Enterprise
Server 11 SP3 is to use control groups, which lets you create groups as needed. For
more information, see Chapter10, Kernel Control Groups (page121).