The process scheduling algorithms in Linux are categorized as follows:
First, first come service and short job ( process ) priority scheduling algorithm
1. First come first service scheduling algorithm (FCFS)
FCFS) scheduling algorithm is one of the simplest , non-preemptive scheduling algorithm, which can be used for job scheduling and process scheduling. The algorithm selects the process that can occupy the processor according to the order of the process into the ready queue Each schedule is to select one or more jobs from the fallback job queue that first enter the queue, transfer them into memory, assign them resources, create processes, Then put the ready queue. The fcfs algorithm, Each schedule is to select a process from the ready queue that first enters the queue, assigning the processor to it and putting it into operation. The process has been running until it has completed or an event has been blocked before discarding the processor.
the Advantage is to achieve simple , basic fairness. the disadvantage is that later processes wait longer for the CPU .
It is now mainly used as auxiliary scheduling method . For example, the priority scheduling algorithm is used, when there are two highest priority processes, then who comes first, who is first dispatched.
2. Short Job ( process ) priority scheduling algorithm
Short Job ( process ) priority (shortestprocess First,SPF) Scheduling algorithm refers to the algorithm of priority scheduling for short or short processes. They can be used for job scheduling and process scheduling, respectively. is to select a process from the ready queue that estimates the shortest running time, assign the processor to it, make it execute immediately and execute until it is complete, or the event is blocked and then re-dispatched.
Disadvantages:
⑴ must know the run time of the job
⑵ is very bad for long work, the turnaround time of long work will increase obviously.
⑶ the use of SPF algorithm, the human machine can not achieve interaction.
⑷ The scheduling algorithm completely does not consider the urgency of the operation, it can not ensure that the urgency of the operation can be timely treatment.
Second, high priority priority scheduling algorithm
1. Priority scheduling Algorithm (highestfirst first,HPF)
The highest priority priority (HPF) scheduling algorithm is introduced in order to take care of the urgent operation, so that it gets preferential treatment after entering the system . This algorithm is often used in batch processing system, as a job scheduling algorithm, also as a process scheduling algorithm in a variety of operating systems, can also be used in real-time systems. When the algorithm is used for job scheduling, the system will select several of the highest priority jobs from the fallback queue to load the memory. When used for process scheduling, the algorithm is to assign the processor to the ready queue of the highest priority process, at this time, the algorithm can be further divided into the following two kinds.
(1) Non-preemptive priority scheduling algorithm: The algorithm stipulates that once the processor is assigned to the highest priority process in the ready sequence, the process will continue to execute.
(2) preemptive priority scheduling algorithm: After the processor is assigned to the highest priority process in the ready sequence, the processor will handle a better priority process if there is a higher priority process in the middle.
2. High response ratio priority scheduling algorithm
In batch processing system, the short job first algorithm is a better algorithm, and its main disadvantage is that the operation of long operation is not guaranteed. If we can introduce the dynamic priority described above for each job, and the priority of the job increases with the wait time to increase at rate a , then the long job waits for a certain period of time, there must be a chance to assign to the processor. The change law of this priority can be described as:
Priority = (wait time + service time)/service time |
As the sum of waiting time and service time is the response time of the system to the job, the priority is equal to the response than the RP. Accordingly, it can also be expressed as:
Rp= (Waiting time + service time)/service time = response Time/service time |
It can be seen from the above formula:
(1) If the waiting time of the job is the same, the shorter the service time, the higher the priority, and therefore the algorithm is advantageous to the short job.
(2) when the time required for the service is the same, the priority of the job depends on its waiting time, the longer the waiting time, the higher the priority, so it realizes the first to serve first.
(3) for long jobs, the priority of the job can increase with the waiting time, and when its waiting time is long enough, its priority can be raised to high, thus also can obtain the processor. In short, the algorithm not only takes care of the short work, but also takes into account the order of the arrival of the operation, will not make long work long-term service. Therefore, the algorithm realizes a good tradeoff. Of course, when using this algorithm, the response ratio calculation must be done before each dispatch, which increases the system overhead.
Three, time-slice-based rotation scheduling algorithm
Time Slice Rotation method ( Round Robin)
In the early time-slice rotation, the system queues up all the ready processes on a first-come-first-served basis, allocating the CPU to the team's first process and making it perform a time slice each time it is scheduled. The size of the time slice is from several Ms to hundreds of Ms. When the elapsed time slice runs out, the clock interrupt request is made by a timer, which signals the scheduler to stop the execution of the process and sends it to the end of the ready queue, and then assigns the processor to the new team first process in the ready queue, while also allowing it to execute a time slice. This ensures that all processes in the ready queue can receive a time slice of processor execution times within a given time. In other words, the system can respond to requests from all users within a given time.
Four, multilevel feedback queue scheduling algorithm
The various algorithms used in the process scheduling have some limitations. such as the short process first scheduling algorithm, only take care of the short process and ignore the long process, and if the length of the process is not indicated, the short process first and process-based preemptive scheduling algorithm will not be used. The multi-level feedback queue scheduling algorithm does not need to know the execution time of various processes in advance, but also can satisfy the needs of various types of processes, so it is now recognized as a good process scheduling algorithm. In the system using multilevel feedback queue scheduling algorithm, the implementation process of scheduling algorithm is described below.
You should set up multiple ready queues, and assign different priorities to each queue. The first queue has the highest priority, the second queue is followed, and the priority of the remaining queues is lowered one by one. The algorithm gives each queue the size of the process execution time slices, and in the higher priority queue, the execution time slices for each process are smaller. For example, the time slice of the second queue is one time longer than the first queue, ..., section i+1 i The time slices of the queue are one times longer.
(2) when a new process enters memory, it is first placed at the end of the first 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 within that timeframe; if it is not completed at the end of a time slice, the scheduler moves the process to the end of the second queue, and then equally waits for the dispatch to execute by the FCFS principle. If it is still not completed after running a time slice in the second queue, place it in the third queue, ... and so on, when a long job ( process ) goes from first queue to nth Queue, the nth queue is run on a time-slice rotation basis.
(3)The Scheduler Dispatches processes in the second queue only when the first queue is idle;1~(i-1)when the queue is empty, the firstIthe process in the queue runs. If the processing machine isIwhen a process is serviced in a queue, a new process enters a queue with higher priority(Section1~(i-1)any one of the queues in), the new process will preempt the processor that is running the process, which is where the scheduler puts the running process back toIAt the end of the queue, the processor is assigned to the new high priority process.
This article is from the "Na-dimensional Snow" blog, please be sure to keep this source http://1536262434.blog.51cto.com/10731069/1788407
"Linux" Process scheduling algorithm