Lecture 23: Process Scheduling for Interactive Systems
Review: Scheduling Algorithms for Batch Systems First come first serve Shortest job first Shortest remaining time next
Review: Scheduling Algorithm Goals All Systems Fairness – giving each process a fair share of the CPU Policy enforcement – seeing that stated policy is carried out Balance – keeping all parts of the system busy
Review: Scheduling Algorithm Goals Interactive Systems Response time – respond to requests quickly Proportionality – meet users’ expectations
Scheduling Algorithms for Interactive Systems Round-Robin scheduling Priority scheduling Multiple queues Lottery scheduling
Round Robin Give CPU time to each process by turn Quantum = CPU time allotted every turn how to choose the value of the quantum? Too small might mean high context switch overhead Too large might mean bad response times
Priority Scheduling Different Priorities: Background process sending mail vs: Shell process accepting input Requirement: Schedule jobs with highest priority first Issue: high priority jobs should not overwhelm the others Might decrease priority with time
Multiple Queues – static version System level processes High Interactive processes Background processes Low Lower priority queues don’t run if higher priority queues non-empty Could time slice between queues
Multiple Queues – dynamic version High Quantum = 1 Quantum = 2 Low Quantum = 4 Process enters high priority level If takes more than 1 quantum, moved to second highest priority, …..
Multiple Queues – dynamic version Higher priority = faster service, but short service times Reduce number of context switches for long processes
Lottery Scheduling Example: 3 processes, priorities 2, 3, 5 Distribute 20, 30, 50 tickets respectively System holds “lottery” 50 times a second Winner gets 20 ms of CPU time Gives probabilistic guarantees
RR, Q = 10 Arrival time CPU burst P1: 4 36 8 112 1 13 I/O burst 16 13 16 20 P1: 4 36 8 112 1 I/O burst P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart
RR, Q = 10 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Which process goes next, and when? Gantt chart P1 idle P2 P3 P4 0 4 13 23 27 29
RR, Q = 10 40 82 47 179 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart P1 idle P2 P3 P4 P2 0 4 13 23 27 29 42
RR, Q = 10 162 End Run 179 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart P1 idle P2 P3 P4 P2 P1 P3 P2 P3 0 4 13 23 27 29 42 50 90 92
RR, Q = 10 End 205 179 13 16 20 P1: 4 36 8 112 1 P2: 23 40 2 P3: 4 20 112 40 2 40 2 40 1 P4: 2 150 3 10 1 Gantt chart P1 idle P2 P3 P4 P2 P1 P3 P2 P3 P1 P3 idle 0 4 13 23 27 29 42 50 90 92 162 163 165