Chapter 2: Process Management and Scheduling
class->
move_one_task
No migration
requests?
schedule
Get migration
request
Iterate over all
scheduler classes
1
1
migration_thread
rq->active_balance set?
active_load_balance
move_one_task
__migrate_task
Figure 2-27: Code flow diagram formigration_thread.
migration_threadruns an infinite loop and sleeps when there is nothing to do. First of all, the function
checks if active balancing is required, and if this is the case,active_load_balanceis called to satisfy this
request. The function tries to move one task from the current run queue to the run queue of the CPU that
initiated the request for active balancing. It usesmove_one_taskforthispurpose,which,inturn,ends
up calling the scheduler-class specificmove_one_taskfunctions of all scheduler classes until one of them
succeeds. Note that these functions try to move processes more aggressively thanload_balance.For
instance, they do not perform the previously mentioned priority comparison, so they are more likely to
succeed.
Once the active load balancing is finished, the migration thread checks if any migration requests from the
scheduler are pending in themigrate_reqlist. If none is available, the thread can reschedule. Otherwise,
the request is fulfilled with__migrate_task, which performs the desired process movement directly
without further interaction with the scheduler classes.
Core SchedulerChanges
Besides the additions discussed above, some changes to the existing methods are required in the core
scheduler on SMP systems. While numerous small details change all over the place, the most important
differences as compared to uniprocessor systems are the following:
❑ When a new process is started with theexecsystem call, a good opportunity for the sched-
uler to move the task across CPUs arises. Naturally, it has not been running yet, so there can-
not be any negative effects on the CPU cache by moving the task to another CPU.sched_exec
is the hook function invoked by theexecsystem call, and the code flow diagram is shown in
Figure 2-28.
sched_balance_selfpicks the CPU that is currently least loaded (and on which the process
is also allowed to run). If this is not the current CPU, thensched_migrate_taskforwards an
according migration request to the migration thread usingsched_migrate_task.
❑ The scheduling granularity of the completely fair scheduler scales with the number of CPUs.
The more processors present in the system, the larger the granularities that can be employed.
Bothsysctl_sched_min_granularityandsysctl_sched_latencyforsysctl_sched_min_