Linux Scheduler and Scheduling Techniques
Linux Scheduler and Scheduling Techniques
EE426
Homework N°1
Done by :
FALI Thamila
Supervisor:
Mister NAMANE
/ /
30/03/2015|1
Assignment Objective
The objective of this work is to study the scheduling techniques used by L)NUX
kernel. to do so, we are going to define what is scheduling and why is it so important, in
other hand we are going to state all the scheduling techniques used by Linux kernel
)ntroduction
Linux is a Unix-like computer operating system assembled under the model of free
and open-source software development and distribution. The Linux kernel, which handles
process control, networking, peripheral and file system access, has performant scheduling
techniques that keep track of processes, threads and organize the CPU time allocated to
each task. )n order to have an efficient scheduler, several techniques are used, those are to
be stated bellow.
Scheduling is the method by which threads, processes or data flows are given
access to system resources e.g. processor time, communications bandwidth . )n order
mainly to load balance and share system resources effectively or achieve a target quality
of service.
Multitasking and multiplexing transmit multiple data streams simultaneously
across a single physical channel in most modern systems, is what made scheduling
algorithm of such importance.
Scheduling is then done by the Scheduler, which is a module of the kernel a
component of the kernel . (ence mainly scheduler decides, in a given set of runnable
processes, what process to run next and for how long.
The main objectives of a scheduler then can be resumed as follow:
Scheduler decides when to take the process from ready to running and waiting
queues.
Scheduler has to divide resources between all processes fairly when needed.
)n real time operating systems scheduler has to meet the dead lines. Critical
processes need real time scheduling. Such as in embedded operating systems and
into super computer where automated tasks have to be done and real time
environment is needed.
Scheduler has to swap in and swap out the process from the main memory
Scheduler is concerned with throughput that total number of process completed
their execution per unit time.
)t has to manage the time given to each process.
Scheduler has to define the priorities for each task, in Linux priorities are from -
.
30/03/2015|2
Types of OS Scheduling
Scheduling occurs at different levels in the system, we can thus distinguish three
scheduling types: -long-term scheduler
-Mid-term scheduler
-Short-term scheduler
At each level a specific scheduling task is done, and as their names suggest, the frequency
at which these scheduling occurs vary.
Long-term scheduling: also known as admission scheduler, decides which jobs
to be admitted to the ready queue. )t dictates what processes are to run on the
system, and the degree of concurrency to be supported at any one time – whether
many or few processes are to be executed concurrently, and how the split between
)/O-bound and CPU-bound processes is to be handled. The long term scheduler is
responsible for controlling the degree of multiprogramming. )n addition, in
modern OS, it is used to make sure that real time processes get enough CPU time
to finish their task.
Mid-term scheduling: manage the swap in swap out between main and
secondary memory, since it can temporarily remove processes from the main
memory. Process that has not been active for a long time, with low priority, which
is page faulting trap raised by hardware when process is trying to access a
memory page whose virtual address space do not map any physical memory or a
process that is taking up large amount of memory.
)n many modern system that supports virtual address space mapping to
secondary storage, the midterm scheduler can perform the long term scheduler
role.
Short-term scheduling: CPU scheduler organizes the execution time, CPU
allocation between processes on the ready queue, which means decides which
process to be executing next. This scheduler can be preemptive, implying that it is
capable of forcibly removing processes from a CPU when it decides to allocate that
CPU to another process, or non-preemptive also known as "voluntary" or "co-
operative" , in which case the scheduler is unable to "force" processes off the CPU.
)n this last, processes are able to give voluntarily time to one another.
L)NUX schedulers
Linux .
)n Linux . , an O n scheduler with a multilevel feedback queue and priority levels
ranging from to is used. –99 are reserved for real-time tasks and – are
considered nice task levels.
For real-time tasks, the time quantum for switching processes was approximately
ms, and for nice tasks approximately ms. The scheduler ran through the run queue
of all ready processes, letting the highest priority processes go first and run through
their time slices, after which they will be placed in an expired queue. When the active
queue is empty the expired queue will become the active queue and vice versa.
30/03/2015|3
The fair queuing CFS scheduler has a scheduling complexity of O log N , where N is the
number of tasks in the runqueue. Choosing a task can be done in constant time, but
reinserting a task after it has run requires O log N operations, because the run queue
is implemented as a red-black tree.
CFS is the first implementation of a fair queuing process scheduler widely used in a
general-purpose operating system.
The main idea behind the CFS is to maintain balance fairness in providing
processor time to tasks. This means processes should be given a fair amount of the
processor. When the time for tasks is out of balance meaning that one or more tasks are
not given a fair amount of time relative to others , then those out-of-balance tasks should
be given time to execute.
To determine the balance, the CFS maintains the amount of time provided to a given task
in what's called the virtual runtime. The smaller a task's virtual runtime—meaning the
smaller amount of time a task has been permitted access to the processor—the higher its
need for the processor. The CFS also includes the concept of sleeper fairness to ensure that
tasks that are not currently runnable for example, waiting for )/O receive a comparable
share of the processor when they eventually need it.
But rather than maintain the tasks in a run queue, as has been done in prior Linux
schedulers, the CFS maintains a time-ordered red-black tree see Figure below . A red-
black tree is a tree with a couple of interesting and useful properties. First, it's self-
balancing, which means that no path in the tree will ever be more than twice as long as
any other. Second, operations on the tree occur in O log n time where n is the number of
nodes in the tree . This means that you can insert or delete a task quickly and efficiently.
30/03/2015|4
Load balancer: )n SMP environment, each CPU has its own rq. These queues might
be unbalanced from time to time. A running queue with empty task pushes its
associated CPU to idle, which does not take full advantage of symmetric
multiprocessor systems. Load balancer is to address this issue. )t is called every
time the system requires scheduling tasks. )f running queues are unbalanced, load
balancer will try to pull idle tasks from busiest processors to idle processor.
A real-time system is one that provides guaranteed system response times for
events and transactions—that is, every operation is expected to be completed within a
certain rigid time period. A system is classified as hard real-time if missed deadlines
because system failure and soft real-time if the system can tolerate some missed time
constraints.
Linux has soft real-time scheduling, Processes with priorities [ , 99] are real-time
and all real-time processes are higher priority than any conventional processes.
There is two real-time scheduling systems, FCFS and round-robin: First-come,
first-served; process is only preempted for a higher-priority process; no time quanta.
Round-robin; real-time processes at a given level take turns running for their time
quantum.
The Linux scheduler tries to be very efficient, and uses different algorithm to
manage processes. The main purpose of scheduling algorithms are to minimize resource
starvation and ensure fairness amongst the parties using them. Among them we can
distinguish:
1. First Come First Served FCFS : a simple non preemptive real time scheduling
algorithm based on the arrival order to the ready queue.
a. Overhead is minimal context switch occurs only after process
completion
30/03/2015|6
b. Throughput can be low, waiting and running time can be low: long process
can hold the CPU.
c. No prioritization, thus this system has trouble meeting process deadlines.
2. Shortest Job First SJF : in this approach, the running process is selected
regarding its burst time. The smallest burst time process present in the ready
Queue takes on the CPU. This algorithm can be preemptive or non-preemptive in
preemptive the remaining time is calculated when a new process arrives, hence
shortest Remaining time first SRTF .
This algorithm is optimal since it gives the minimal average waiting time, but
present some drawback point, since it requires to know the length of the next
CPU burst of a process. Moreover it can cause starvation of long processes if
shorter ones keep entering the ready queue.
5. Multilevel Queue: this is used when processes can be divided into foreground
interactive processes and batch background processes. )n this scheduling
algorithm, there is 'n' number of queues, where 'n' is the number of groups the
processes are classified into. Each queue will be assigned a priority and will have
its own scheduling algorithm like Round-robin scheduling or FCFS. For the
process in a queue to execute, all the queues of priority higher than it should be
empty, meaning the processes in those high priority queues should have
completed their execution. )n this scheduling algorithm, once assigned to a queue,
the process will not move to any other queues. Foreground processes are given
high priority and background processes have low priority.
30/03/2015|7
Conclusion