Title: Chapter 9, Part II
1Chapter 9, Part II
2Scheduling Algorithms
Algorithms
- First Come First Served (FCFS)
- Round Robin (RR) time slicing.
- Shortest Process Next (SPN)
- Shortest Remaining Time (SRT)
- Highest Response Ratio Next (HRRH)
- Feedback
3First-Come-First-Served (FCFS)
1
2
3
4
5
4FCFS (continued)
- First-Come-First-Served - each process joins the
Ready queue - When the current process ceases to execute, the
oldest process in the Ready queue is selected - A short process may have to wait a very long time
before it can execute. - Favors CPU-bound processes over I/O-bound
processes. - I/O processes have to wait until CPU-bound
process completes - FCFS, although not attractive alternative for a
uni-processor system, when combined with a
priority scheme may prove to be an effective
scheduler.
5Round-Robin (RR)
1
2
3
4
5
6Round Robin (continued)
- Uses FCFS w/preemption - based on a clock (time
slicing). - If the time quantum is very short, then short
processes move relatively quickly through the
system (with more overhead). - The time quantum should be slightly greater than
the time required for a typical interaction. - Particularly effective in GP time-sharing or
transaction processing system. - Generally favors processor bound processes as I/O
bound give up their time slice while process
bound use their complete time quantum. - Could be improved using a virtual round robin
(VRR) scheduling scheme implement an auxiliary
I/O queue which gets preference over the main
queue.
7Shortest Process Next (SPN)
8Shortest Process Next (continued)
- Shortest Process Next - Non-preemptive policy
- Process with shortest expected processing time is
selected next - Short process jumps ahead of longer processes
- May be impossible to know or at least estimate
the required processing time of a process. - For batch jobs, require a programmers estimate.
- If estimate is substantially off, system may
abort job. - In a production environment, the same jobs run
frequently and statistics may be gathered. - In an interactive environment, the operating
system may keep a running average of each burst
for each process. - SPN could result in starvation of longer
processes if there is a steady supply of short
processes. - Not suitable for time-sharing or transaction
processing environment because of lack of
preemption.
9Shortest Remaining Time (SRT)
10Shortest Remaining Time (continued)
- The shortest remaining time (SRT) policy is a
preemptive version of SPN. - Must estimate expected remaining processing time
- When a new process joins the ready queue, it may
have a shorter remaining time and preempts the
current process. - SRT does not bias in favor of long processes (as
does FCFS) - Unlike RR, no additional interrupts are generated
reducing overhead. - Superior turnaround performance to SPN, because a
short job is given immediate preference to a
running longer job.
11Highest Response Ratio Next (HRRN)
1
2
3
4
5
12Highest Response Ration Next (continued)
- Choose next process with the highest ratio
- Attractive approach to scheduling because it
accounts for the age of a process. - While shorter jobs are favored (a smaller
denominator yields a larger ratio), aging without
service increases the ratio so that a longer
process will eventually get past competing
shorter jobs.
13Feedback
- If we have no indication of the relative length
of various processes, then SPN, SRT, and HRRN
cannot be effectively used. - ie. if we cannot focus on time remaining, focus
on time spent in execution so far. - Using feedback, we can give preference for
shorter jobs by penalizing jobs that have been
running longer. - Feedback scheduling is done on a preemptive basis
with a dynamic priority mechanism. - A process is demoted to the next lower-priority
queue each time it returns to the ready queue.
14Feedback (continued)
- Within each queue, a simple FCFS mechanism is
used except once in the lowest-priority queue, a
process cannot go lower and is treated in a RR
fashion. - Longer processes gradually drift downward.
- Newer, shorter processes are favored over older,
longer processes. - Feedback scheduling can make turnaround time for
longer processes intolerable. - To avoid starvation, preemption time for
lower-priority processes is usually longer.
15Comparisons
Comparisons
Starvation
Effect on Processes
Overhead
Response Time
Throughput
Decision Mode
Selection Function
FCFS
Round Robin (RR)
Shortest Process Next (SPN)
Shortest Remaining Time (SRT)
Highest Response Ratio Next (HRRN)
Feedback
16Comparisons
P1
P2
P3
P4
P5
Mean
Arrival
0
2
4
6
8
Service Time
3
6
4
5
2
- P1 arrives at time 0, requires 3 units
- P2 arrives at time 2, requires 6 units
- P3 arrives at time 4, requires 4 units
- P4 arrives at time 6, requires 5 units
- P5 arrives at time 8, requires 2 units
17Fair Scheduling
Other Algorithms
- Users application runs as a collection of
processes (threads) - User is concerned about the performance of the
application - Need to make scheduling decisions based on groups
of processes - Lottery Scheduling
18Multilevel Queue Scheduling
Other Algorithms
- Partition the ready queue
- system processes, interactive processes,batch
processes, student processes, etc. - Schedule each queue separately
- Assign a priority among queues
- schedule between queues
- generally a fixed priority preemptive
- Multilevel feedback queueing
- allow a process to move between queues
19Scheduling Algorithm Evaluation
Algorithm Evaluation
- How do we pick an algorithm?
- Many algorithms
- Many parameters
- Maximize or Minimize some criteria.
- Utilization, throughput, etc.
- What do we base our choice on?
- A single example?
20Deterministic Modeling
Algorithm Evaluation
- Given a predetermined workload, simulate
- run the workload through different schedulers
- calculate statistics
Process P1 P2 P3 P4 P5
Burst Time 10 29 3 7 12
21Deterministic Modeling
Algorithm Evaluation
What about context switch overhead?
22Deterministic Modeling
Algorithm Evaluation
Advantages Simple Fast Exact Results Disadvantage
s too specific too much exact knowledge is
required tied to example data
23Queuing Theory
Queuing Theory
- Using statistics, we can determine the
distribution of CPU and I/O bursts. - Probability distribution function
- The result is a mathematical formula which
describes the probability of a particular burst - Mathematics can then tell us performance
- A computer system can be described as a network
of servers - each server has a queue of waiting processes
- Simply add an imaginary server to each queue.
- Now, we can compute statistics
24UNIX Scheduling
Other Algorithms
- Priorities are recomputed once per second
- Base priority divides all processes into fixed
bands of priority levels - Nice adjustment factor used to keep process in
its assigned band
25Unix System V Scheduling
Performance Comparisons
- Multilevel feedback (Fair-share scheduling), with
- RR within each priority queue
- 10ms second preemption
- priority based on process type and execution
history, lower value is higher priority - Priority recomputed once per second, and
scheduler selects new process to run - For process j, Pj(i) Base CPU(i-1)/2 nice
- Pj(i) is priority of process j at interval i
- Base is base priority of process j
- CPU(i) U(i)/2 CPU(i-1)/2
- U(i) is CPU use of process j in interval i
- exponentially weighted average CPU use through
interval i - nice is user-controllable adjustment factor
- Restrictions placed on CPU and nice to prevent a
process from getting too far away from its base
priority band
26(No Transcript)
27Scheduling Algorithms
Algorithms
- First Come First Served (FCFS)
- Round Robin (RR) time slicing.
- Shortest Process Next (SPN)
- Shortest Remaining Time (SRT)
- Highest Response Ratio Next (HRRN)
- Feedback
28Algorithms
Algorithms
- First Come First Served
- Processes queued in order of arrival
- Runs until finished or blocks on I/O
- Tends to penalize short processes (have to wait
for long processes) - Favors processor-bound processes (I/O process
quickly block) - Round Robin
- FCFS with preemption
- Size of ticks affects performance
- Favors processor-bound processes
- Virtual Round Robin
- Second queue for formerly blocked processes
given priority - At end of time slice, add to end of standard queue
29Algorithms (continued)
Algorithms
- Shortest Process Next
- Select process with shortest expected running
time (non-preemptive) - Difficult to estimate required time (keep
history) - Tends to be less predictable
- Can starve long processes
- Short processes may still wait if a long process
has just started - Shortest Remaining Time
- Preemptive version of Shortest Process Next
- May switch processes when a new process arrives
- Still may starve long processes
30Algorithms (continued)
Algorithms
- Highest Response Ratio Next
- Non-preemptive, tries to get best average
normalized turnaround time - Depends on Response Ratio
- W time spent waiting
- S expected service time RR (W S) / S
- Select process with highest RR
- Feedback
- Starts in high-priority queue, moves down in
priority as it executes - Lower-priority queues often given longer time
slices - Can starve long processes
- Move up processes if they wait too long