- Types of Scheduling
- Scheduling is about selecting which process runs.
- Goal is to optimize a set of criteria
- fair
- No starvation
- Efficient
- low overhead
- Respect priorities
- Types:
- Long term- decide who gets executed at all. (who goes from New to Ready and who goes from New to ready/suspend). Keeps a limit on the number of processes going.
- Medium term - who gets brought into memory (Ready/Suspend to Ready or Blocked/Suspend to Blocked) Keeps a limit of the time wasted swapping
- Short term - who actually executes (goes from Ready to Running). The dispatcher. Acts on any event.
- I/O- who gets control of the I/O channels.
- Scheduling algorithms
- Start with short-term
- User oriented (response time) vs. System Oriented (efficiency)
- User:
- Turnaround time - time start to finish
- Response time
- Meets deadlines.
- Predictability
- Priorities -
- Process with higher priorities run before low.
- Multiple queues.
- Starvation - allow priorities to change based of execution history.
- w:time spent waiting so far, e: time spent executing so far, s:total time, e+future.
- FCFS - first come, first served
- Round Robin - If quantum is too large, I/O bound processes are penalized, too small and too much time wasted in overhead.
- Virtual Round Robin - 2 ready queues: if a job was blocked for I/O it goes on the I/O job ready queue, which has higher priority.
- Shortest Process next - favor short jobs by letting them run
first.
- Long processes can be starved.
- How do we know? For batch jobs, creator specifies.
- For I/O jobs, look at the "bursts" of CPU activity.
- We could keep a running average of that job in the past:
\[\begin{aligned}
S_{n+1} =& \frac{1}{n}\sum^n_{i=1}T_i\\
&\text{which can be re-written as}\\
S_{n+1}=& \frac{1}{n} T_n + \frac{n - 1}{n} S_n\\
=&\alpha T_n + (1 - \alpha)S_n\\
\end{aligned}
\]
- The second version weights all instances equally, but we might wish to weigh more recent runs more, so we can use a tunable parameter to adjust how much each factor weighs.
- Shortest Remaining Time - Preemptive version of SPN
- Highest Response Ratio Next: \(R = \frac{w + s}{s}\). Short jobs initially favored, but as a job waits, w grows, and the ratio gets larger.
- These all assume we know a lot about the future... If we
don't, we try to approximate it. Feedback Scheduling - Multiple queues.
- Jobs start at the highest priority queue.
- if a job does not use entire quantum but blocks (not for
I/O), it will be rescheduled on same queue.
- If job uses quantum, it is rescheduled on lower priority queue.
- If a job blocks for I/O, it is rescheduled on a higher queue.
- At the bottom is a round-robin queue.
- Performance modeling

- Fair Share - tasks are often made up of several processes, or in the case of linux, individually scheduled threads.
- We may want to schedule based on these groups.
- Priority of process is sum of base priority + portion of time spent running + portion of time other processes in group spent running.
- Linux Scheduling
- 1.2 Round Robin
- 2.2 Separate queues for real-time and batch tasks.
- 2.4 \(O(n)\) Epoch- if process doesn't use all its
timeslice, the remaining is added to its next timeslice. Each
process was evaluated based on priority and history at each
switch. Slow.
- 2.6 \(O(1)\) Multi-level queue system, complex heuristics to
select queue for process.
- 2.6.21 "Completely Fair Scheduler" Keep track of processor
time. Implement the priority queue with a red-black tree.
(WHY!?) Priority is managed by giving higher priority tasks more
time on the CPU. It also allocates time on CPU based on group,
for fair sharing.