CS 423 Operating System Design: Scheduling Professor Adam Bates - - PowerPoint PPT Presentation

cs 423 operating system design scheduling
SMART_READER_LITE
LIVE PREVIEW

CS 423 Operating System Design: Scheduling Professor Adam Bates - - PowerPoint PPT Presentation

CS 423 Operating System Design: Scheduling Professor Adam Bates Spring 2017 CS 423: Operating Systems Design Goals for Today Learning Objective: Introduce goals, definitions, and policies related to uniprocessor and multiprocessor


slide-1
SLIDE 1

CS 423: Operating Systems Design

Professor Adam Bates Spring 2017

CS 423
 Operating System Design: Scheduling

slide-2
SLIDE 2

CS 423: Operating Systems Design 2

Goals for Today

Reminder: Please put away devices at the start of class

  • Learning Objective:
  • Introduce goals, definitions, and policies related to

uniprocessor and multiprocessor scheduling

  • Reason about advantages and disadvantages of

different foundational scheduling algorithms

  • Announcements, etc:
  • MP1 is is out! Due Feb 19
slide-3
SLIDE 3

CS 423: Operating Systems Design

What Are Scheduling Goals?

3

  • What are the goals of a scheduler?
  • Scheduling Goals:

■ Generate illusion of concurrency ■ Maximize resource utilization (e.g., mix CPU and

I/O bound processes appropriately)

■ Meet needs of both I/O-bound and CPU-bound

processes

■ Give I/O-bound processes better interactive response ■ Do not starve CPU-bound processes

■ Support Real-Time (RT) applications

slide-4
SLIDE 4

CS 423: Operating Systems Design

Definitions

4

  • Task/Job
  • Something that needs CPU time: a thread associated with a process or

with the kernel…

  • … a user request, e.g., mouse click, web request, shell command, …
  • Latency/response time
  • How long does a task take to complete?
  • Throughput
  • How many tasks can be done per unit of time?
slide-5
SLIDE 5

CS 423: Operating Systems Design

Definitions

5

  • Overhead
  • How much extra work is done by the scheduler?
  • Fairness
  • How equal is the performance received by different users?
  • Predictability
  • How consistent is the performance over time?
  • Starvation
  • A task ‘never’ receives the resources it needs to complete
  • Not very fair : - (
slide-6
SLIDE 6

CS 423: Operating Systems Design

Definitions

6

  • Workload
  • Set of tasks for system to perform
  • Work-conserving
  • Resource is used whenever there is a task to run
  • For non-preemptive schedulers, work-conserving is not always better
slide-7
SLIDE 7

CS 423: Operating Systems Design 7

■ Non-preemptive scheduling:

■ The running process keeps the CPU until it voluntarily

gives up the CPU

■ process exits ■ switches to blocked state ■ 1 and 4 only (no 3)

■ Preemptive scheduling:

■ The running process can be interrupted and must release

the CPU (can be forced to give up CPU)

Running Terminated Ready Blocked 1 4 3

Definitions

slide-8
SLIDE 8

CS 423: Operating Systems Design

Definitions

8

  • Scheduling algorithm
  • takes a workload as input
  • decides which tasks to do first
  • Performance metric (throughput, latency) as output
  • Only preemptive, work-conserving schedulers to be considered
slide-9
SLIDE 9

CS 423: Operating Systems Design 9

  • Schedule tasks in the order they arrive
  • Continue running them until they complete or give up the processor
  • Example: memcached
  • Facebook cache of friend lists, …
  • On what workloads would FIFO be particularly bad?

First In First Out (FIFO)

slide-10
SLIDE 10

CS 423: Operating Systems Design 10

  • Schedule tasks in the order they arrive
  • Continue running them until they complete or give up the processor
  • Example: memcached
  • Facebook cache of friend lists, …
  • On what workloads would FIFO be particularly bad?

First In First Out (FIFO)

slide-11
SLIDE 11

CS 423: Operating Systems Design 11

  • Always do the task that has the shortest remaining

amount of work to do

  • Often called Shortest Remaining Time First (SRTF)
  • Suppose we have five tasks arrive one right after each
  • ther, but the first one is much longer than the others
  • Which completes first in FIFO? Next?
  • Which completes first in SJF? Next?

Shortest Job First (SJF)

slide-12
SLIDE 12

CS 423: Operating Systems Design

FIFO vs. SJF

12 (1) Tasks (3) (2) (5) (4)

FIFO

(1) Tasks (3) (2) (5) (4)

SJF Time

slide-13
SLIDE 13

CS 423: Operating Systems Design 13

  • Each task gets resource for a fixed period of time

(time quantum)

  • If task doesn’t complete, it goes back in line
  • Performance changes based on time quantum size
  • What if time quantum is too short?
  • One instruction?
  • What if time quantum is too long?
  • Infinite?

Round Robin (RR)

slide-14
SLIDE 14

CS 423: Operating Systems Design

Round Robin

14 (1) Tasks (3) (2) (5) (4)

Round Robin (100 ms time slice) Time

Rest of Task 1

slide-15
SLIDE 15

CS 423: Operating Systems Design

Round Robin

15 (1) Tasks (3) (2) (5) (4)

Round Robin (100 ms time slice) Time

Rest of Task 1 (1) Tasks (3) (2) (5) (4)

FIFO

slide-16
SLIDE 16

CS 423: Operating Systems Design

Round Robin

16 (1) Tasks (3) (2) (5) (4)

Round Robin (1 ms time slice)

Rest of Task 1

slide-17
SLIDE 17

CS 423: Operating Systems Design

Round Robin

17 (1) Tasks (3) (2) (5) (4)

Round Robin (1 ms time slice)

Rest of Task 1 (1) Tasks (3) (2) (5) (4)

SJF Time

slide-18
SLIDE 18

CS 423: Operating Systems Design

Scheduling

18

Basic scheduling algorithms

FIFO (FCFS)

Shortest job first

Round Robin

slide-19
SLIDE 19

CS 423: Operating Systems Design

Scheduling

19

Basic scheduling algorithms

FIFO (FCFS)

Shortest job first

Round Robin

What is an optimal algorithm in the sense

  • f maximizing the number of jobs finished

(i.e., minimizing average response time)?

slide-20
SLIDE 20

CS 423: Operating Systems Design

FIFO vs. SJF

20 (1) Tasks (3) (2) (5) (4)

FIFO

(1) Tasks (3) (2) (5) (4)

SJF Time

wait time for 2, 3, 4, 5 is BIG! wait time for 2, 3, 4, 5 is SMALL!

slide-21
SLIDE 21

CS 423: Operating Systems Design

Scheduling

21

Basic scheduling algorithms

FIFO (FCFS)

Shortest job first

Round Robin

Assuming zero-cost to time slicing, is Round Robin always better than FIFO?

slide-22
SLIDE 22

CS 423: Operating Systems Design

RR v. FIFO (fixed size tasks)

22 (1) Tasks (3) (2) (5) (4)

FIFO and SJF

(1) Tasks (3) (2) (5) (4)

Round Robin (1 ms time slice) Time

slide-23
SLIDE 23

CS 423: Operating Systems Design

Starvation, Sample Bias

23

  • Suppose you want to compare two scheduling

algorithms

  • Create some infinite sequence of arriving tasks
  • Start measuring
  • Stop at some point
  • Compute average response time as the average for completed tasks

between start and stop

  • Is this valid or invalid?
slide-24
SLIDE 24

CS 423: Operating Systems Design

Sample Bias Solutions

24

  • Measure for long enough that # of completed tasks >>

# of uncompleted tasks

  • For both systems!
  • Start and stop system in idle periods
  • Idle period: no work to do
  • If algorithms are work-conserving, both will complete the same tasks
slide-25
SLIDE 25

CS 423: Operating Systems Design

Round Robin = Fairness?

25

Is Round Robin the fairest possible algorithm? What is fair?

  • FIFO?
  • Equal share of the CPU?
  • What if some tasks don’t need their full share?
  • Minimize worst case divergence?
  • Time task would take if no one else was running
  • Time task takes under scheduling algorithm
slide-26
SLIDE 26

CS 423: Operating Systems Design

Mixed Workloads??

26

I/O Bound Tasks CPU Bound CPU Bound

Time

Issues I/O Request I/O Completes Issues I/O Request I/O Completes

slide-27
SLIDE 27

CS 423: Operating Systems Design

Max-Min Fairness

27

  • How do we balance a mixture of repeating tasks?
  • Some I/O bound, need only a little CPU
  • Some compute bound, can use as much CPU as they are assigned
  • One approach: maximize the minimum allocation given

to a task

  • If any task needs less than an equal share, schedule the smallest of

these first

  • Split the remaining time using max-min
  • If all remaining tasks need at least equal share, split evenly
slide-28
SLIDE 28

CS 423: Operating Systems Design 28

  • Goals:
  • Responsiveness
  • Low overhead
  • Starvation freedom
  • Some tasks are high/low priority
  • Fairness (among equal priority tasks)
  • Not perfect at any of them!
  • Used in Linux (and probably Windows, MacOS)

Multi-Level Feedback Queue

slide-29
SLIDE 29

CS 423: Operating Systems Design 29

  • Set of Round Robin queues
  • Each queue has a separate priority
  • High priority queues have short time slices
  • Low priority queues have long time slices
  • Scheduler picks first thread in highest priority queue
  • Tasks start in highest priority queue
  • If time slice expires, task drops one level

Multi-Level Feedback Queue

slide-30
SLIDE 30

CS 423: Operating Systems Design 30

Multi-Level Feedback Queue

Priority 1 Time Slice (ms)

Time Slice Expiration New or I/O Bound Task

2 4 3 80 40 20 10 Round Robin Queues

slide-31
SLIDE 31

CS 423: Operating Systems Design

Summary

31

  • FIFO is simple and minimizes overhead.
  • If tasks are variable in size, then FIFO can have very

poor average response time.

  • If tasks are equal in size, FIFO is optimal in terms of

average response time.

  • Considering only the processor, SJF is optimal in terms
  • f average response time.
  • SJF is pessimal in terms of variance in response time.
slide-32
SLIDE 32

CS 423: Operating Systems Design

Summary

32

  • If tasks are variable in size, Round Robin approximates

SJF.

  • If tasks are equal in size, Round Robin will have very

poor average response time.

  • Tasks that intermix processor and I/O benefit from SJF

and can do poorly under Round Robin.

slide-33
SLIDE 33

CS 423: Operating Systems Design

Summary

33

  • Max-Min fairness can improve response time for I/O-

bound tasks.

  • Round Robin and Max-Min fairness both avoid

starvation.

  • By manipulating the assignment of tasks to priority

queues, an MFQ scheduler can achieve a balance between responsiveness, low overhead, and fairness.