Linux Resource Management: Difference between revisions
(10 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
===CFS Scheduler=== | ===CFS Scheduler=== | ||
The CFS (Completely Fair Scheduler) aims at dividing the CPU time fairly among the processes. The processor time is divided in quantas, and for each quanta, the scheduler attempts to distribute the processor time fairly across the processes in the ready queue. | |||
The implementation monitors the virtual runtime for each process (<tt>vruntime</tt>). At every scheduling point, if the process has run for t milliseconds, <tt>vruntime</tt> is incremented with t multiplied with the weight of the process, henceforth vruntime monotonically increases for a process. When a context change occurs (timer interrupt), always choose the task with lowest <tt>vruntime</tt>. | |||
In order to pick the process with the lowest vruntime, the scheduler maintains a [[Red-black Tree|red-black tree]]. | |||
Relative priority amongst processes is enforced by the fact that the <tt>vruntime</tt> is updated proportionally with the process weight, which is inverse proportional with the priority of the process: for a lower priority process, <tt>vruntime</tt> increases ''faster'', so the process returns to ready queue more often. | |||
I/O bound processes naturally get a higher priority, because they consume relatively little time before it is preempted for I/O. | |||
====CFS and cgroups==== | |||
cgroups can be used to configure CFS scheduler parameters, so it controls how much CPU is allocated to the tasks under cgroups control. For more details, see the [[Linux_cgroups#cpu|cpu]] cgroup controller, specifically the [[Linux_cgroups#Controlling_Relative_Share_of_CPU|cpu.shares]] configuration element. | |||
===RT Scheduler=== | ===RT Scheduler=== |
Latest revision as of 20:34, 8 February 2018
Internal
CPU
Schedulers
CFS Scheduler
The CFS (Completely Fair Scheduler) aims at dividing the CPU time fairly among the processes. The processor time is divided in quantas, and for each quanta, the scheduler attempts to distribute the processor time fairly across the processes in the ready queue.
The implementation monitors the virtual runtime for each process (vruntime). At every scheduling point, if the process has run for t milliseconds, vruntime is incremented with t multiplied with the weight of the process, henceforth vruntime monotonically increases for a process. When a context change occurs (timer interrupt), always choose the task with lowest vruntime.
In order to pick the process with the lowest vruntime, the scheduler maintains a red-black tree.
Relative priority amongst processes is enforced by the fact that the vruntime is updated proportionally with the process weight, which is inverse proportional with the priority of the process: for a lower priority process, vruntime increases faster, so the process returns to ready queue more often.
I/O bound processes naturally get a higher priority, because they consume relatively little time before it is preempted for I/O.
CFS and cgroups
cgroups can be used to configure CFS scheduler parameters, so it controls how much CPU is allocated to the tasks under cgroups control. For more details, see the cpu cgroup controller, specifically the cpu.shares configuration element.