Scheduling 0 : Levels
High level scheduling:
Deciding whether another process can run is process table full?
user process limit reached? load to swap space or memory?
Medium level scheduling:
Balancing the system load swap out a process?
swap in a process?
Low level scheduling
Scheduling 1 : Objectives
System throughput should be maximised. Graceful degradation of performance. No sudden collapse!
Provide a tolerable response time.
Scheduling 2 : Criteria
Job Priority : Depends on
Category of job: batch,
on-line, real-time.
CPU bound or I/O bound. Resource requirements Waiting time to date. Resources used to date.
Scheduling 3 : Low-level
Low-level scheduling can be:
Preemptive
Current process may be interrupted by o/s. new process arrived
interrupt placed blocked process in Ready queue
clock interrupt (time up). Non-Preemptive
Process executes until it terminates
blocks on I/O or system call. Cooperative
Scheduling 4 : Low-level Policies i
First-come-first-served, or FIFO.
Non-preemptive.
first process to arrive in queue gets CPU
when this process stops running, next in queue gets CPU ie. the process that has been waiting longest goes next. favours cpu-bound processes.
Round Robin
Uses a time-slice and preemption. each process runs for a short period
when timer expires, or process blocks, next process runs design issue is length of time-slice.
Scheduling 5 : Low-level Policies ii
Shortest job first.
non-preemptive
process with shortest expected processing time goes first. need to calculate processing time for each job.
risk of starvation for long jobs
Shortest remaining time
preemptive version of SJF
process with shortest remaining processing time runs. preempted if new shorter job arrives in queue.
risk of starvation again.
Scheduling 6 : Low-level iii.
Highest Response Ratio Next
non-preemptive.
process with the highest ratio of ’waiting time : run time’ goes next. Favours shorter jobs.
Doesn’t starve longer jobs
Still need to know how long the job will take to complete.
Priority = waiting time + runtime runtime
Scheduling 7 : Low-level iv.i
Multi-level feedback queues
preemptive Run Queue 0 CPU Run Queue 1 CPU Run Queue 1 CPU Run Queue 0 Run Queue 1 Run Queue 2 CPU Run Queue 0 Run Queue 1 Run Queue 2 CPU
Scheduling 8 : Low-level iv.ii
Long processes can get starved, therefore :
time quantum = τ
Process first placed on RQ0
gets time slice of length τ x 20
gets time slice of length τ x 21
gets time slice of length τ x 22
gets time slice of length τ x 2i
If process does not complete then move to RQ1
If process does not complete then move to RQ2
Scheduling 9 : Generic Unix
Traditional time-sharing, multi-user, interactive system. Uses multi-level feedback with round-robin queues. Preemption after 1 sec.
Priority is recalculated every second using
CPUj(i) = CPUj(i − 1) 2
Pj(i) = Basej + CPUj(i)
2 + nicej
from Operating Systems, W. Stallings 5th Ed. Pearson.
Where CPUj(i) Pj(i) Basej nicej utilization by j in time i priority of j at start of i
base priority of process j
user adjustment for j
Scheduling 9.1 : generic Unix
Queues are, in order of priority
Swapper
Block I/O device control
File Manipulation
Character I/O Device control
User Process
Scheduling 10 : Linux pre 2.6
Linux has one run queue, but uses several scheduling policies, a number of
priority levels and a ’niceness’ factor to control scheduling:
Niceness is in the range -20 to +19, (user processes only)
The priority is recorded in the priority field of the task_struct
and is in the range 0 - 99
The policy is recorded in the policy field of the task_struct
Policies are
SCHED_RR SCHED_FIFO SCHED_OTHER
Scheduling 10.1 : Linux pre 2.6
SCHED_RR
process base priority fixed for life in the range 1 .. 99 Round-Robin scheduling
runs until
it blocks itself -> moved to wait Q
preempted by higher priority process -> run Q uses up its quantum -> moved to run Q
SCHED_FIFO
process base priority fixed for life in the range 1 .. 99 First come first served scheduling
runs until
it blocks itself -> moved to wait Q
preempted by higher priority process -> run Q it completes current task -> moved to run Q
Scheduling 10.2 : Linux pre 2.6
SCHED_OTHER
Used for all normal processes. Process base priority fixed at 0
Process has ’niceness’ factor which affects quantum.
The counter field in task_struct is the quantum for a process.
Decremented every clock tick when process running. Scheduler called when value = 0.
counter field value recalculated as follows
counter = Scale_Factor × (20 − (nice) + 1)
The Scale_Factor is based on the processor speed and is to ensure that the standard quantum is around 50ms.
Scheduling 10.3 : Linux pre 2.6
Remember, all runnable processes are held in the same queue!
The scheduler decides which process to run next by calculating the
goodness
factor.
For policies
SCHED_RR SCHED_FIFO
goodness = 1000 + priority
Scheduling 10.4 : Linux pre 2.6
SCHED_OTHER
is a bit more complex
goodness = p->counter; if (p->processor == this_cpu) goodness += PROC_CHANGE_PENALTY; if (p->mm == this_mm || !p->mm) goodness += 1; goodness += 20 - p->nice; goto out;
If the counter value is zero for all processes then it is recalculated as