0% found this document useful (0 votes)
29 views

Linux Scheduler and Scheduling Techniques

This document discusses Linux kernel scheduling techniques. It begins by defining scheduling and explaining its importance for multitasking. It then outlines the main scheduling techniques used in Linux, including long-term, mid-term, and short-term scheduling. It discusses the schedulers used in early Linux versions and introduces the Completely Fair Scheduler implemented since Linux 2.6, which uses a red-black tree to maintain fairness. In closing, it provides a concrete view of the Linux kernel scheduler structure.

Uploaded by

nausicaatetoo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Linux Scheduler and Scheduling Techniques

This document discusses Linux kernel scheduling techniques. It begins by defining scheduling and explaining its importance for multitasking. It then outlines the main scheduling techniques used in Linux, including long-term, mid-term, and short-term scheduling. It discusses the schedulers used in early Linux versions and introduces the Completely Fair Scheduler implemented since Linux 2.6, which uses a red-black tree to maintain fairness. In closing, it provides a concrete view of the Linux kernel scheduler structure.

Uploaded by

nausicaatetoo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

M’hamed Bouguara _ Boumerdes

Institute of Electrical and Electronics Engineering


I.G.E.E (ex-INELEC)
Department of Computer Engineering

EE426

LINUX Kernel Scheduling Techniques

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 and Scheduler

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

 Linux .6.0 to Linux .6.


)n those versions, the kernel used an O scheduler, a kernel scheduling design that
can schedule processes within a constant amount of time, regardless of how many
processes are running on the operating system. O scheduler providing "constant
time" scheduling services has helped to minimize overhead and jitter of OS services.

 Since Linux .6.


Those Linux versions implemented a Completely Fair Scheduler as a replacement for
the earlier O scheduler.
The Completely Fair Scheduler CFS uses a scheduling algorithm called fair queuing.
Fair queuing had been previously applied to CPU scheduling under the name stride
scheduling.

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.

Completely fair scheduler

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

 Concrete view of Linux Kernel Scheduler L)NUX .

Linux scheduler contains:


 A Running Queue: A running queue rq is created for each processor CPU . Each
rq contains a list of runnable processes on a given processor.
30/03/2015|5

 Schedule Class: schedule class was introduced in . . . )t is an extensible


hierarchy of scheduler modules. These modules encapsulate scheduling policy
details and are called from the scheduler core without the core code assuming too
much about them. There are two schedule classes implemented in . . :

 Completely Fair Schedule class: schedules tasks following Completely Fair


Scheduler CFS algorithm. Tasks which have policy set to SC(ED_ NORMA L
SC(ED_OT(ER , SC(ED_BATC(, SC(ED_)DLE are scheduled by this schedule
class.
 RT schedule class: schedules tasks following real-time mechanism defined in
POS)X standard. Tasks which have policy set to SC(ED_F)FO, SC(ED_RR are
scheduled using this schedule class.

 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.

Real time scheduling scheduler

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.

Scheduling techniques algorithms

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.

d. No prioritization means that as long as processes are terminating, there is


no starvation, but in an environment where some processes might not
complete, then starvation can occur.
e. Based on queuing.

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.

3. Priority Scheduler: a non-preemptive algorithm where each process is assigned


a priority. Process with the highest priority gets the CPU and if two processes are
having the same priority then execution is FCFS based. )ts biggest drawback is
starvation of low priority processes, in order to go over this problem, dynamic
priorities might be used priority of an executed process is decreased after its
CPU burst . Another approach is to have the CPU keep track of low priority
processes and increase their priority once executed its priority go back to lower
one
 Dynamic priority is calculated from static priority and average sleep time.
When process wakes up, record how long it was sleeping, up to some maximum value
then when it is running, decrease that value each timer tick.
Roughly speaking, the bonus is a number in [0, 10] that measures what percentage of
the time the process was sleeping recently; 5 is neutral, 10 helps priority by 5, 0 hurts
priority by 5 DP = max (100, min(SP − bonus + 5, 139)).

4. Round Robin: a preemptive scheduling technique that is based of fair sharing of


CPU time time sharing . )n this technique fixed time quantum is allocated to all
the processes on the ready queue, so that the CPU cycle through them and no
process remains in the ready queue for long time starvation free .

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

This work is an overview on Linux scheduler’s techniques and policies.


At first we gave an independent overview of the scheduler in general. Then we discussed
the scheduling levels and the recently used scheduling policies. We also documented the
Kernel features for both . and . . . , . . version and compared between the old
version and the new version of the kernel.
Through this work most of the important aspects of Linux scheduler has been
covered. Kernel scheduler is one of the most frequently executed components in Linux
system. (ence, it has gained a lot of attentions from kernel developers who have thrived
to put the most optimized algorithms and codes into the scheduler. Different algorithms
used in kernel scheduler were discussed in the project. CFS scheduler achieves a good
performance and responsiveness while being relatively simple compared with the
previous algorithm like O . CFS exceeds performance expectation in some workloads.
But it still shows some weakness in other workloads.
Kernel scheduling is in constant improvement, developers always seeking for
better performance and simpler algorithms. Well for now this present work allowed us to
understand Linux scheduling logics and improvement through time.

You might also like