================ Start Lecture #7
================
Round Robbin (RR, RR, RR, RR)
- An important preemptive policy
- Essentially the preemptive version of FCFS
- The key parameter is the quantum size q
- When a process is put into the running state a timer is set to q.
- If the timer goes off and the process is still running, the OS
preempts the process.
- This process is moved to the ready state (the
preempt arc in the diagram).
- The next job in the ready list (normally a queue) is
selected to run
- As q gets large, RR approaches FCFS
- As q gets small, RR approaches PS (Processor Sharing, described next)
- What value of q should we choose?
- Tradeoff
- Small q makes system more responsive
- Large q makes system more efficient since less switching
Homework: 9, 19, 20, 21
Processor Sharing (PS, **, PS, PS)
Merge the ready and running states and permit all ready jobs to be run
at once. However, the processor slows down so that when n jobs are
running at once each progresses at a speed 1/n as fast if it were
running alone.
- Clearly impossible as stated due to overhead of process switching.
- Of theoretical interest (easy to analyze)
- Approximated by RR when the quantum is small. Make
sure you understand this last point.
Homework: 18.
Variants of Round Robbin
- State dependent RR
- Same as RR but q is varied dynamically depending on the state
of the system
- Favor processes holding important resources
- For example, non-swappable memory
- Perhaps medium term scheduling
- External priorities: RR but can pay more for bigger q
Priority Scheduling
Each job is assigned a priority (externally, perhaps by charging
more for higher priority) and the highest priority ready job is run.
- Similar to ``External priorities'' above
- If many processes with the highest priority, use RR among them.
- Can easily starve processes (see aging below for fix).
- Can have the priorities changed dynamically to favor processes
holding important resources (similar to state dependent RR).
- Many policies can be thought of as priority scheduling in
which we run the job with the highest priority (with different notions
of priority for different policies).
Priority aging
As a job is waiting, raise its priority so eventually it will have the
maximum priority.
Can apply this to many policies, in particular to priority
scheduling described above
Homework: 22, 23
Selfish RR (SRR, **, SRR, **)
- Preemptive.
- Perhaps it could be called ``snobbish RR''.
- ``Accepted processes'' run RR.
- A new process waits until its priority reaches that of accepted
processes (or until there are no accepted processes). At that point
the new process is accepted.
- A new process starts at priority 0; its priority increases at rate a>=0.
- Accepted process have their priority increase at rate b>=0.
- Note that at any time all accepted processes have same priority.
- If b>=a, get FCFS.
- If b=0, get RR.
- If a>b>0, it is interesting
Shortest Job First (SPN, SJF, SJF, SJF)
Sort jobs by total execution time needed and run the shortest first.
- Nonpreemptive
- First consider a static situation where all jobs are available in
the beginning, we know how long each one takes to run, and we
implement ``run-to-completion'' (i.e., we don't even switch to another
process on I/O). In this situation, then SJF has the shortest average
waiting time
- Moving a short job before a long one decreases the wait for
the short by the length of the long and increases the wait of the
long by the length of the short.
- This decreases the total waiting time for these two.
- Hence decreases the total waiting for all and hence decreases
the average waiting time as well.
- In the more realistic case where the scheduler switches to a new
process when the currently running process blocks (say for I/O), we
should call the policy shortest next-CPU-burst first.
- The difficulty is predicting the future (i.e., knowing in advance
the time required for the job or next-CPU-burst).
Preemptive Shortest Job First (PSPN, SRT, PSJF/SRTF, --)
Preemptive version of above
- Permit a process that enters the ready list to preempt the running
process if the time for the new process (or for its first burst) is
less than the remaining time for the running process (or for
its current burst).
- It will never happen that an existing process in the ready list
will require less time than the remaining time for the currently
running process.
- Can starve processs that have a long burst.
- This is fixed by the standard technique.
- What is that technique?
Highest Penalty Ratio Next (HPRN, HRN, **, **)
Run job that has been ``hurt'' the most.
- For each job, let r = T/t; where T = wall clock time this job has
been in system and t = the running time of the job to date.
- Run job with highest r
- Normally defined to be nonpreemptive (only check r when a burst
ends), but there is an preemptive analogue
- Do not worry about a job that just enters the system (its
ratio is undefined)
- When putting process in run state commpute the time that it
will no longer have the highest ratio and set a timer.
- When a job is moved into the ready state, compute its ratio
and preempt if needed.
- HRN stands for highest response ratio next
- This is another example of priority scheduling
Multilevel Queues (**, **, MLQ, **)
Put different classes of jobs in different queues
- Jobs do not move from one queue to another.
- Can have different policies on the different queues.
For example, might have a background (batch) queue that is FCFS and one or
more foreground queues that are RR.
- Must also have a policy among the queues.
For example, might have two queues, foreground and background, and give
the first absolute priority over the second
- Might apply aging to prevent background starvation
Multilevel Feedback Queues (FB, MFQ, MLFBQ, MQ)
Many queues and processs move from queue to queue in an attempt to
dynamically separate ``batch-like'' from interactive processs.
- Run processs from highest nonempty queue in a RR manner.
- When process uses up full quanta (looks a like batch process), move it to
a lower queue.
- When process doesn't use a full quanta (looks like an interactive
process), move it to a higher queue
- Long interactive processs (user generating spurious I/O) can keep process
in the upper queues.
- Might have bottom queue FCFS
- Many variants
For example, might let process stay in top queue 1 quantum, next queue 2
quanta (i.e. put back in same queue, at end, after first quantum
expires), next queue 4
Theoretical Issues
Considerable theory has been developed
- NP completeness results abound
- Much work in queuing theory to predict performance
- Not covered in this course
Medium Term scheduling
Decisions made at a coarser time scale.
- Called two-level scheduling by Tanenbaum
- Suspend (swap out) some process if memory is over-committed
- Criteria for choosing a victim
- How long since previously suspended
- How much CPU time used recently
- How much memory does it use
- External priority (pay more, get swapped out less)
- We will discuss again during
next topic (memory management).
Long Term Scheduling
- ``Job scheduling''. Decide when to start jobs (i.e., do not
necessarily start them when submitted.
- Force user to log out and/or block logins if overcommitted
- CTSS for decent interactive response time
- Unix if out of processes (i.e. out of PTEs)
- ``LEM jobs during the day'' (Grumman).