So far we have learned about the CPU scheduling, Objectives and Working of a Scheduler and Multi-Processor Scheduling and there are many things we haven't learned about scheduling which were overwhelming for me so for now I left them and the reason why I didn't wrote about the scheduling algorithms was because I already did wrote about them in the earlier posts in the Algorithms Series in Day 63 and Day 64. But now we will be looking at some examples of scheduling in Operating Systems mainly in Linux and Windows. Vur for today we will be only learnig about the Linux Scheduling.
Scheduling In Linux
In the earlier versions of the Linux Kernel, the scheduler was not designed with SMP (Symmetric Multi-Processing) systems in mind so it didn't worked properly with the systems with a large number of processors running at the same time. So programmers at Linux worked for some time and came up with the scheduling algorithm which later became the default Linux scheduling algorithm. It is called Completely Fair Scheduler or CFS for short.
Linux schedules processes in terms of scheduling classes and each class is assigned to a specific priority. To select which process to run next the scheduler will select the highest-priority task from the highest-priority class. Standard Linux kernel implements two scheduling classes.
- with CFS scheduling algorithm
- with real-time scheduling class
Other classes can also be added to it.
The CFS scheduling algorithm assigns the CPU for a proportion of processing time to all the tasks. This proportion of processing time is calculated based on the nice value that is between +19 to -20 where lower value indicates higher priority. The default nice value for each task is 0 and lower the nice value, higher the time it will get to be processed by the CPU. (The term nice comes from the idea that if a task increases its nice value from, say, 0 to +10, it is being nice to other tasks in the system by lowering its relative priority. In other words, nice processes finish last!).
Linux does not have a default value of time for which a task should run but a targeted latency, which is the interval of time a process should run at least once. Proportions of processing time are allocated from the value of targeted latency. Targeted latency can be increased if the number of active tasks increase from a certain threshold.
CFS assigns the priorities to the tasks by recording how long a task have been running up until now by maintaining the virtual run time of each task. it will select the task with the minimum virtual run time and higher priority to be assigned to the CPU for processing. For this it uses a variable vruntime. The virtual run time of each task is associated with the decay factor of each task. The decay factor of a task with lower priority will be higher than that of the task with high priority.
This is motly how Linux Process Scheduler works. I have missed many things in this but this much is enough for now. These topics are becoming more complex to grasp than imagened before so we will see what will hapeen next.