Multilevel Queue (MLQ) CPU Scheduling
It may happen that processes in the ready queue can be divided into different classes where each class has its own scheduling needs. For example, a common division is a foreground (interactive) process and a background (batch) process. These two classes have different scheduling needs. For this kind of situation, Multilevel Queue Scheduling is used.
Now, let us see how it works.
Features of Multilevel Queue (MLQ) CPU Scheduling:
- Multiple queues: In MLQ scheduling, processes are divided into multiple queues based on their priority, with each queue having a different priority level. Higher-priority processes are placed in queues with higher priority levels, while lower-priority processes are placed in queues with lower priority levels.
- Priorities assigned: Priorities are assigned to processes based on their type, characteristics, and importance. For example, interactive processes like user input/output may have a higher priority than batch processes like file backups.
- Preemption: Preemption is allowed in MLQ scheduling, which means a higher priority process can preempt a lower priority process, and the CPU is allocated to the higher priority process. This helps ensure that high-priority processes are executed in a timely manner.
- Scheduling algorithm: Different scheduling algorithms can be used for each queue, depending on the requirements of the processes in that queue. For example, Round Robin scheduling may be used for interactive processes, while First Come First Serve scheduling may be used for batch processes.
- Feedback mechanism: A feedback mechanism can be implemented to adjust the priority of a process based on its behavior over time. For example, if an interactive process has been waiting in a lower-priority queue for a long time, its priority may be increased to ensure it is executed in a timely manner.
- Efficient allocation of CPU time: MLQ scheduling ensures that processes with higher priority levels are executed in a timely manner, while still allowing lower priority processes to execute when the CPU is idle.
- Fairness: MLQ scheduling provides a fair allocation of CPU time to different types of processes, based on their priority and requirements.
- Customizable: MLQ scheduling can be customized to meet the specific requirements of different types of processes.
Advantages of Multilevel Queue CPU Scheduling:
- Low scheduling overhead: Since processes are permanently assigned to their respective queues, the overhead of scheduling is low, as the scheduler only needs to select the appropriate queue for execution.
- Efficient allocation of CPU time: The scheduling algorithm ensures that processes with higher priority levels are executed in a timely manner, while still allowing lower priority processes to execute when the CPU is idle. This ensures optimal utilization of CPU time.
- Fairness: The scheduling algorithm provides a fair allocation of CPU time to different types of processes, based on their priority and requirements.
- Customizable: The scheduling algorithm can be customized to meet the specific requirements of different types of processes. Different scheduling algorithms can be used for each queue, depending on the requirements of the processes in that queue.
- Prioritization: Priorities are assigned to processes based on their type, characteristics, and importance, which ensures that important processes are executed in a timely manner.
- Preemption: Preemption is allowed in Multilevel Queue Scheduling, which means that higher-priority processes can preempt lower-priority processes, and the CPU is allocated to the higher-priority process. This helps ensure that high-priority processes are executed in a timely manner.
Disadvantages of Multilevel Queue CPU Scheduling:
- Some processes may starve for CPU if some higher priority queues are never becoming empty.
- It is inflexible in nature.
- There may be added complexity in implementing and maintaining multiple queues and scheduling algorithms.
Ready Queue is divided into separate queues for each class of processes. For example, let us take three different types of processes System processes, Interactive processes, and Batch Processes. All three processes have their own queue. Now, look at the below figure.
The Description of the processes in the above diagram is as follows:
- System Processes: The CPU itself has its own process to run which is generally termed a System Process.
- Interactive Processes: An Interactive Process is a type of process in which there should be the same type of interaction.
- Batch Processes: Batch processing is generally a technique in the Operating system that collects the programs and data together in the form of a batch before the processing starts.
All three different type of processes have their own queue. Each queue has its own Scheduling algorithm. For example, queue 1 and queue 2 use Round Robin while queue 3 can use FCFS to schedule their processes.
Scheduling among the queues: What will happen if all the queues have some processes? Which process should get the CPU? To determine this Scheduling among the queues is necessary. There are two ways to do so –
- Fixed priority preemptive scheduling method – Each queue has absolute priority over the lower priority queue. Let us consider the following priority order queue 1 > queue 2 > queue 3. According to this algorithm, no process in the batch queue(queue 3) can run unless queues 1 and 2 are empty. If any batch process (queue 3) is running and any system (queue 1) or Interactive process(queue 2) entered the ready queue the batch process is preempted.
- Time slicing – In this method, each queue gets a certain portion of CPU time and can use it to schedule its own processes. For instance, queue 1 takes 50 percent of CPU time queue 2 takes 30 percent and queue 3 gets 20 percent of CPU time.
Consider the below table of four processes under Multilevel queue scheduling. Queue number denotes the queue of the process.
Priority of queue 1 is greater than queue 2. queue 1 uses Round Robin (Time Quantum = 2) and queue 2 uses FCFS.
Below is the Gantt chart of the problem:
- At starting, both queues have process so process in queue 1 (P1, P2) runs first (because of higher priority) in the round-robin fashion and completes after 7 units
- Then process in queue 2 (P3) starts running (as there is no process in queue 1) but while it is running P4 comes in queue 1 and interrupts P3 and start running for 5 seconds and
- After its completion P3 takes the CPU and completes its execution.
This article is contributed by Ashish Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Login to comment...