Having understood the scheduling domains and the policies, it is time to have a look at the way Linux implements CPU load balancing. Linux performs load balancing through SCHED _SOFTIRQ softirq. The sojtirq is installed in the sched_init function, as follows:

The SCHED _SOFTIRQ is raised by the scheduler _ tick function. The scheduler _tick function is invoked by the tick handler code with HZ frequency. The function raises SCHED _SOFTIRQ if the current value of jiffies \is greater than next_balance jiffies (set earlier) for the given CPU:

Thejunction runJebalance_domains is invoked when SCHED_SOFTIRQ is raised. For all domains, it checks if load rebalancing is required and invokes the load_balan,ce function to do the load balancing:

Name:  Linux load balancing implementation.jpg
Views: 804
Size:  18.7 KB

The load_balance function checks if a scheduling domain is highly imbalanced. It does this by calling the functionjind_busiestJ]roup andjind_busiest_queue. Later, the load_balance function invokes the move_tasks function to move processes from the source runqueue to the locaCrunqueue. This completes the Linux load balancing mechanism.

The Linux scheduler has gone through drastic changes with the advent of SMP, HTT, NUMA and multi-core architectures. To support new architectures and to be more flexible with such architectures, the scheduling domain concept was introduced.
The scheduling domains, their propertles and their relationships with other scheduling domains help the Linux scheduler in taking intelligent decisions to ensure maximum processor utilisation and still maintain fairness among processes.