Load Balancing Program Load_balance
Invoke Condition:
As long as the current executable queue is empty, it is called.
Called by the timer: When the system is idle, it is called every 1 milliseconds or in other cases every 200mm.
Single processor is not called
Perform steps
1. First, Load_balance calls Find_busiest_queue () to find the busiest executable queue. This means that the queue has the highest number of processes. If no number of processes in the executable queue is more than 25% or more than the number of current queues, find_busiest_queue () returns NULL, and Load_balance () returns. Otherwise, the busiest executable queue is returned.
2. Second, load_balance () selects a priority group from the busiest run queue to extract the process. It is best to expire the array, because the processes there have not been running for a relatively long time, probably not in the processor cache (in other words, they are not cache hits (cache hot) If the expired array is empty, then only the active array is selected.
3. Next, Load_balance () looks for a linked list that contains processes with the highest priority (least value) because it is important to spread the high-priority processes on average.
4. Analysis finds all of these processes with the same priority, selecting a process that is not being executed, and not being moved because of the cancellation of processor affinity, and not in the cache. If a process satisfies these conditions, call Pull_task () to extract it from the busiest queue to the current queue.
5. As long as the executable queue is still unbalanced, repeat the previous two steps to continue extracting the process from the busy queue to the current queue. This will eventually eliminate the imbalance, at which point the lock on the current queue process is removed and returned from Load_balance ().
Linux Kernel Design Learning