The Migration Thread

The migration thread serves two purposes: It must fulfill migration requests originating from the scheduler, and it is used to implement active balancing. This is handled in a kernel thread that executes migration_thread. The code flow diagram for the function is shown in Figure 2-27.

Linux Thread Construct Diagram
Figure 2-27: Code flow diagram for migration_thread.

migration_thread runs 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_balance is 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 uses move_one_task for this purpose, which, in turn, ends up calling the scheduler-class specific move_one_task functions of all scheduler classes until one of them succeeds. Note that these functions try to move processes more aggressively than load_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 the migrate_req list. 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.

Continue reading here: Core Scheduler Changes

Was this article helpful?

+4 0