Download presentation
Presentation is loading. Please wait.
1
1 Multilevel Feedback Queue Scheduling Another way to put a preference on short-lived processes –Penalize processes that have been running longer. Preemptive CPU Ready Queue 0 dispatched Timeout admitted CPU Ready Queue 1 dispatched CPU Ready Queue 2 dispatched Timeout (RR) Processes in RQ1 are scheduled only when no processes exist in RQ0. Processes in RQ2 are scheduled only when no processes exist in RQ1. Longer processes gradually drift downward. Timeout
2
2 05101520 P1 P2 P3 P4 P5 MFQ tq=1 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec Assume 3 ready queues
3
3 05101520 P1 P2 P3 P4 P5 MFQ tq=1 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec Assume 3 ready queues TNT 4-0 = 44/3=1… 20-2=1818/6=3 16-4=1212/4=3 19-6=1313/5=2… 11-8=33/2=1.5 Avg TAvg NT 10.002.29
4
4 05101520 P1 P2 P3 P4 P5 MFQ tq=1 TNT 4-0 = 44/3=1… 20-2=1818/6=3 16-4=1212/4=3 19-6=1313/5=2… 11-8=33/2=1.5 Avg TAvg NT 10.002.29 05101520 P1 P2 P3 P4 P5 RR tq=1 TNT 4-0 = 44/3=1… 18-2=1616/6=2… 17-4=1313/4=3… 20-6=1414/5=2… 15-8=77/2=3… Avg TAvg NT 10.82.71 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 17 context switches 18 context switches
5
5 Favors newer, shorter processes over older, longer processes. Leaves I/O-bound processes at higher queues An issue: possible starvation for long processes –If new short processes continuously enters the OS. Different time quantum (time slice) values in different ready queues. –2 i msec, where i indicates the ID of ready queue 1 msec for RQ0 2 msec for RQ1 4 msec for RQ2
6
6 05101520 P1 P2 P3 P4 P5 MFQ tq=2 i ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec Assume 3 ready queues
7
7 05101520 P1 P2 P3 P4 P5 MFQ tq=2 i ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec Assume 3 ready queues TNT 3-0 = 33/3=1 17-2=1515/6=2… 18-4=1414/4=3… 20-6=1414/5=2… 14-8=66/2=3 Avg TAvg NT 10.402.56
8
8 05101520 P1 P2 P3 P4 P5 MFQ tq=2 i TNT 4-0 = 44/3=1… 17-2=1515/6=2… 18-4=1414/4=3… 20-6=1414/5=2… 14-8=66/2=3 Avg TAvg NT 10.402.56 P1 P2 P3 P4 P5 MFQ tq=1 4-0 = 44/3=1… 20-2=1818/6=3 16-4=1212/4=3 19-6=1313/5=2… 11-8=33/2=1.5 Avg TAvg NT 10.002.29 P1 P2 P3 P4 P5 RR tq=1 4-0 = 44/3=1… 18-2=1616/6=2… 17-4=1313/4=3… 20-6=1414/5=2… 15-8=77/2=3… Avg TAvg NT 10.82.71 P1 P2 P3 P4 P5 RR tq=4 3-0 = 33/3=1 17-2=1515/6=2… 11-4=77/4=1… 20-6=1414/5=2… 19-8=1111/2=5.5 Avg TAvg NT 102.71 11 context switches 17 context switches 6 context switches 18 context switches
9
9 Variants of MFQ CPU Ready Queue 0 dispatched timeout admitted CPU Ready Queue 1 dispatched CPU Ready Queue 2 FCFS timeout Using FCFS at the lowest queue to avoid the starvation for long-lived processes –Rather than RR
10
10 Using aging promotion to avoid starvation for long- lived processes –Promote a process to a higher queue after it spends a certain amount of time waiting in the current RQ. CPU Ready Queue 0 dispatched Timeout admitted CPU Ready Queue 1 dispatched CPU Ready Queue 2 dispatched Timeout (RR) Timeout Promotion based on aging
11
11 Priority Scheduling Previous scheduling algorithms consider the concept of priority. –Short-lived or long-lived? –CPU-bound or I/O-bound? i.e., Priorities are determined with internal measurable characteristics of a process. External characteristics of a process –Time-sharing, batch (SVR3, 4.3BSD) –Real-time, system, time-sharing (SVR4, 4.4BSD) –Real-time, system, time-sharing, interactive (Solaris 9) –Real-time, system, time-sharing, interactive, batch
12
12 CPU Ready Queue 0 admitted dispatched exit interrupted I/O type 1 wait I/O 1 completed I/O 1 Blocked Queue I/O N Blocked Queue I/O type N wait I/O N completed Design choices: Preemptive or non-preemptive? Same or different time slices to different ready queue? Fixed or dynamic priorities? Potential issue: Lower-priority processes may suffer starvation. Workaround: promotion with aging Ready Queue 1 Ready Queue N
13
13 Traditional Unix Scheduling “Traditional” means –No consideration on realtime processes. –Typically 4.3BSD and SVR3 MFQ-based –Preemptive (time quantum based) –Round robin in the same priority queue –Same time quantum to different priority queues –Dynamic priority assignment Priority –Integer value between 0 and 127 Numerically lower values correspond to higher priorities. Priorities between 0 and 49 are reserved for the kernel Priorities between 50 and 127 are for user-level programs
14
14 PCB: the most important data structure in an OS –Process identification PID –CPU state information The contents of CPU registers Program counter –Indicates the address of the next instruction to be executed. –Process control information Event that a process is waiting on. I/O status (e.g., open files) Scheduling info Process Control Block User Program User Data/Stack Kernel Stack Process Image
15
15 PCB contains, as process scheduling info, –Current scheduling priority (pri) –User mode priority (usrpri) –Measure of recent CPU utilization (cpu) –Nice value (user-controllable adjustment factor; nice) Current scheduling priority (pri) –Used to decide which process to schedule. –Same as user mode priority (usrpri), when a process is in user mode. –Goes down to place higher priority to kernel mode processing upon I/O completion. Down to a predefined priority (0 =< sleep priority =< 49). –20 for disk I/O This enables a prompt I/O completion (a prompt completion of system call). –Replaced with the current user mode priority (usrpri) when it is back in use mode.
16
16 7-State Process Behavior Model Ready: The process is in main memory and available for execution. Blocked: The process is in main memory and blocked on an event. Blocked, suspended: The process is in virtual memory and blocked on an event. Ready, suspended: The process is in virtual memory but is available for execution as soon as it is loaded to main memory. Ready, Suspended ReadyRunningTerminated Blocked activated Dispatched to a CPU interrupted I/O or event wait Event completion exit Blocked, Suspended Suspended New admitted activated
17
17 User mode priority (usrpri) –Depends two factors: Recent CPU utilization (cpu) Nice value (nice) CPU utilization –Initialized to 0 when a process is created. –Incremented (for the currently-running process) at every clock interrupt. 10 msec Nice value –An integer value between 0 and 39 The default value is 20. –Increasing this value decreases the priority. Only OS administrators can decrease it. –The nice command is used to change the nice value for each process. Accepts -20 to 19 as an increment to the current value.
18
18 cpu j (i) –CPU utilization by process j through interval i. –Unit time for i: 10 msec. DR: decay rate –cpu j is reduced by a decay factor. –1/2 in SVR3. PUSER (baseline priority): 50 –used to divide processes into fixed bands of priority levels. Every second, user mode priority (usrpri) is updated as follows:
19
19 An Example DR: 1/2 PUSER: 50 nice: 0 3 processes in the same priority band Process 1 usrpri cpu Process 2 usrpri cpu Process 3 usrpri cpu Time 0 1 2 3 4 501 2 100 500 500 7550 501 2 100 500 6325 7550 501 2 100 7550 5713 14 112 6325 7856 6325 5713 14 112
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.