Scheduling Algorithm and Resource Scheduling Algorithm
In a multi-channel program environment, there are multiple processes in the main memory, and the number of processes is usually more than the number of processors. This requires the system to dynamically allocate the processor to a process in the ready queue according to an algorithm for execution. The task of allocating the processor is completed by the processor scheduler.
Processor Scheduling
In a multi-channel Program System, a job can be executed only after being submitted and scheduled by the processor. For Batch jobs, a processor can be obtained through two processes: Job Scheduling (also known as Advanced scheduling) and process scheduling (also known as low-level scheduling). For Terminal jobs, generally, the processor can be obtained only after process scheduling. In addition to the preceding two types of scheduling, an intermediate scheduling is usually set in the operating system to improve memory utilization.
Next we will talk about these scheduling types respectively. The first is Advanced scheduling. Its main function is to transfer jobs stored in the backup queue to the memory based on an algorithm. That is to say, the scheduling object is a job. So what is job?
A job is a more extensive concept than a program. It not only contains the common program and data, but also has a job Manual. The system controls the running of the program according to the manual. The algorithm mentioned above is several common scheduling algorithms we will mention later.
Low-level scheduling is used to determine which process in the ready queue should obtain the processor, and then the dispatcher executes the specific operation to assign the processor to the process.
The main purpose of intermediate scheduling is to improve memory utilization and system throughput. Its working principle is to temporarily unable to run the process to the external storage, the status is called suspended. On the contrary, when the memory is idle, they are re-transferred back to the memory. The status is called ready and hung on the ready queue to wait for the process to schedule.
Three scheduling relationships are as follows:
So how do we evaluate different scheduling algorithms? To compare the performance of various algorithms, many evaluation criteria are proposed:
1. cpu utilization: the cpu is the most important and expensive resource in the computer system, so we should keep the cpu working as much as possible;
2. system throughput: the number of jobs completed by the cpu per unit time. A long job consumes a long processor time, which will reduce the system throughput;
3. turnaround time: the total time taken from job submission to job completion, including job waiting, queuing in the ready queue, running on the processing machine, and input/output operations.
Turnaround time = job completion time-job submission time
Average turnover time = (turnover time of Job 1 + turnover time of job 2 +... + Turnover time of job n)/n
Weighted turnaround time = turnaround time/actual job running time
Average Weighted turnaround time = (weighted turnaround time of Job 1 +... + Weighted turnaround time of job n)/n
4. Waiting Time: The sum of the waiting time of processes in the same processor state. The longer the waiting time, the lower the user satisfaction. The Processor Scheduling Algorithm does not affect the execution time or input/output time of a job. It only affects the waiting time of a job in the ready queue. Therefore, to measure the merits of a scheduling algorithm, you only need to simply examine the wait time.
5. Response Time: refers to the time from when the user submits a request to when the system generates a response for the first time. In an interactive system, the turnaround time cannot be the best evaluation criterion. Generally, the scheduler uses the response time as one of the important criteria for measuring the scheduling algorithm. From the user's perspective, the scheduling policy should minimize the response time so that the response time is within the user's acceptable range.
Below we will officially introduce several common scheduling algorithms in the operating system:
Service scheduling algorithm first
The FCFS scheduling algorithm is the simplest scheduling algorithm. It can be used for Job Scheduling or process scheduling.
In job scheduling, the algorithm selects one or more jobs that first enter the queue from the backup Job Queue each time, transfers them to the memory, allocates necessary resources, creates processes, and puts them in the ready queue.
In process scheduling, the FCFS scheduling algorithm selects the process that first enters the queue from the ready queue each time and assigns the processor to it for running, the processor is released until it is completed or blocked for some reason.
The following example shows the performance of the FCFS scheduling algorithm. Assume that the system has four jobs whose submission time is 8, 8.4, 8.8, and 9, and the running time is 2, 1, 0.5, and 0.2 in sequence. The FCFS scheduling algorithm is used in the system worker.
Analysis shows that:
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.4 + 13.5)/4 = 5.625
On the surface, it is fair to all jobs, but if a long job arrives at the system first, it will make many of the subsequent short jobs wait for a long time, therefore, it cannot be used as the main scheduling policy for time-sharing and real-time systems. However, it is often used in combination with other scheduling policies. For example, in a system where priority is used as a scheduling policy, multiple processes with the same priority are usually processed according to the FCFS principle.
The FCFS scheduling algorithm is simple but inefficient. It is advantageous for long jobs but not for short jobs (compared with SJF and high response ratio, this is not conducive to busy I/O jobs.
Short job (process) Priority Scheduling Algorithm
The short job (process) Priority Scheduling Algorithm refers to the short job (process) priority scheduling algorithm. The short job priority (SJF) scheduling algorithm selects one or more jobs in the backup queue with the minimum estimated running time and transfers them to the memory for running. The short process priority (SPF) scheduling algorithm selects a process from the ready queue to estimate the minimum running time and assigns the processor to it for immediate execution, the processor is released until it is completed or blocked by an event.
In the above example, we will get different results by using the short job method:
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
It seems that the short job priority scheduling algorithm is quite good, but there are also shortcomings that cannot be ignored:
This algorithm is not good for long jobs. The turnover time of long jobs increases in the SJF scheduling algorithm. More seriously, if a long job enters the system's backup queue, because the scheduler always gives priority to the short jobs (even those that come in later, long jobs will not be scheduled for a long time ("Hunger" phenomenon, pay attention to distinguish "deadlock ". The latter is a system loop wait, and the former is a scheduling policy problem ).
This algorithm does not take into account the degree of urgency of the job, so it cannot guarantee that the urgency job will be processed in a timely manner.
Because the length of a job depends on the estimated execution time provided by the user, the user may intentionally or unintentionally shorten the estimated running time of the job, as a result, this algorithm may not be able to really implement priority scheduling for short jobs.
Note: The average waiting time and average turnaround time of the SJF scheduling algorithm are the least.
Priority Scheduling Algorithm
In job scheduling, the priority scheduling algorithm selects one or more jobs with the highest priority from the backup Job Queue each time, transfers them to the memory, and allocates necessary resources, create a process and put it in the ready queue. In process scheduling, the priority scheduling algorithm selects the process with the highest priority from the ready queue each time and assigns the processor to it for running.
The scheduling algorithm can be divided:
Non-deprivation priority scheduling algorithm. When a process is running on the processor, even if a more important or urgent process enters the ready queue, the running process continues to run, the processor is assigned to a more important or urgent process only when the processor is actively transferred out for its own reasons (task completion or waiting for an event.
The denied priority scheduling algorithm. When a process is running on the processor, if a more important or urgent process enters the ready queue, it immediately suspends the running process and assigns the processor to a more important or urgent process.
Based on whether the priority of a process can be changed after it is created, the process priority can be divided into the following two types:
Static Priority. The priority is determined during Process Creation and remains unchanged throughout the process. Determining static priorities is mainly based on the process type, resource requirements of processes, and user requirements.
Dynamic Priority. During the process, the priority is dynamically adjusted based on the changes in the process. The main reason for dynamic priority adjustment is the length of CPU time occupied by the process and the length of CPU time waiting for the ready process.
Rotation Scheduling Algorithm Based on time slice
The time slice rotation scheduling algorithm is mainly applicable to time-sharing systems. In this algorithm, the system queues all ready processes in the order of arrival time. The process scheduler always selects the first process in the ready queue for execution, that is, the principle of service first, however, only one time slice can be run, such as 100 ms. After using a time slice, even if the process has not completed its operation, it must release the (deprived) processor to the next ready process, the denied process returns to the end of the ready queue and queues again, waiting for another operation.
In the time slice rotation scheduling algorithm, the size of the time slice has a great impact on the system performance. If the time slice is large enough that all processes can be executed in one time slice, the rotation scheduling algorithm of the time slice degrades first to serve the scheduling algorithm. If the time slice is small, the processor will switch between processes too frequently, increasing the overhead of the processor, and reducing the time actually used to run user processes. Therefore, select the appropriate time slice size.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.