Unformatted text preview:

Review Banker s Algorithm for Preventing Deadlock Banker s algorithm CS162 Operating Systems and Systems Programming Lecture 11 Allocate resources dynamically Evaluate each request and grant if some ordering of threads is still deadlock free afterward Technique pretend each request is granted then run deadlock detection algorithm substituting Maxnode Allocnode Avail for Requestnode Avail Grant request if result is deadlock free conservative Keeps system in a SAFE state i e there exists a sequence T1 T2 Tn with T1 requesting all remaining resources finishing then T2 requesting all remaining resources etc Thread Scheduling con t Protection Address Spaces October 5 2009 Prof John Kubiatowicz http inst eecs berkeley edu cs162 Algorithm allows the sum of maximum resource needs of all current threads to be greater than total resources 10 5 09 Review Last Time Run threads to completion in order of submission Pros Simple Cons Short jobs get stuck behind long ones Round Robin Scheduling Give each thread a small amount of CPU time when it executes cycle between all ready threads Pros Better for short jobs Cons Poor when jobs are same length Kubiatowicz CS162 UCB Fall 2009 Lec 11 2 Review FCFS and RR Example with Different Quantum Scheduling selecting a waiting process from the ready queue and allocating the CPU to it FCFS Scheduling 10 5 09 Kubiatowicz CS162 UCB Fall 2009 Lec 11 3 P2 8 Best FCFS 0 P4 24 8 32 Quantum Best FCFS Q 1 Q 5 Wait Q 8 Time Q 10 Q 20 Worst FCFS Best FCFS Q 1 Q 5 Completion Q 8 Time Q 10 Q 20 Worst FCFS 10 5 09 P1 53 P1 32 84 82 80 82 72 68 85 137 135 133 135 125 121 P3 68 85 P2 0 22 20 8 10 20 145 8 30 28 16 18 28 153 P3 85 85 85 85 85 85 0 153 153 153 153 153 153 68 Kubiatowicz CS162 UCB Fall 2009 153 P4 8 57 58 56 68 88 121 32 81 82 80 92 112 145 Average 31 62 61 57 61 66 83 69 100 99 95 99 104 121 Lec 11 4 Starvation Review SRTF Further discussion Goals for Today SRTF can lead to starvation if many small jobs Large jobs never get to run Somehow need to predict future How can we do this Some systems ask the user Finish discussion of Scheduling Kernel vs User Mode What is an Address Space How is it Implemented When you submit a job have to say how long it will take To stop cheating system kills job if takes too long But Even non malicious users have trouble predicting runtime of their jobs Bottom line can t really know how long job will take However can use SRTF as a yardstick for measuring other policies Optimal so can t do any better SRTF Pros Cons Note Some slides and or pictures in the following are adapted from slides 2005 Silberschatz Galvin and Gagne Optimal average response time Hard to predict future Unfair 10 5 09 Kubiatowicz CS162 UCB Fall 2009 Lec 11 5 10 5 09 Kubiatowicz CS162 UCB Fall 2009 Example to illustrate benefits of SRTF C A or B C s I O Three jobs SRTF Example continued C s I O C C s I O A RR 100ms time slice C s I O A B both CPU bound run for week C I O bound loop 1ms CPU 9ms disk I O If only one at a time C uses 90 of the disk A or B could use 100 of the CPU With FIFO CABAB C s I O C Once A or B get in keep CPU for two weeks C A A Easier to see with a timeline C s I O C s I O Kubiatowicz CS162 UCB Fall 2009 Lec 11 7 10 5 09 Disk CUtilization 9 201 4 5 C sUtilization Disk I O 90 but lots of wakeups RR 1ms time slice C s I O What about RR or SRTF 10 5 09 B Lec 11 6 Disk Utilization 90 A SRTF Kubiatowicz CS162 UCB Fall 2009 Lec 11 8 Predicting the Length of the Next CPU Burst Adaptive Changing policy based on past behavior Multi Level Feedback Scheduling Long Running Compute Tasks Demoted to Low Priority CPU scheduling in virtual memory in file systems etc Works because programs have predictable behavior If program was I O bound in past likely in future If computer behavior were random wouldn t help Example SRTF with estimated burst length Use an estimator function on previous bursts Let tn 1 tn 2 tn 3 etc be previous CPU burst lengths Estimate next burst n f tn 1 tn 2 tn 3 Function f could be one of many different time series estimation schemes Kalman filters etc For instance exponential averaging n tn 1 1 n 1 with 0 1 10 5 09 Another method for exploiting past behavior First used in CTSS Multiple queues each with different priority Higher priority queues often considered foreground tasks Each queue has its own scheduling algorithm e g foreground RR background FCFS Sometimes multiple RR priorities with quantum increasing exponentially highest 1ms next 2ms next 4ms etc Adjust each job s priority as follows details vary Kubiatowicz CS162 UCB Fall 2009 Lec 11 9 Job starts in highest priority queue If timeout expires drop one level If timeout doesn t expire push up one level or to top 10 5 09 Scheduling Details Midterm I coming up in two weeks CPU bound jobs drop like a rock Short running I O bound jobs stay near top Monday 10 19 6 00 9 00 145 Dwinelle Should be 2 hour exam with extra time Closed book one page of hand written notes both sides Scheduling must be done between the queues Fixed priority scheduling serve all from highest priority then next priority etc Time slice each queue gets a certain amount of CPU time e g 70 to highest 20 next 10 lowest Countermeasure user action that can foil intent of the OS designer For multilevel feedback put in a bunch of meaningless I O to keep job s priority high Of course if everyone did this wouldn t work Example of Othello program Playing against competitor so key was to do computing at higher priority the competitors Put in printf s ran much faster Kubiatowicz CS162 UCB Fall 2009 Lec 11 10 Administrivia Result approximates SRTF 10 5 09 Kubiatowicz CS162 UCB Fall 2009 Lec 11 11 No class on day of Midterm I will post extra office hours for people who have questions about the material or life whatever Review Session 7 00pm Sunday 10 18 Location TBA Midterm Topics Everything up to and including Wednesday 10 14 History Concurrency Multithreading Synchronization Protection Address Spaces TLBs 10 5 09 Kubiatowicz CS162 UCB Fall 2009 Lec 11 12 Scheduling Fairness What about fairness Lottery Scheduling Strict fixed priority scheduling between queues is unfair run highest then next etc long running jobs may never get CPU In Multics shut down machine found 10 year old …


View Full Document

Berkeley COMPSCI 162 - Lecture 11 Thread Scheduling Protection: Address Spaces

Documents in this Course
Lecture 1

Lecture 1

12 pages

Nachos

Nachos

41 pages

Security

Security

39 pages

Load more
Loading Unlocking...
Login

Join to view Lecture 11 Thread Scheduling Protection: Address Spaces and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 11 Thread Scheduling Protection: Address Spaces and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?