Documente Academic
Documente Profesional
Documente Cultură
Operating
Systems
Spring 2012
Ed Lazowska
lazowska@cs.w
ashington.edu
Allen Center 570
Module 10
Scheduling
In discussing processes and threads, we talked about
context switching
an interrupt occurs (device completion, timer interrupt)
a thread causes a trap or exception
may need to choose a different thread/process to run
Classes of Schedulers
Batch
Throughput / utilization oriented
Example: audit inter-bank funds transfers each night, Pixar rendering,
Hadoop/MapReduce jobs
Interactive
Response time oriented
Example: attu.cs
Real time
Deadline driven
Example: embedded systems (cars, airplanes, etc.)
Parallel
Speedup-driven
Example: space-shared use of a 1000-processor machine for large
simulations
Well be talking primarily about interactive schedulers
Medium term
Should a running program be temporarily marked as nonrunnable (e.g., swapped out)?
Short term
Which thread should be given the CPU next? For how long?
Which I/O operation should be sent to the disk next?
On a multiprocessor:
should we attempt to coordinate the running of threads from the
same address space in some way?
should we worry about cache state (processor affinity)?
Schedulable units
Scheduling:
- Who to assign each resource to
- When to re-evaluate your
decisions
Resources
When to assign?
Preemptive
you can re-visit a decision
setting the timer allows you to preempt the CPU from a thread even if it
doesnt relinquish it voluntarily
in any modern system, if you mark a program as non-runnable, its memory
resources will eventually be re-allocated to others
Littles Law: N = X * R
Where N is average number in system, X is throughput, and
R is average response time (average time in system)
This means that better average response time implies fewer in
system, and vice versa
Proof:
Let W denote the total time-in-system accumulated by all
customers during a time interval of length T
The average number of requests in the system N = W / T
If C customers complete during that time period, then the
average contribution of each completing request R = W / C
Algebraically, W/T = C/T * W/C.
Thus, N = X * R
10
11
12
13
Up * Rp = constant
14
Sounds perfect!
in the real world, when does FCFS/FIFO work well?
even then, whats its limitation?
15
FCFS/FIFO example
time
1
2
Job A
B
Job A
16
FCFS/FIFO drawbacks
Average response time can be lousy
small requests wait behind big ones
17
18
sg
tk+sf
tk+sf+sg
19
SPT/SJF drawbacks
Its non-preemptive
So?
20
Algorithm #3: RR
Sounds perfect!
how is RR an improvement over FCFS?
how is RR an improvement over SPT?
how is RR an approximation to SPT?
2012 Gribble, Lazowska, Levy, Zahorjan
21
RR drawbacks
What if all jobs are exactly the same length?
What would the pessimal schedule be (with average
response time as the measure)?
22
Sounds perfect!
23
Priority drawbacks
How are you going to assign priorities?
Starvation
if there is an endless supply of high priority jobs, no lowpriority job will ever run
24
25
Residual
ResidualLife
Life
Given that a job has already executed for X seconds,
how much longer will it execute, on average, before
completing?
Give priority to new jobs
Round robin
Residual
Life
Give priority to old jobs
26
27
UNIX scheduling
Canonical scheduler is pretty much MLFQ
3-4 classes spanning ~170 priority levels
timesharing: lowest 60 priorities
system: middle 40 priorities
real-time: highest 60 priorities
Goals:
reward interactive behavior over CPU hogs
interactive jobs typically have short bursts of CPU
2012 Gribble, Lazowska, Levy, Zahorjan
28
29
2012
Gribble,
Lazowska,
Levy,
Zahorjan
2003
Bianca
Schroeder
& Mor
Harchol-Balter,
CMU
30
Summary
Scheduling takes place at many levels
It can make a huge difference in performance
this difference increases with the variability in service
requirements
31