1 / 48

Operating Systems CMPSCI 377 Lecture 6: Scheduling

Operating Systems CMPSCI 377 Lecture 6: Scheduling. Emery Berger University of Massachusetts, Amherst. Last Time: Threads & Scheduling. Thread = execution stream within process User-level, kernel-level, hybrid There’s no perfect scheduling algorithm! Competing goals: Minimize response time

mai
Download Presentation

Operating Systems CMPSCI 377 Lecture 6: Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating SystemsCMPSCI 377Lecture 6: Scheduling Emery Berger University of Massachusetts, Amherst

  2. Last Time: Threads & Scheduling • Thread = execution stream within process • User-level, kernel-level, hybrid • There’s no perfect scheduling algorithm! • Competing goals: • Minimize response time • Maximize throughput • Fairness • Policy decision

  3. This Time: Scheduling Algorithms • FCFS • First-Come, First-Served • Round-robin • SJF • Multilevel Feedback Queues • Lottery Scheduling

  4. Round-Robin Scheduling • Quantum expires: move to back of queue • Variants used in most real systems • Quantum length – • Large: response time increases • quantum )1 = FCFS • Small: throughput decreases • quantum ) 0 = overhead dominates • context switches, cache misses

  5. waiting running Example: Round-Robin

  6. waiting running Example: Round-Robin

  7. waiting running Example: Round-Robin

  8. waiting running Example: Round-Robin

  9. waiting running Example: Round-Robin

  10. waiting running Example: Round-Robin

  11. waiting running Example: Round-Robin

  12. waiting running Example: Round-Robin

  13. waiting running Example: Round-Robin

  14. waiting running Example: Round-Robin

  15. waiting running Example: Round-Robin • Fair • Long average wait times

  16. Round-Robin vs. FCFS • Example 1: • 5 jobs, 100 seconds each, quantum = 1s • ignore context switch time

  17. Round-Robin vs. FCFS • Example 1: • 5 jobs, 100 seconds each, quantum = 1s • ignore context switch time

  18. Round-Robin vs. FCFS • Example 2: • 5 jobs: 50, 40, 30, 20, 10 seconds each

  19. Round-Robin vs. FCFS • Example 2: • 5 jobs: 50, 40, 30, 20, 10 seconds each

  20. This Time: Scheduling Algorithms • FCFS • First-Come, First-Served • Round-robin • SJF • Multilevel Feedback Queues • Lottery Scheduling

  21. 0 10 30 60 100 150 Example: SJF • Schedule job with least work until I/O or done 10 20 30 40 50

  22. 0 10 30 60 100 150 Example: SJF • Schedule job with least work until I/O or done 10 20 30 40 50

  23. 0 10 30 60 100 150 Example: SJF • Schedule job with least work until I/O or done 10 20 30 40 50

  24. 0 10 30 60 100 150 Example: SJF • Schedule job with least work until I/O or done 10 20 30 40 50

  25. 0 10 30 60 100 150 Example: SJF • Schedule job with least work until I/O or done 10 20 30 40 50

  26. 0 10 30 60 100 150 Example: SJF • Schedule job with least work until I/O or done 10 20 30 40 50

  27. Example: SJF • 5 jobs, length 50, 40, 30, 20, 10 seconds

  28. Example: SJF • 5 jobs, length 50, 40, 30, 20, 10 seconds

  29. SJF/SRTF: Shortest-Job First • Advantages: • Optimal – minimizes average waiting time • Works for preemptive & non-preemptive schedulers • Preemptive SJF = SRTF • Shortest remaining time first • I/O-bound jobs get priority over CPU-bound jobs • Disadvantages: • Impossible to predict CPU time job has left • Long-running CPU-bound jobs can starve

  30. This Time: Scheduling Algorithms • FCFS • First-Come, First-Served • Round-robin • SJF • Multilevel Feedback Queues • Lottery Scheduling

  31. Multilevel Feedback Queues (MLFQ) • Use past behavior to predict future! • Overcome prediction problem in SJF • Assumption: • I/O-bound in past, I/O-bound in future • Scheduler favors jobs that use least CPU time • Adaptive: • Change in behavior ) change in scheduling decisions

  32. MLFQ: Approximating SJF • Multiple queues, different priorities • Round-robin scheduling at each priority level • Run all at highest priority first, then next, etc. • Can lead to starvation • Increase quantum exponentially at lower priorities

  33. MLFQ Example

  34. MLFQ: Assigning Priorities • Job starts in highest priority queue • Quantum expires ) CPU-bound • Drop priority one level • Quantum does not expire ) I/O-bound • Increase priority one level • CPU-bound jobs move down,I/O-bound jobs move up

  35. Improving Fairness • SJF: optimal, but unfair • Increase fairness = give long jobs CPU time • degrades average waiting time • Solutions: • Each queue – fraction of CPU time • Fair iff even distribution of jobs among queues • Adjust priority of jobs w/o service • Originally done by UNIX • Avoids starvation • Under load, waiting time suffers

  36. This Time: Scheduling Algorithms • FCFS • First-Come, First-Served • Round-robin • SJF • Multilevel Feedback Queues • Lottery Scheduling

  37. Lottery Scheduling • Every job gets lottery tickets • Each quantum: randomly pick winner • On average:CPU time proportional to # of tickets • Give most tickets to short-running jobs (approximates SJF) • Give every job at least one ticket • Degrades gracefully as load changes

  38. Example: Lottery Scheduling • Paying customers: 40%, guests: 60% • 2:1 ticket ratio 2 1 1 1 1 1 1 2

  39. Example: Lottery Scheduling 2 1 1 1 1 1 1 2 • Paying customers: 40%, guests: 60% • 2:1 ticket ratio

  40. Example: Lottery Scheduling 2 1 1 1 1 1 1 2 • Paying customers: 40%, guests: 60% • 2:1 ticket ratio

  41. Example: Lottery Scheduling 2 1 1 1 1 1 1 2 • Paying customers: 40%, guests: 60% • 2:1 ticket ratio

  42. Example: Lottery Scheduling 2 1 1 1 1 1 1 2 • Paying customers: 40%, guests: 60% • 2:1 ticket ratio

  43. Example: Lottery Scheduling 2 1 1 1 1 1 1 2 • Paying customers: 40%, guests: 60% • 2:1 ticket ratio

  44. Example: Lottery Scheduling 2 1 1 1 1 1 1 2 • Paying customers: 40%, guests: 60% • 2:1 ticket ratio

  45. Example: Lottery Scheduling 2 1 1 1 1 1 1 2 2/5=40%

  46. Example: Lottery Scheduling 2 1 1 1 1 1 1 2 • Probabilistically achieves desired proportions 3/5=60% 2/5=40%

  47. Summary of Scheduling Algorithms • FCFS: • unfair, average waiting time poor • Round robin: • fair, average waiting time poor • SJF: • unfair, minimizes average waiting time • requires accurate prediction • Multilevel Feedback Queueing: • approximates SJF • Lottery scheduling: • fair, low average waiting time • poor fit to priority

  48. Next Time • Synchronization

More Related