Midterm
1
Introduction to CPU Scheduling Part 2
2
The worst assumption:
3
The Question
How do we schedule jobs without knowing their run time duration so that we can minimize turnaround time and also minimize response time for interactive jobs?
4
Multilevel Feedback Queue (MLFQ)
5
Multilevel Feedback Queue (MLFQ)
6
Multilevel Feedback Queue (MLFQ)
7
Multilevel Feedback Queue (MLFQ)
8
?
Multilevel Feedback Queue (MLFQ)
Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t)
Rule 2: If Priority(A) = Priority(B), RR(A, B)
Does it work well?
9
Multilevel Feedback Queue (MLFQ)
Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t)
Rule 2: If Priority(A) = Priority(B), RR(A, B)
With only these two rules, A and B will keep alternating via RR, and C and D will never get to run.
What other rule(s) do we need to add?
We need to understand how job priority changes over time.
10
Attempt 1: How to Change Priority
Rule 3: When a job enter the system, it is placed at the highest priority (the top most queue).
Rule 4a: If a job uses up an entire time slice while running, its priority is reduced (it moves down one queue).
Rule 4b: If a job gives up the CPU (voluntarily) before the time slice is up, it stays at the same priority level.
11
Example 1: A Single Long-Running Job
12
Example 2: Along Came A Short Job
Major goal of MLFQ: At first, since the scheduler does not know about the job, it first assumes that is might be a short job (higher priority). If it is not a short job, it will gradually be moved down the queues.
13
Example 3: What about I/O?
14
Problem 1: Starvation
15
Problem 2: Gaming the System
16
Problem 3:
17
Attempt 2: Priority Boost
Rule 5: After some time period S, move all the jobs in the system to the topmost queue
18
Problem: Starvation
Rule 5 help guaranteeing that processes will not be staved. It also helps with CPU-bound jobs that become interactive
19
What should S be set to?
20
Attempt 3: Better Accounting
Rewrite of Rule 4 to address the issue of gaming the system
Rule 4: Once a job uses up its time allotment at a given level (regardless of how many time it has given up the CPU), its priority is reduced.
21
Summary
Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t)
Rule 2: If Priority(A) = Priority(B), RR(A, B)
Rule 3: When a job enter the system, it is placed at the highest priority (the top most queue).
Rule 4: Once a job uses up its time allotment at a given level (regardless of how many time it has given up the CPU), its priority is reduced.
Rule 5: After some time period S, move all the jobs in the system to the topmost queue
MLFQ observes the execution of a job and gradually learns what type of job it is, and prioritize it accordingly.
Used by many systems, including FreeBSD, MacOS X, Solaris, Linux 2.6, and Windows NT
22
Exercise
Follow the Setup External Access slides to enable browser-based access to the VM.
Update the Operating-Systems git repository in the CSC VM
$ cd ~/Operating-Systems
$ git pull
$ cd schedule
$ ls
23
Exercise 1
24
Exercise 2
25