Summary of common scheduling algorithms

Source: Internet
Author: User

Summary of common scheduling algorithmsCategory: Operating system 2013-08-10 17:59 71 people read Comments (0) favorite reports

Directory (?) [+]

    1. First come first service queue
    2. Shortest priority Priority queue
    3. High priority priority scheduling algorithm
      1. Types of priority scheduling algorithms
      2. High response ratio priority scheduling algorithm
    4. Time-slice-based rotation scheduling algorithm
      1. Time Slice Rotation method
      2. Multilevel Feedback Queue scheduling algorithm
    5. Elevator scheduling algorithm
Scheduling algorithm refers to the resource allocation algorithm according to the system resource allocation strategy, such as task A after execution, select which task to execute, so that a factor (such as process total execution time, or disk seek time, etc.) minimum. For different system targets, different scheduling algorithms are usually used.
Several common operating system process scheduling algorithms.
1 first come first service (queue)First come first service (FCFS) scheduling algorithm is the simplest scheduling algorithm, which can be used for both job scheduling and process scheduling. When this algorithm is used in job scheduling, each schedule selects one or more jobs that first enter the queue from the fallback job queue, puts them into memory, assigns them resources, creates processes, and then puts them in the ready queue. When the FCFS algorithm is used in the process scheduling, each schedule is to select a process from the ready queue that is first entered into 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.
Disadvantage: The comparison is advantageous to the long work, but does not favor the short work. It is advantageous to the CPU busy job, but is not conducive to the I/O busy job.
2 Shortest priority (priority queue)The shortest priority 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. The scheduling algorithm for short job first (SJF) 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, causes it to execute immediately and executes until it is completed, or when an event is blocked to abort the processor and then re-dispatched.
Cons: Long-running operations are not guaranteed.
2 High priority priority scheduling algorithm2.1 Types of priority scheduling algorithms In order to take care of urgent operations, so that they get into the system after the preferential treatment, the introduction of the highest priority priority (FPF) scheduling algorithm. 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 algorithm
in this way, once the system has allocated the processor to the highest priority process in the ready queue, the process continues until it is completed, or the system can re-allocate the processor to another process with the highest priority due to an event that causes the process to abandon the processor. This scheduling algorithm is mainly used in batch processing systems, and can also be applied to some real-time systems where real-time requirements are not stringent.
2) Preemptive priority scheduling algorithm
In this way, the system also assigns the processor to the highest priority process and makes it execute. During its execution, however, as soon as another process with its higher priority arises, the process scheduler immediately stops the execution of the current process (the one that has the highest priority) and re-assigns the processor to the new highest priority process. Therefore, when this scheduling algorithm is used, the priority pi is compared with the priority PJ of the executing process J whenever a new ready process I is present in the system. If PI≤PJ, the original process PJ will continue to execute, but if it is PI>PJ, then immediately stop the execution of PJ, do a process switch, so that I process into execution. Obviously, this preemptive priority scheduling algorithm can better meet the requirements of urgent operation, so it is often used in the demanding real-time system, and in the batch processing and timeshare system with high performance requirements.
2.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:

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:

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.
3 Time-slice-based rotation scheduling algorithm3.1 Time slice rotation method 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.
3.2 Multilevel Feedback queue scheduling algorithm The various algorithms used as process scheduling in the previous section 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. The
(1) 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 times longer than the time slice of the first queue ..., the time slice of the i+1 queue is one times longer than the time slice of the I queue.
(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 on the chip, and 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 similarly waits for dispatch execution by the FCFS principle, if it is still not completed after running a time slice in the second queue Then put it in the third queue, ..., and so on, when a long job (process) from the first queue down to the nth queue, in the nth queue will be taken by the time slice rotation operation.
(3) The scheduler dispatches the processes in the second queue only when the first queue is idle, and the processes in queue I are scheduled to run only if the 1~ (i-1) queue is empty. If the processor is servicing a process in queue I, and a new process enters a higher priority queue (1~ (i-1)), 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 queue. Assign the processor to the new high priority process.
4 Elevator scheduling algorithm The elevator in high-rise buildings is constantly coming, and the computer that controls the elevator can easily track the order in which the customer presses the request. If the use of first-come-first service algorithm scheduling, and if the elevator load is heavy, then most of the time the elevator will stay in the central area of the elevator, and the elevator both sides of the area of the request will have to wait until the load of statistical fluctuations in the central region has no request location, so that the request from the central region is poor service Therefore, there is a conflict between the goal and fairness of obtaining the minimum response time.
Most elevators use elevator algorithms to coordinate two conflicting goals of efficiency and fairness. Elevator algorithm The elevator keeps moving in one direction until there is no requested position in that direction and then changes direction. The
Elevator algorithm (elevation algorithm) requires software to maintain a bits, which is the current direction bit: up (up) or downward (down). When a request processing is complete, the driver of the elevator checks the bit, and if it is up, the elevator moves to the next higher outstanding request. If there is no outstanding request in the higher position, the direction bit is reversed. When the direction bit is set to down, there is a low position request at the same time, move to that position.

Now we understand that the elevator up and down arrow buttons to tell the elevator you want to go up or down, rather than let the elevator up or down.

Example: Elevators on the upward, 5 floor has the call and the next call. The elevator will stop at the 5 floor, but it is for the call, so the lights will remain lit. It then starts up until all requests for the upstream are finished. Turn down to the five floor when it will stop. At this time is the service 5 downstairs called.

Elevator Handling Request Rules:
The elevator has a moving direction, the requests of each floor request direction, here maintains a request table (record request ID, request direction, the request of the dock floor). Because the elevator moves in the direction of movement until there is no request in that direction (the request includes the request ID and the request for the docking floor), it does not suddenly change the direction of the elevator movement according to the request direction. Therefore, the elevator in the process of moving only the "direction of the elevator move" the same "request direction" request. If the elevator moves down, only the downward request is processed, and the direction of the request is downward (no direction is requested on the dock floor).

Examples of specific algorithm procedures are as follows:










The disk wall scheduling algorithm in the operating system (the time required to read and write a disk block is the time to seek: To move the disk arm to the appropriate cylinder) and to use the elevator algorithm.

Summary of common scheduling algorithms

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.