Docsity

Operating Systems: Scheduling with I/O - Lecture Notes, Lecture notes of Operating Systems

Toggle sidebar
bg1
TCSS 422 A – Spring 2021
School of Engineering and Technology
4/15/2021
L6.1
Slides by Wes J. Lloyd
April 15, 2021 TCSS422: Operating Systems [Spring 2021]
School of Engineering and Technology, University of Washington - Tacoma
Intro to Sche dulers I I,
Pr opo rt ion al Sha re
Sc hed ul ers
Wes J. Lloyd
Sch ool of Engi neer ing and Tech nolo gy
Uni vers ity of Wa shin gton - Tac oma
TCSS 422: OPERATING SYSTEMS
Qu esti ons f rom 4/1 3
As sign ment 0
C T utor ial - Poi nter s, S tri ngs, Exec in C
Cha pte r 7: S ched uli ng I ntro duct ion
RR s chedu ler
Cha pte r 8: Mult i-le vel Feed bac k Que ue
MLF Q Sche duler
Job Star vatio n
Gam ing the Sch eduler
Exa mples
Cha pte r 9: Prop ort iona l Sh are Sche dul ers
April 15, 2021
TCSS422: Operating Systems [Spring 2021]
School of Engineering and Technology, University of Washington - Tacoma
L6.2
OB JECTI VES – 4/15
Dai ly Feed back Qu iz i n C anva s – Avail abl e Af ter Eac h Cl ass
Ext ra cred it avai labl e fo r c omp leti ng s urv eys ON TIM E
Tues day sur vey s: d ue b y ~ Wed @ 1 1:5 9p
Thu rsd ay s urv eys : du e ~ Mon @ 1 1:59 p
April 15, 2021
TCSS422: Computer Operating Systems [Spring 2021]
School of Engineering and Technology, University of Washington -Tacoma
L6.3
ONLIN E DAILY F EEDBACK S URVEY
April 15, 2021 TCSS422: Computer Operating Systems [Spring 2021]
School of Engineering and Technology, University of Washington -Tacoma L6.4
Ple ase cla ssi fy y our per spe ctiv e on ma teri al c ove red in t oday ’s
cla ss (52 res pon dent s):
1-m ost ly r evi ew, 5 -eq ual new /rev iew , 10- mos tly new
Ave rag e – 7.27 ( - p rev ious 6.9 1)
Ple ase rat e th e p ace of toda y’s cla ss:
1-s low , 5- just ri ght, 10 -fas t
Ave rag e – 5. 52 ( - p rev ious 5.6 5)
April 15, 2021
TCSS422: Computer Operating Systems [Spring 2021]
School of Engineering and Technology, University of Washington -Tacoma
L6.5
MATERIAL / PACE
Wh at i s th e p urp ose of c alc ula tin g tu rnar oun d ti me a nd
re spon se t ime ?
Calc ulat ing t hese metr ics he lps u s co mpar e diff eren t CPU sche duli ng
algo rith ms re lati ve to s che dulin g a sp ecif ic se t of jobs
The idea is t o fin d the best sch eduli ng al gori thm fo r a s et of job s
It i s ha rd to find a sc hedu ling a lgor ithm that is go od fo r AL L jobs
Do pro gra ms u sua lly out put a so rt of " pr ojec ted t im e to
co mple tio n" t o fa cil ita te ea sie r s ort ing for fai rne ss?
No, ofte n li ttle i nfor matio n is avail able to sug gest prog ram r unti me
Fair ness is fr eque ntly evalu ated a fter -the -fact
The perc enta ge exe cutio n tim e may be gi ven : A=5 2% B=3 2% C= 16%
Or w e mu st ca lcul ate th e % t ime: A=10 m 24s B =6m 24s C= 3m 1 2s
Is it com mon pra ctic e to br eak dow n di ffe ren t me asur es o f
fa irn ess f or res our ce al loc ati on w hen des ign ing p ro gram s?
No. We c alcu late f airn ess to com pare opera ting syste m alg orit hms
use d to s hare comp utin g reso urce s (CPU , di sk, n etwo rk)
April 15, 2021
TCSS422: Operating Systems [Spring 2021]
School of Engineering and Technology, University of Washington - Tacoma
L6.6
FE EDBAC K
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Operating Systems: Scheduling with I/O - Lecture Notes and more Lecture notes Operating Systems in PDF only on Docsity!

School of Engineering and Technology

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma

Intro to Schedulers II,

Proportional Share

Schedulers

Wes J. Lloyd

School of Engineering and Technology
University of Washington - Tacoma

TCSS 422: OPERATING SYSTEMS

 Questions from 4/
 Assignment 0
 C Tutorial - Pointers, Strings, Exec in C
 Chapter 7: Scheduling Introduction

 RR scheduler

 Chapter 8: Multi-level Feedback Queue

 MLFQ Scheduler  Job Starvation  Gaming the Scheduler  Examples

 Chapter 9: Proportional Share Schedulers

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

OBJECTIVES – 4/

 Daily Feedback Quiz in Canvas – Available After Each Class  Extra credit available for completing surveys ON TI ME  Tuesday surveys: due by ~ Wed @ 11:59p  Thursday surveys: due ~ Mon @ 11:59p April 15, 2021 TCSS422: Computer Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

ONLINE DAILY FEEDBACK SURVEY

April 15, 2021 TCSS422: Computer Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.  Please classify your perspective on material covered in today’s class (52 respondents):  1-mostly review, 5-equal new/review, 10-mostly new  Average – 7.27 ( - previous 6 .91)  Please rate the pace of today’s class:  1-slow, 5-just right, 10-fast  Average – 5 .52 ( - previous 5 .65) April 15, 2021 TCSS422: Computer Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

MATERIAL / PACE

 What is the purpose of calculating tu rnaround time and response time?  Calculating these metrics helps us compare different CPU scheduling algorithms relative to scheduling a specific set of jobs  The idea is to find the best scheduling algorithm for a set of jobs  It is hard to find a scheduling algorithm that is good for ALL jobs  Do p rograms usually ou tput a s or t of "p rojected time to completion" to facilitate easier s or ting for fairness?  No, often little information is available to suggest program runtime  Fairness is frequently evaluated after-the-fact  The percentage execution time may be given: A=52% B=32% C=16%  Or we must calculate the % time: A=10m 24s B=6m 24s C=3m 12s  Is it common p ractice to break down different measures of fairness for resource allocation when designing pr ograms?  No. used to share computing resources (CPU, disk, network) We calculate fairness to compare operating system algorithms April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

FEEDBACK

School of Engineering and Technology

 What exactly does the fairness number represent?
Best case is 1 and worst case is 1/n.
Does that mean the share of the CPU?

 No, the share of the resource is the Xi values we use to calculate the Jain’s fairness index score.  Perfect fairness always equals 1. This is when a resource is shared equally among a set of processes/users  Low values are always bad. If the number of processes is small, the value may not be that small

 Jain’s fairness index: the math

 Consider JFI for A=52% B=32% C=16% April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

FEEDBACK - 2

 If SJF (Shor test job fir st) scheduler is not realistic, why is it s till being used?  The textbook introduces some “pedagogical schedulers”  FIFO and Round-robin are actually legitimate schedulers  SJF and STCF require knowing how long a job will run in advance and this information is often not known  Each successive scheduler introduces new features and capabilities  We are building towards schedulers full-featured schedulers  Linux, for example, does not predict job runtime, but it does TRACK cumulative job runtime in making future scheduling decisions  How would the implementation of a s cheduler look? Both at a higher and lower level.  Round-robin/FIFO can be simple. Involve a queue and job pointer April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

FEEDBACK - 3

 What are the advantages of using lower-level APIs such as
open() compared to the specialized versions with
additional features like fopen()? Is this similar to the
control tradeoff? Introducing unnecessary overhead and
the like?

 fopen() and other functions like it are provided largely out of convenience for developers  Specialized wrappers such as fopen() abstract additional functionality to make it more easily accessible for programmers

 With the use of standard out and standard error when
EXEC with file redirection, I'm still not sure about the
steps from L4.

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

FEEDBACK - 2

 Can we go over trap tables in a little more detail?  TRAP TABLE: The x86 processor uses a table known as the interrupt descriptor table (IDT) to determine how to transfer control when a trap occurs. The x86 allows up to 256 different interrupt or exception entry points into the kernel, each with a different interrupt vector.  TRAP HANDLERS: Trap handlers are OS kernel functions that are pointed to by the trap table. These are “event handlers” that respond to various traps. April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

FEEDBACK - 4

 Questions from 4/
 Assignment 0
 C Tutorial - Pointers, Strings, Exec in C
 Chapter 7: Scheduling Introduction

 RR scheduler

 Chapter 8: Multi-level Feedback Queue

 MLFQ Scheduler  Job Starvation  Gaming the Scheduler  Examples

 Chapter 9: Proportional Share Schedulers

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

OBJECTIVES – 4/

 Questions from 4/
 Assignment 0
 C Tutorial - Pointers, Strings, Exec in C
 Chapter 7: Scheduling Introduction

 RR scheduler

 Chapter 8: Multi-level Feedback Queue

 MLFQ Scheduler  Job Starvation  Gaming the Scheduler  Examples

 Chapter 9: Proportional Share Schedulers

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

OBJECTIVES – 4/

School of Engineering and Technology

 When a job initiates an I/O request
 A is blocked, waits for I/O to compute, frees CPU
 STCF scheduler assigns B to CPU
 When I/O completes  raise interrupt
 Unblock A, STCF goes back to executing A: (10ms sub-job)

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

SCHEDULING WITH I/O - 2

Cpu utilization = 100/100=100% April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

 Which scheduler, this far, best addresses fairness
and average response time of jobs?
 First In – First Out (FIFO)
 Shortest Job First (SJF)
 Shortest Time to Completion First (STCF)
 Round Robin (RR)
 None of the Above
 All of the Above

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

QUESTION: SCHEDULING FAIRNESS

 Consider Three jobs (A, B, C) that require:
timeA=400ms, timeB=100ms, and timeC=200ms
 All jobs arrive at time=0 in the sequence of A B C.
 Draw a scheduling graph to help compute the
average response time (ART) and
average turnaround time (ATT) scheduling metrics for the
FIFO scheduler.

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

SCHEDULING METRICS

A B C 0 400 500 700 Example: April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.23 April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

School of Engineering and Technology

 Consider Three jobs (A, B, C) that require:
timeA=400ms, timeB=100ms, and timeC=200ms
 All jobs arrive at time=0 in the sequence of A B C.
 Draw a scheduling graph to help compute the
average response time (ART) and
average turnaround time (ATT) scheduling metrics for the
SJF scheduler.

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

SCHEDULING METRICS

B C A 0 100 300 700 Example: April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6. April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

 Questions from 4/
 Assignment 0
 C Tutorial - Pointers, Strings, Exec in C
 Chapter 7: Scheduling Introduction

 RR scheduler

 Chapter 8: Multi-level Feedback Queue

 MLFQ Scheduler  Job Starvation  Gaming the Scheduler  Examples

 Chapter 9: Proportional Share Schedulers

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

OBJECTIVES – 4/

CHAPTER 8 – MULTI-LEVEL FEEDBACK QUEUE (MLFQ) SCHEDULER April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

 Objectives:
 Improve turnaround time:
Run shorter jobs first
 Minimize response time:
Important for interactive jobs (UI)
 Achieve without a priori knowledge of job length

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

MULTI-LEVEL FEEDBACK QUEUE

School of Engineering and Technology

 Questions from 4/
 Assignment 0
 C Tutorial - Pointers, Strings, Exec in C
 Chapter 7: Scheduling Introduction

 RR scheduler

 Chapter 8: Multi-level Feedback Queue

 MLFQ Scheduler  Job Starvation  Gaming the Scheduler  Examples

 Chapter 9: Proportional Share Schedulers

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

OBJECTIVES – 4/

 Starvation

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

MLFQ: ISSUES

 Questions from 4/
 Assignment 0
 C Tutorial - Pointers, Strings, Exec in C
 Chapter 7: Scheduling Introduction

 RR scheduler

 Chapter 8: Multi-level Feedback Queue

 MLFQ Scheduler  Job Starvation  Gaming the Scheduler  Examples

 Chapter 9: Proportional Share Schedulers

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

OBJECTIVES – 4/

 Gaming the scheduler
 Issue I/O operation at 99% completion of the time slice
 Keeps job priority fixed – never lowered
 Job behavioral change
 CPU/batch process becomes an interactive process

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

MLFQ: ISSUES - 2

Priority becomes stuck

 Priority Boost
 Reset all jobs to topmost queue after some time interval S

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

RESPONDING TO BEHAVIOR CHANGE

Starvation

 With priority boost
 Prevents starvation

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

RESPONDING TO BEHAVIOR CHANGE - 2

With

School of Engineering and Technology

 Without priority boost:
 Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t).
 Rule 2: If Priority(A) = Priority(B), A & B run in RR.
 KEY: If time quantum of a higher queue is filled,
then we don’t run any jobs in lower priority queues!!!

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

KEY TO UNDERSTANDING MLFQ – PB

 Consider 3 queues:  Q2 – HIGH PRIORIT Y – Time Quantum 10ms  Q1 – MEDIUM PRIORIT Y – Time Quantum 20 ms  Q0 – LOW PRIORIT Y – Time Quantum 40 ms  Job A: 200ms no I/O  Job B: 5ms then I/O  Job C: 5ms then I/O  Q2 fills up, starves Q1 & Q  A makes no progress April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

STARVATION EXAMPLE

Starvation  Improved time accounting:  Track total job execution time in the queue  Each job receives a fixed time allotment  When allotment is exhausted, job priority is lowered April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

PREVENTING GAMING

 Consider the tradeoffs:

 How many queues?  What is a good time slice?  How often should we “Boost” priority of jobs?  What about different time slices to different queues? April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

MLFQ: TUNING

 Oracle Solaris MLFQ implementation
 60 Queues 
w/ slowly increasing time slice (high to low priority)
 Provides sys admins with set of editable table(s)
 Supports adjusting time slices, boost intervals, priority
changes, etc.
 Advice
 Provide OS with hints about the process
 Nice command  Linux

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

PRACTICAL EXAMPLE

 The refined set of MLFQ rules:
 Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t).
 Rule 2: If Priority(A) = Priority(B), A & B run in RR.
 Rule 3: When a job enters the system, it is placed at the
highest priority.
 Rule 4: Once a job uses up its time allotment at a given
level (regardless of how many times it has given up the
CPU), its priority is reduced(i.e., it moves down on queue).
 Rule 5: After some time period S, move all the jobs in the
system to the topmost queue.

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

MLFQ RULE SUMMARY

School of Engineering and Technology

 Also called fair-share scheduler
or lottery scheduler
 Guarantees each job receives some percentage of CPU
time based on share of “tickets”
 Each job receives an allotment of tickets
 % of tickets corresponds to potential share of a resource
 Can conceptually schedule any resource this way

 CPU, disk I/O, memory April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

PROPORTIONAL SHARE SCHEDULER

 Simple implementation
 Just need a random number generator

 Picks the winning ticket

 Maintain a data structure of jobs and tickets (list)
 Traverse list to find the owner of the ticket
 Consider sorting the list for speed

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

LOTTERY SCHEDULER

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

LOTTERY SCHEDULER IMPLEMENTATION

12 //int counter: counter used= 0 ; to track if we’ve found the winner yet (^34) // winner: use some call to a random number generator to 56 //int get winner a value, = getrandom( between 0 0 and, totaltickets); the total # of tickets (^78) // current: use this to walk through the list of jobs 910 node_t *current = head; 1112 //while loop (current) until the { sum of ticket values is > the winner 1314 counterif (counter = counter > winner) + current->tickets; (^1516) current = breakcurrent->next;; // found the winner 1718 }// ’current’ is the winner: schedule it...

 Ticket currency / exchange
 User allocates tickets in any desired way
 OS converts user currency into global currency
 Example:
 There are 200 global tickets assigned by the OS

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

TICKET MECHANISMS

 Ticket transfer
 Temporarily hand off tickets to another process
 Ticket inflation
 Process can temporarily raise or lower the number of
tickets it owns
 If a process needs more CPU time, it can boost tickets.

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

TICKET MECHANISMS - 2

 Scheduler picks a winning ticket
 Load the job with the winning ticket and run it
 Example:
 Given 100 tickets in the pool

 Job A has 75 tickets: 0 - 74  Job B has 25 tickets: 75 – 99

 But what do we know about probability of a coin flip?

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

LOTTERY SCHEDULING

Scheduled job:

School of Engineering and Technology

 Equality of distribution (fairness) requires a lot of flips! April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

COIN FLIPPING

Similarly, Lottery scheduling requires lots of “rounds” to achieve fairness. April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

LOTTERY FAIRNESS

 With two jobs  Each with the same number of tickets (t=100) When the job length is not very long, average unfairness can be quite severe.

 What is the best approach to assign tickets to jobs?
 Typical approach is to assume users know best
 Users are provided with tickets, which they allocate as
desired
 How should the OS automatically distribute tickets upon
job arrival?
 What do we know about incoming jobs a priori?
 Ticket assignment is really an open problem…

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

LOTTERY SCHEDULING CHALLENGES

 Addresses statistical probability issues with
lottery scheduling
 Instead of guessing a random number to select a
job, simply count…

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

STRIDE SCHEDULER

 Jobs have a “stride” value

 A stride value describes the counter pace when the job should give up the CPU  Stride value is inverse in proportion to the job’s number of tickets (more tickets = smaller stride)

 Total system tickets = 10,

 Job A has 100 tickets  Astride = 10000/100 = 100 stride  Job B has 50 tickets  Bstride = 10000/50 = 200 stride  Job C has 250 tickets  Cstride = 10000/250 = 40 stride

 Stride scheduler tracks “pass” values for each job (A, B, C)

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

STRIDE SCHEDULER - 2

 Basic algorithm:
1. Stride scheduler picks job with the lowest pass value
2. Scheduler increments job’s pass value by its stride and
starts running
3. Stride scheduler increments a counter
4. When counter exceeds pass value of current job, pick a
new job (go to 1)
 KEY: When the counter reaches a job’s “PASS” value,
the scheduler passes on to the next job…

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

STRIDE SCHEDULER - 3

School of Engineering and Technology

 Every thread/process has a scheduling class (policy):  Normal classes: SCHED_OTHER (TS), SCHED_IDLE, SCHED_BATCH  TS = Time Sharing  Real-time classes: SCHED_FIFO (FF), SCHED_RR (RR)  How to show scheduling class and priority:

 #class
ps –elfc
 #priority (nice value)
ps ax -o pid,ni,cls,pri,cmd

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

COMPLETELY FAIR SCHEDULER - 2

 Linux ≥ 2.6.23: Completely Fair Scheduler (CFS)  Linux < 2.6.23: O(1) scheduler  Linux maintains simple counter (vruntime) to track how long each thread/process has run  CFS picks process with lowest vruntime to run next  CFS adjusts timeslice based on # of proc waiting for the CPU  Kernel parameters that specify CFS behavior: April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

COMPLETELY FAIR SCHEDULER - 3

$ sudo sysctl kernel.sched_latency_ns kernel.sched_latency_ns = 24000000 $ sudo sysctl kernel.sched_min_granularity_ns kernel.sched_min_granularity_ns = 3000000 $ sudo sysctl kernel.sched_wakeup_granularity_ns kernel.sched_wakeup_granularity_ns = 4000000  Sched_min_granularity_ns (3ms)  Time slice for a process: busy system (w/ full runqueue)  If system has idle capacity, time slice exceed the min as long as dif ference in vruntime between running process and process with lowest vruntime is less than sched_wakeup_granularity_ns (4ms)  Scheduling time period is: total cycle time for iterating through a set of processes where each is allowed to run (like round robin)  Example: sched_latency_ns (24ms) if (proc in runqueue < sched_latency_ns/sched_min_granularity) or sched_min_granularity * number of processes in runqueue R e f : h t t p s : / / w w w. s y s t u t o r i a l s. c o m / s c h e d _ m i n _ g r a n u l a r i t y _ n s - s c h e d _ l a t e n c y _ n s - c f s - a f f e c t - t i m e s l i c e - p r o c e s s e s / April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

COMPLETELY FAIR SCHEDULER - 4

 HIGH sched_min_granularity_ns (timeslice) sched_latency_ns sched_wakeup_granularity_ns reduced context switching  less overhead poor near-term fairness  LOW sched_min_granularity_ns (timeslice) sched_latency_ns sched_wakreup_granularity_ns increased context switching  more overhead better near-term fairness April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

CFS TRADEOFF

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

COMPLETELY FAIR SCHEDULER - 5

 Runqueues are stored using a linux red-black tree
 Self balancing binary tree - nodes indexed by vruntime
 Leftmost node has lowest
vruntime (approx execution time)
 Walking tree to find left
most node has very low
big O complexity:

~O(log N) for N nodes

 Completed
processes removed
 Time slice: Linux “Nice value”
 Nice predates the CFS scheduler
 Top shows nice values
 Process command (nice & priority):
ps ax -o pid,ni,cmd,%cpu, pri
 Nice Values: from -20 to 19
 Lower is higher priority, default is 0
 Vruntime is a weighted time measurement
 Priority weights the calculation of vruntime within a
runqueue to give high priority jobs a boost.

 Influences job’s position in rb-tree April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

CFS: JOB PRIORIT Y

School of Engineering and Technology

 CFS tracks cumulative job run time in vruntime variable  The task on a given runqueue with the lowest vruntime is scheduled next  struct sched_entity contains vruntime parameter  Describes process execution time in nanoseconds  Value is not pure runtime, is weighted based on job priority  Perfect scheduler  achieve equal vruntime for all processes of same priority  Sleeping jobs: upon return reset vruntime to lowest value in system  Jobs with frequent short sleep SUFFER !!

 Key takeaway:
identifying the next job to schedule is really fast!

April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

COMPLETELY FAIR SCHEDULER - 6

 More information:  Man page: “man sched” : Describes Linux scheduling API  http://manpages.ubuntu.com/manpages/bionic/man7/sched.7.html  https://www.kernel.org/doc/Documentation/scheduler/sched- design-CFS.txt  https://en.wikipedia.org/wiki/Completely_Fair_Scheduler  See paper: The Linux Scheduler – a Decade of Wasted Cores  http://www.ece.ubc.ca/~sasha/papers/eurosys16-final29.pdf April 15, 2021 TCSS422: Operating Systems [Spring 2021] School of Engineering and Technology, University of Washington - Tacoma L6.

COMPLETELY FAIR SCHEDULER - 7

QUESTIONS QUESTIONS

TCSS 422

OFFICE HOURS

PLEASE SAY HELLO

OFFICE HOURS

HAVE STEPPED OUT

WILL RETURN

SHORTLY