Recap • First-Come, First-Served (FCFS) – Run to completion in order of arrival – Pros: simple, low overhead, good for batch jobs – Cons: short jobs can stuck behind the long ones • Round-Robin (RR) – FCFS with preemption. Cycle after a fixed time quantum – Pros: better interactivity (low average scheduling latency) – Cons: performance is dependent on the quantum size • Shortest Job First (SJF)/ Shorted Remaining Time First (SRTF) – Shorted job (or shortest remaining job) first – Pros: optimal average waiting time – Cons: you need to know the future, long jobs can be starved by short jobs 1
50
Embed
Lecture 2: Operating System Structure - ittc.ku.eduheechul/courses/eecs678/S18/slides/W8.Scheduling.pdfMulti-level Feedback Queue • Each queue has a priority ... Example of Multilevel
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Recap
• First-Come, First-Served (FCFS)– Run to completion in order of arrival
– Pros: simple, low overhead, good for batch jobs
– Cons: short jobs can stuck behind the long ones
• Round-Robin (RR)– FCFS with preemption. Cycle after a fixed time quantum
– Pros: better interactivity (low average scheduling latency)
– Cons: performance is dependent on the quantum size
• Shortest Job First (SJF)/ Shorted Remaining Time First (SRTF)– Shorted job (or shortest remaining job) first
– Pros: optimal average waiting time
– Cons: you need to know the future, long jobs can be starved by short jobs
1
Example
• Task A and B
– CPU bound, run an hour
• Task C
– I/O bound, repeat(1ms CPU, 9ms disk I/O)
• FCFS?
– If A or B is scheduled first, C can begins an hour later
• RR and SRTF?
2
Compute I/O I/O
A or B C
Example Timeline
3
C A B
RR with 100ms time quantum
C
…
A
RR with 1ms time quantum
B … A B
I/O
I/O
C A B A B … C A B …
I/O
C
…
SRTF
A
I/O
C A C A …
I/O
Discussion
• Comparison between FCFS, SRTF(SJF), and RR
– What to choose for smallest average waiting time?
• SRTF (SFJ) is the optimal
– What to choose for better interactivity?
• RR with small time quantum (or SRTF)
– What to choose to minimize scheduling overhead?
• FCFS
4
Agenda
• Multi-level queue scheduling
• Fair scheduling
• Real-time scheduling
• Multicore scheduling
5
Multiple Scheduling Goals
• Optimize for interactive applications
– Round-robin
• Optimize for batch jobs
– FCFS
• Can we do both?
6
Multi-level Queue
• Ready queue is partitioned into separate queues
– Foreground: interactive jobs
– Background: batch jobs
• Each queue has its own scheduling algorithm
– Foreground : RR
– Background: FCFS
• Between the queue?
7
Multi-level Queue Scheduling
• Scheduling between the queues
– Fixed priority
• Foreground first; schedule background only when no tasks in foreground
• Possible starvation
– Time slicing
• Assign fraction of CPU time for each queue
• 80% time for foreground; 20% time for background
8
Multi-level Feedback Queue
• Each queue has a priority
• Tasks migrate across queues
– Each job starts at the highest priority queue
– If it uses up an entire quantum, drop one-level
– If it finishes early, move up one-level (or stay at top)
• Benefits
– Interactive jobs stayat high priority queues
– Batch jobs will be at the low priority queue
– Automatically!
9
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 0
Time
A B C
0 2 5 9
10
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 1
Time
A
B C
0
0 3 7
A
1
11
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 2
Time
A B
C
0
0 4
3
A
1
B
12
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 3
Time
A B C
0 63
A
1
B C
13
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 3
Time
A B C
0 63
A
1
B C
Suppose A is blocked on I/O
14
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 3
Time
B C
52
A B C
Suppose A is blocked on I/O
0
15
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 5
Time
A
B
C
0
3
A
1
B C
A is returned from I/O
0
16
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 6
TimeAB
C
3
A B C
0
17
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 8
TimeAB
C
3
A B C
2
C
18
Example of Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 9
TimeAB CA B C C
19
Recap: Multi-level Queue
• Ready queue is partitioned into separate queues
– Foreground: interactive jobs
– Background: batch jobs
• Each queue has its own scheduling algorithm
– Foreground : RR
– Background: FCFS
• Between the queue?
20
Recap: Multi-level Feedback Queue
• Each queue has a priority
• Tasks migrate across queues
– Each job starts at the highest priority queue
– If it uses up an entire quantum, drop one-level
– If it finishes early, move up one-level (or stay at top)
• Benefits
– Interactive jobs stayat high priority queues
– Batch jobs will be at the low priority queue
– Automatically!
21
Completely Fair Scheduler (CFS)
22
• Linux default scheduler, focusing on fairness
• Each task owns a fraction of CPU time share
– E.g.,) A=10%, B=30%, C=60%
• Scheduling algorithm
– Each task maintains its virtual runtime
• Virtual runtime = executed time (x 1 / weight)
– Pick the task with the smallest virtual runtime
• Tasks are sorted according to their virtual times
CFS Example
• Tasks are sorted according to their virtual times
23
5
6
8
10
Scheduled the “neediest” task
CFS Example
• Tasks are sorted according to their virtual times
24
9
6
8
10
On a next scheduler eventre-sort the list
But list is inefficient.
Red-black Tree
– Self-balancing binary search tree
– Insert: O(log N), Remove: O(1)
25
Figure source: M. Tim Jones, “Inside the Linux 2.6 Completely Fair Scheduler”, IBM developerWorks