Operating system scheduling algorithm

Source: Internet
Author: User

There are many scheduling algorithms in the operating system, some of which are suitable for job scheduling, some scheduling algorithms are suitable for process scheduling, and some scheduling algorithms are applicable. Here are a few common scheduling algorithms.

First come first service (FCFS) scheduling algorithm

FCFS scheduling algorithm is one of the simplest scheduling algorithms, which can be used for job scheduling and process scheduling. In job scheduling, each time the algorithm selects one or more jobs from the fallback job queue that first enters the queue, it puts them into memory, allocates the necessary resources, creates the processes, and puts them in the ready queue.

In the process scheduling, the FCFS scheduling algorithm selects the process that first enters the queue from the ready queue, assigns the processor to it, and puts it into operation until it is complete or blocked for some reason to release the processor.

The performance of the FCFS scheduling algorithm is illustrated by an example below. Assume that there are 4 jobs in the system, their submission time is 8, 8.4, 8.8, 9, Running time is 2, 1, 0.5, 0.2, the system is used FCFS scheduling algorithm, the average waiting time of this group of jobs, average turnaround time and the average turnaround time with the right to see table 2-3.

3
Table 2-3 performance of FCFS scheduling algorithm
Job number submit time run time start time wait time finish time turnaround time Take ownership turnaround time
1 8 2 8 0 2 1
2 8.4 1 ten 1.6 one 2.6 2.6
8.8 0.5 one 2.2 11.5 2.7 5.4
4 9 0.2 11.5 2.5 11.7 2.7 13.5

Average wait time t = (0+1.6+2.2+2.5)/4=1.575
Average turnaround time T = (2+2.6+2.7+2.7)/4=2.5
Average weighted turnaround time W = (1+2.6+5.13.5)/4=5.625

FCFS scheduling algorithm belongs to the non-deprivation algorithm. On the surface, it is fair to all jobs, but if a long job arrives at the system first, it will cause many short jobs to wait for a long time, so it can not be used as the main scheduling strategy of time-sharing system and realtime system. However, it is often used in conjunction with other scheduling strategies. For example, in a system that uses precedence as a scheduling policy, multiple processes with the same priority are often treated as FCFS principles.

FCFS scheduling algorithm is characterized by simple algorithm, low efficiency, good for long-term operation, but unfavorable for short-term operation (relative SJF and high response ratio), which is advantageous to CPU busy job, and is not conducive to I/O busy job.

Short job first (SJF) scheduling algorithm

Short job (process) Priority scheduling algorithm refers to the algorithm of the short job (process) priority scheduling. The short job first (SJF) scheduling algorithm is to select one or several jobs with the shortest estimated run time from the fallback queue and transfer them into the memory run. The short-process-first (SPF) scheduling algorithm chooses a process that estimates the shortest running time from the ready queue, assigns the processor to it to execute immediately, and then releases the processor until it is blocked by the completion or occurrence of an event.

For example, consider a set of jobs given in table 2-3, if the system is to use a short job priority scheduling algorithm, its average waiting time, average turnaround time and average time of the right to turn around is shown in table 2-4.

Table 2-4 performance of SJF scheduling algorithm
Job Number Time of submission Run Time Start Time Wait Time Completion Time Turnaround Time turnaround time with weight
1 8 2 8 0 10 2 1
2 8,4 1 10.7 2.3 11.7 3.3 3.3
3 8.8 0.5 10.2 1.4 10.7 1.9 3.8
4 9 0.2 10 1 10.2 1.2 6

Average wait time t = (0+2.3+1.4+1)/4=1.175
Average turnaround time T = (2+3.3+1.9+1.2)/4=2.1
Average weighted turnaround time W = (1+3.3+3.8+6)/4=3.525

The SJF scheduling algorithm also has disadvantages that cannot be ignored:

    • The algorithm is unfavorable to the long operation, and the turnaround time of the long operation in SJF scheduling algorithm is increased by Table 2-3 and table 2-4. More seriously, if there is a long job going into the system's back-up queue, because the scheduler always prioritizes those (even backward) short jobs, it will cause long jobs to not be dispatched long-term ("hunger" phenomenon, attention to differentiate "deadlock". The latter is the system ring wait, the former is the scheduling policy problem).
    • The algorithm does not take into account the urgency of the operation, so it cannot guarantee that the urgency operation will be processed in time.
    • Since the length of the job is only based on the estimated execution time provided by the user, and the user may intentionally or unintentionally shorten the estimated running time of their job, the algorithm does not necessarily really do the short job priority scheduling.


Note that the average waiting time and the average turnaround time of the SJF scheduling algorithm are the least.

Priority scheduling algorithm

Priority scheduling algorithm is also called priority scheduling algorithm, which can be used for job scheduling and process scheduling, and the priority of the algorithm is used to describe the urgency of job operation.

In job scheduling, the priority scheduling algorithm selects one or more of the highest priority jobs from the fallback job queue each time, puts them into memory, allocates the necessary resources, creates processes, and puts them in the ready queue. In the process scheduling, the priority scheduling algorithm selects the highest priority process from the ready queue, assigns the processor to it and puts it into operation.

Depending on whether the new higher-priority process can preempt the process being executed, the scheduling algorithm can be divided into:

    • Non-deprivation priority scheduling algorithm. When a process is running on a processing machine, even if there is a more important or urgent process going into the ready queue, the running process continues to run until the processor is voluntarily given up for its own reasons (task completion or wait events), assigning the processor to a more important or urgent process.
    • Deprivation-based priority scheduling algorithm. When a process is running on a processing machine, if a more important or urgent process enters the ready queue, the running process is immediately suspended and the processor is assigned to a more important or urgent process.


Depending on whether the priority can be changed after the process has been created, you can divide the process priority into the following two types:

    • Static precedence. The priority is determined when the process is created and remains the same throughout the duration of the process. The main basis for determining the static priority is the process type, the resource requirements of the process, and the user requirements.
    • Dynamic priority. The priority is dynamically adjusted as the process changes as the process runs. The main basis for dynamically adjusting the priority is the length of CPU time that the process occupies, and how long the ready process waits for CPU time.
High response ratio priority scheduling algorithm

The high response ratio priority scheduling algorithm is mainly used for job scheduling, which is a comprehensive balance of FCFS scheduling algorithm and SJF scheduling algorithm, taking into account the waiting time and estimated running time of each job. In each job schedule, the response ratio of each job in the fallback job queue is calculated first, and the highest response is selected to run.

The change law of response ratio can be described as:


According to the formula:

    • When the waiting time of the job is the same, the shorter the service time is required, the higher the response ratio is, and the shorter job is advantageous.
    • When the service time is required, the response of the job is more than the waiting time, the longer the wait time, the higher the response ratio, so it realizes the first-come-first service.
    • For long jobs, the response ratio of the job can increase with the waiting time, and when the waiting time is long enough, the response ratio can be raised to a high level, and the processor can also be obtained. Overcome the hunger, taking into account the long work.
Time-Slice rotation scheduling algorithm

Time-slice rotation scheduling algorithm is mainly applicable to the timeshare system. In this algorithm, the system queues up all the ready processes in the order of arrival time, and the process scheduler always chooses the first process in the ready queue, i.e. the principle of first-come-first service, but only one time slice, such as 100ms, can be run. After a time slice is used, even if the process does not complete its operation, it must also release the (stripped) processor to the next ready process, and the stripped process returns to the end of the ready queue to be queued again, waiting to run again.

In the time-slice rotation scheduling algorithm, the size of the time slice has a great influence on the performance of the system. If the time slice is large enough that all processes can be executed in a single time slice, then the time-slice rotation scheduling algorithm degrades to the first-come-first service scheduling algorithm. If the time slice is small, then the processor will switch too frequently between processes, making the processor more expensive, and the actual time spent running the user process will be reduced. Therefore the size of the time slice should be chosen appropriately.

The length of time slices is usually determined by the response time of the system, the number of processes in the ready queue, and the processing power of the system.

Multilevel feedback Queue scheduling algorithm (the advantages of the previous algorithms are set)

The multilevel feedback queue scheduling algorithm is the synthesis and development of time-slice rotation scheduling algorithm and priority scheduling algorithm, which is shown in 2-5. By dynamically adjusting the process priority and time slice size, the multilevel feedback queue scheduling algorithm can take into account many system targets. For example, take care of short processes to improve system throughput and shorten average turnaround time, take care of I/O processes for better I/O device utilization and reduce response time, and do not have to estimate process execution time beforehand.


Figure 2-5 Multilevel feedback queue scheduling algorithm


The realization of multilevel feedback queue scheduling algorithm is as follows:

    1. You should set up multiple ready queues and give different priorities to each queue, the 1th-level queue has the highest priority, the 2nd-level queue is the second, and the remaining queues have a lower priority.
    2. The size of the process execution time slices in each queue is also different, and the higher the priority queue, the smaller the elapsed time slice for each process. For example, the time slice of the 2nd-level queue is one-fold longer than the time slice of the 1th-level queue ... The time slice of the i+1 queue is one-fold longer than the time slice of the class I queue.
    3. When a new process enters memory, it is first placed at the end of the 1th level queue and queued for dispatch by the FCFS principle. When it is time for the process to execute, it can prepare the evacuation system if it can be completed on the chip, and if it is not completed at the end of a time slice, the scheduler transfers the process to the end of the 2nd level queue, and then similarly waits for dispatch execution according to the FCFS principle, if it is not completed after running a time slice in the 2nd In the same way into the 3rd level queue ... In this way, when a long process is descending from the 1th level to the nth queue, it is run in the nth queue in a time-slice rotation.
    4. Only when the 1th-level queue is empty does the scheduler dispatch the processes in the 2nd-level queue, and the processes in the level I queue are dispatched only if the 1th-(i-1)-level queue is empty. If the processor is performing a process in the Class I queue, and a new process enters a queue with a higher priority (1th ~ (i-1) Any one of the queues), then the new process will preempt the processor that is running the process, that is, the scheduler puts the running process back to the end of the class I queue. Assign the processor to the new higher-priority process.


The advantages of multi-level feedback queues are:

      • Terminal type job User: Short job first.
      • Short batch job User: Turnaround time is short.
      • Long batch job users: Some of the previous queues have been partially executed and will not be processed for long periods of time.

Operating system scheduling algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.