scheduling 3 1
Changelog Changes not seen in fjrst lecture: 4 Feb 2020: MLFQ example: number priorities so largest number is highest priority 4 Feb 2020: lottery scheduler assignment: replace “how long processes run” with “how often processes scheduled’ to better match assignment writeup 4 Feb 2020: CFS: A’s long sleep: show overriding of natural virtual time with strikeout 4 Feb 2020: added CFS exercise explanation slides 1
last time fjrst-come fjrst-served and round robin round robin time quantum low = fair but bad throughput high = unfair (order) but good throughput priority scheduling run some threads fjrst, no matter what often implies starvation shortest remaining time fjrst (SRTF): mean turnaround time started multi-level feedback queues approximate SRTF via priority buckets exceeds time quantum? adjust priority 2 ⇒ CPU burst estimate + time quantum priority =
multi-level feedback queues classic strategy based on priority scheduling combines update time estimates and running shorter times fjrst small(ish) number of time estimate “buckets” 3 key idea: current priority ≈ current time estimate
multi-level feedback queues: setup priority 3 use less than 1ms at priority 0? — you shouldn’t be there use more than 1ms at priority 3? — you shouldn’t be there dynamically adjust priorities based on observed CPU burst times just a few priority levels — can’t guess CPU burst precisely anyways goal: place processes at priority level based on CPU burst time thread F thread E thread D thread C thread B thread A 20+ ms quantum priority 0 10–20 ms quantum priority 1 1–10 ms quantum priority 2 0–1 ms quantum 4 priority level → allowed/expected time quantum
taking advantage of history thread D thread A put on higher priority next time fjnished early? thread A add to lower priority queue now used whole timeslice? priority process run highest thread F thread E thread C priority 3 / 1 ms thread B thread A quantum with difgerent each priority round robin at idea: priority = CPU burst length priority 0 / 100 ms priority 1 / 20 ms priority 2 / 10 ms 5
taking advantage of history thread D thread A put on higher priority next time fjnished early? thread A add to lower priority queue now used whole timeslice? priority process run highest thread F thread E thread C priority 3 / 1 ms thread B thread A quantum each priority round robin at idea: priority = CPU burst length priority 0 / 100 ms priority 1 / 20 ms priority 2 / 10 ms 5 with difgerent
taking advantage of history thread D thread A put on higher priority next time fjnished early? thread A add to lower priority queue now used whole timeslice? priority process run highest thread F thread E thread C priority 3 / 1 ms thread B thread A quantum with difgerent each priority round robin at idea: priority = CPU burst length priority 0 / 100 ms priority 1 / 20 ms priority 2 / 10 ms 5
taking advantage of history thread D thread A put on higher priority next time fjnished early? thread A add to lower priority queue now used whole timeslice? priority process run highest thread F thread E thread C priority 3 / 1 ms thread B thread A quantum with difgerent each priority round robin at idea: priority = CPU burst length priority 0 / 100 ms priority 1 / 20 ms priority 2 / 10 ms 5
multi-level feedback queue idea higher priority = shorter time quantum (before interrupted) adjust priority and timeslice based on last timeslice intuition: thread always uses same CPU burst length? ends up at “right” priority rises up to queue with quantum just shorter than it’s burst then goes down to next queue, then back up, then down, then up, etc. 6
MLFQ example prio 1: B ready B B ready B B I/O B promoted; did not use whole quantum B quantum quantum B uses quantum (again), demoted (NB: new quantum used in two parts) B B ready B quantum A, B start at highest priority (wrong guess for B) quantum oscillation: too big for prio 2 / too small for prio 3 B uses quantum, demoted prio 2: A: A’s I/O (wait for I/O) (wait for I/O) (wait for I/O) … (I/O) prio 3: A’s I/O B I/O quantum B A ready A A’s I/O A A fjnishes I/O A’s I/O A 7 B: (I/O)
MLFQ example prio 1: B ready B B ready B B I/O B promoted; did not use whole quantum B quantum quantum B uses quantum (again), demoted (NB: new quantum used in two parts) B B ready B quantum A, B start at highest priority (wrong guess for B) quantum oscillation: too big for prio 2 / too small for prio 3 B uses quantum, demoted prio 2: A: A’s I/O (wait for I/O) (wait for I/O) (wait for I/O) … (I/O) prio 3: A’s I/O B I/O quantum B A ready A A’s I/O A A fjnishes I/O A’s I/O A 7 B: (I/O)
MLFQ example prio 1: B ready B B ready B B I/O B promoted; did not use whole quantum B quantum quantum B uses quantum (again), demoted (NB: new quantum used in two parts) B B ready B quantum A, B start at highest priority (wrong guess for B) quantum oscillation: too big for prio 2 / too small for prio 3 B uses quantum, demoted prio 2: A: A’s I/O (wait for I/O) (wait for I/O) (wait for I/O) … (I/O) prio 3: A’s I/O B I/O quantum B A ready A A’s I/O A A fjnishes I/O A’s I/O A 7 B: (I/O)
MLFQ example prio 1: B ready B B ready B B I/O B promoted; did not use whole quantum B quantum quantum B uses quantum (again), demoted (NB: new quantum used in two parts) B B ready B quantum A, B start at highest priority (wrong guess for B) quantum oscillation: too big for prio 2 / too small for prio 3 B uses quantum, demoted prio 2: A: A’s I/O (wait for I/O) (wait for I/O) (wait for I/O) … (I/O) prio 3: A’s I/O B I/O quantum B A ready A A’s I/O A A fjnishes I/O A’s I/O A 7 B: (I/O)
MLFQ example prio 1: B ready B B ready B B I/O B promoted; did not use whole quantum B quantum quantum B uses quantum (again), demoted (NB: new quantum used in two parts) B B ready B quantum A, B start at highest priority (wrong guess for B) quantum oscillation: too big for prio 2 / too small for prio 3 B uses quantum, demoted prio 2: A: A’s I/O (wait for I/O) (wait for I/O) (wait for I/O) … (I/O) prio 3: A’s I/O B I/O quantum B A ready A A’s I/O A A fjnishes I/O A’s I/O A 7 B: (I/O)
cheating multi-level feedback queuing algorithm: don’t use entire time quantum? priority increases getting all the CPU: while ( true ) { useCpuForALittleLessThanMinimumTimeQuantum(); yieldCpu(); } 8
almost none — starvation multi-level feedback queuing and fairness suppose we are running several programs: A. one very long computation that doesn’t need any I/O B1 through B1000. 1000 programs processing data on disk C. one interactive program how much time will A get? intuition: the B programs have higher priority than A because it has smaller CPU bursts 9
multi-level feedback queuing and fairness suppose we are running several programs: A. one very long computation that doesn’t need any I/O B1 through B1000. 1000 programs processing data on disk C. one interactive program how much time will A get? intuition: the B programs have higher priority than A because it has smaller CPU bursts 9 almost none — starvation
MLFQ variations version of MLFQ I described is in Anderson-Dahlin problems: starvation worse than with real SRTF — based on guess , not real remaining time oscillation not great for predictability 10
variation to prevent starvation Apraci-Dusseau presents version of MLFQ w/o starvation two changes: don’t increase priority when whole quantum not used instead keep the same — more stable periodically increase priority of all threads allow compute-heavy threads to run a little still deals with thread’s behavior changing over time replaces fjner-grained upward adjustments 11
FreeBSD scheduler current default FreeBSD scheduler based on MLFQ idea …but: time quantums don’t depend on priority I/O wait note: deliberately not estimating remaining time (using “recent” history of thread) thread priorities set based on interactivity score 12 computes interactivity score ∼ I/O wait + runtime
confmicting goals for interactivity heuristics effjciency avoid scanning all threads every few milliseconds fjgure out new programs quickly adapt to changes/spikes in program behavior avoid pathological behavior starvation, hanging when new compute-intensive program starts, etc. exercise: how to handle each of these well? what does MLFQ do well? 13
fair scheduling what is the fairest scheduling we can do? intuition: every thread has an equal chance to be chosen 14
random scheduling algorithm “fair” scheduling algorithm: choose uniformly at random good for “fairness” bad for response time bad for predictability 15
proportional share maybe every thread isn’t equal if thread A is twice as important as thread B, then… one idea: thread A should run twice as much as thread B proportional share 16
proportional share maybe every thread isn’t equal if thread A is twice as important as thread B, then… one idea: thread A should run twice as much as thread B proportional share 16
Recommend
More recommend