Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 2: Process Management and Scheduling


❑ Not all processes on a system are equally important: Less urgent tasks should receive less atten-
tion, while important work should be done as quickly as possible. To determine the importance
of a particular task, it is equipped with a relative priority.
However, the task structure employs three elements to denote the priority of a process:prio
andnormal_prioindicate the dynamic priorities,static_priothe static priority of a process.
Thestatic priorityis the priority assigned to the process when it was started. It can be modified
with theniceandsched_setschedulersystem calls, but remains otherwise constant during the
process’ run time.
normal_prioritydenotes a priority that is computed based on the static priority and the
scheduling policy of the process. Identical static priorities will therefore result in different
normal priorities depending on whether a process is a regular or a real-time process. When a
process forks, the child process will inherit the normal priority.
However, the priority considered by the scheduler is kept inprio. A third element is required
because situations can arise in which the kernel needs to temporarily boost the priority of a pro-
cess. Since these changes are not permanent, thestatic and normal priorities are unaffected by
this. How the three priorities depend on each other is slightly subtle, and I discuss this in detail
below.
❑ rt_prioritydenotes the priority of a real-time process. Note that this does not replace the pre-
viously discussed values! The lowest real-time priority has value 0, whereas the highest priority
is 99. Higher values correspond to higher priorities. The convention used here is different from
the convention used for nice values.
❑ sched_classdenotes the scheduler class the process is in.
❑ The scheduler is not limited to schedule processes, but can also work with larger entities. This
allows for implementinggroup scheduling: This way, the available CPU time can first be dis-
tributed between general process groups (e.g., all processes can be grouped according to their
owner), and the assigned time is then again distributed within the group.
This generality requires that the scheduler does not directly operate on processes but works with
schedulable entities. An entity is represented by an instance ofsched_entity.
In the simplest case, scheduling is performed on a per-process level, and this is the case we con-
centrate on initially. Since the scheduler is designed to work on schedulable entities, each process
must look to it like such an entity.setherefore embeds an instance ofsched_entityon which
the scheduler operates in each task struct (notice thatseisnota pointer because the entity is
embedded in the task!).
❑ policyholds the scheduling policy applied to the process. Linux supports five possible values:

❑ SCHED_NORMALis used for normal processes on which our description focuses. They are
handled by the completely fair scheduler.SCHED_BATCHandSCHED_IDLEare also handled
by the completely fair scheduler but can be used for less important tasks.SCHED_BATCH
is for CPU-intensive batch processes that are not interactive. Tasks of this type are disfa-
vored in scheduling decisions: They will never preempt another process handled by the
CF scheduler and will therefore not disturb interactive tasks. The class is well suited for
situations in which the static priority of a task is not desired to be decreased withnice,but
when the task should nevertheless not influence the interactivity of a system.
SCHED_IDLEtasks will also be of low importance in the scheduling decisions, but this time
because their relative weight is always minimal (this will become clear when I discuss how
the kernel computes task weights that reflect their priority).
Free download pdf