Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scheduling Adapted from:

Similar presentations


Presentation on theme: "Scheduling Adapted from:"— Presentation transcript:

1 Scheduling Adapted from:
© Ed Lazowska, Hank Levy, Andrea And Remzi Arpaci-Dussea, Michael Swift

2 Decisions about Resources
Allocation: Which process gets which resource Which resources should each process get? Space sharing: Control concurrent access to resource Implication: Resources are not easily preemptible Example: disk space Scheduling: How long process keeps resource In which order should requests be serviced Time sharing: More resources requested than exist Implication: Resource is preemtible Example: CPU time

3 Role of Dispatcher vs. Scheduler
Low-level mechanism Responsibility: Context-switch Change mode of old process to either WAITING or BLOCKED Save execution state of old process in PCB Load state of new process from PCB Change mode of new processes to RUNNING Switch to user mode privilege Jump to process instruction Scheduler Higher level policy Responsibility: Decide which process to dispatch to CPU could be allocated Parallel and Distributed Systems

4 Scheduling The scheduler is the module that moves jobs from queue to queue the scheduling algorithm determines which job(s) are chosen to run next, and which queues they should wait on the scheduler is typically run when: a job switches from running to waiting when an interrupt occurs especially a timer interrupt when a job is created or terminated There are two major classes of scheduling systems in preemptive systems, the scheduler can interrupt a job and force a context switch in non-preemptive systems, the scheduler waits for the running job to explicitly (voluntarily) block

5 CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state 2. Switches from running to ready state 3. Switches from waiting to ready 4. Terminates Scheduling under 1 and 4 is nonpreemptive All other scheduling is preemptive

6 Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency – time it takes for the dispatcher to stop one process and start another running

7 Process Model Workload contains collection of jobs (processes)
Process alternates between CPU and I/O bursts CPU bound jobs: (e.g. HPC applications) I/O bound: (e.g. Interactive applications) I/O burst = process idle, switch to another “for free” Problem: don’t know job’s type before running Need job scheduling for each ready job Schedule each CPU burst Matrix Multiply emacs read() write()

8 Scheduling Goals Scheduling algorithms can have many different goals (which sometimes conflict) maximize CPU utilization maximize job throughput (#jobs/s) minimize job turnaround time (Tfinish – Tstart) minimize job waiting time (Avg(Twait): average time spent on wait queue) minimize response time (Avg(Tresp): average time spent on ready queue) Maximize resource utilization Keep expensive devices busy Minimize overhead Reduce number of context switches Maximize fairness All jobs get same amount of CPU over some time interval Goals may depend on type of system batch system: strive to maximize job throughput and minimize turnaround time interactive systems: minimize response time of interactive jobs (such as editors or web browsers)

9 Scheduler Non-goals Schedulers typically try to prevent starvation
starvation occurs when a process is prevented from making progress, because another process has a resource it needs A poor scheduling policy can cause starvation e.g., if a high-priority process always prevents a low-priority process from running on the CPU

10 First Come First Served (FCFS)
Simplest Scheduling algorithm First job that requests CPU is allocated CPU Nonpreemptive Advantage: Simple Implementation with FIFO queue Disadvantage: Response time depends on arrival order Unfair to later jobs (especially if the system has long jobs) Job A Job B Job C Time CPU Uniprogramming: Run job to completion Multiprogramming: Put job at back of queue when performing I/O

11 Convoy Effect Short running jobs stuck waiting for long jobs Problems
Example: 1 CPU bound job, 3 I/O bound jobs Problems Reduces utilization of I/O devices Hurts response time of short jobs A B C C A B C C CPU Idle A B C C Idle A B C C Disk Time

12 Shortest Job First Minimizes average response time
Job A Job B Job C Time CPU FCFS if simultaneous arrival Provably optimal (given no preemption) to reduce response time Short job improved more than long job is hurt Not practical: Cannot know burst lengths (I/O + CPU) Can only use past behavior to predict future behavior

13 Shortest Time to Completion First (STCF)
SJF with preemption New process arrives w/ short CPU burst Shorter than remaining time of current job Job Submission: A at time 0, B/C/D at time t A B D A C CPU t Time SJF without preemption A B D C CPU Time

14 Shortest Remaining Processing Time (SRPT)
STCF for batch workloads Used in distributed systems Provides maximum throughput (transactions/sec) Minor risk of starvation Very popular in web servers and similar systems

15 Round Robin (RR) Practical approach to support time-sharing Advantages
Run job for a time-slice and then go to back of queue Preempted if still running at end of time-slice Advantages Fair allocation of CPU across jobs Low average response time when job lengths vary widely Avoids worst case scenarios and starvation A B C A B C A B A CPU Time

16 Disadvantages of Round Robin
Poor average response time when job sizes are identical E.g. 10 jobs each require 10 time slices All complete after 100 time slices Even FCFS is better How large should the time slice be? Depends on the workload! Tradeoff between throughput and responsiveness Batch vs. interactive workloads

17 Priority based scheduling
Priorities assigned to each process Run highest priority job in system (that is ready) Round robin among equal priority levels Aside: How to parse priority numbers Is low high or is high high? (Depends on system) Static vs. Dynamic priorities Some jobs have static priority assignments (kernel threads) Others need to be dynamic (user applications) Should priorities change as a result of scheduling decisions?

18 Priority Discussion Advantages Disadvantages
Static priorities work well for real time systems guarantee jobs get serviced Known set of jobs, so can assign priorities (e.g. radio in a cellphone is high priority, browser is low priority) Dynamic priorities work well for general workloads can react to changes in programs and workloads Disadvantages Low priority jobs can starve How to choose priority of each job? Goal: Adjust priority of job to match CPU burst Approximate SCTF by giving short jobs high priority

19 Priority Example Mechanism: sort ready queue by priority
Higher priority is better Job Arrival CPU Burst Priority A 10 5 B 1 2 C 4 3 A B A C Time

20 Multi-level Queue Scheduling
Implement multiple ready queues based on job “type” interactive processes CPU-bound processes batch jobs system processes student programs Different queues may be scheduled using different algorithms Intra-queue CPU allocation is either strict or proportional Problem: Classifying jobs into queues is difficult A process may have CPU-bound phases as well as interactive ones

21 Multiple Priority Queues
System Processes Interactive Processes Batch Processes

22 Multi-level Feedback Queues
Implement multiple ready queues Different queues may be scheduled using different algorithms Just like multilevel queue scheduling, but assignments are not static Jobs move from queue to queue based on feedback Feedback = The behavior of the job, e.g. does it require the full quantum for computation, or does it perform frequent I/O ? Very general algorithm Need to select parameters for: Number of queues Scheduling algorithm within each queue When to upgrade and downgrade a job

23 Multilevel Feedback Queues
System Processes Interactive Processes Batch Processes Batch Processes

24 Solaris Schedulers Scheduling classes
Time sharing – dynamically alters priorities and timeslices – higher priority indicates lower timeslice, more responsive but less time to respond. Fixed priority – priorities don’t change, good for real time. Is preemptive Fair share – doesn’t assign priority, but shares CPU equally among processes at this level Preemption: will preempt lower priority thread when higher becomes able to run Table driven MLFQ. Priority 0 is lowest, priority 59 is highest If quantum expires, priority is lowered If wake up from sleep / IO, priority gets a boost If waits too long without executing, gets priority boost

25 Real world scheduling Current schedulers exhibit combinations of above approaches Include priorities, round robin queues, queue reordering, and much more There is no single good algorithm Nor is there a way to even measure “goodness” Most schedulers designed based on heuristics and best guesses of potential workloads Linux has a lot of complexity to detect batch vs. interactive processes (can change during execution) Many times a scheduler will work great 99% of the time but completely fall over for 1% of workloads


Download ppt "Scheduling Adapted from:"

Similar presentations


Ads by Google