0% found this document useful (0 votes)
33 views3 pages

Understanding Linux CFS Scheduler

Uploaded by

Yongqi Zhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Understanding Linux CFS Scheduler

Uploaded by

Yongqi Zhu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Linux Scheduler CFS

lottery scheduling
concept
use tickets to represent CPU share, use random, walk through the list until total
count > random number

shortcome:

can’t deliver the exact right properties in short run time

stride scheduling
concept
largen
dividek =​ ​

ticketsk ​

curr = remove_min(queue); // pick client with min pass


schedule(curr); // run for quantum
curr->pass += curr->stride; // update pass using stride
insert(queue, curr); // return curr to queue

shortcome

Linux Scheduler CFS 1


can’t handle mid-in task

CFS
content
choose lowest vruntime task to run

sched_latency
switch_time = ​

nprocess

to prevent context switching too offen, switch_time has a minimal value

with priority
weight(nice) table

static const int prio_to_weight[40] = {


/* -20 */ 88761, 71755, 56483, 46273, 36291,
/* -15 */ 29154, 23254, 18705, 14949, 11916,
/* -10 */ 9548, 7620, 6100, 4904, 3906,
/* -5 */ 3121, 2501, 1991, 1586, 1277,
/* 0 */ 1024, 820, 655, 526, 423,
/* 5 */ 335, 272, 215, 172, 137,
/* 10 */ 110, 87, 70, 56, 45,
/* 15 */ 36, 29, 23, 18, 15,
};

weightk
time_slicen = ∗ sched_latency
∑n−1
​ ​

i=0weighti
​ ​

weight0
vruntimei = vruntimei + ∗ runtimei

​ ​ ​ ​

weighti ​

work with i/o

Linux Scheduler CFS 2


job which executes i/o operation will get lower vruntime than others, to prevent
these jobs monopolize the CPU, set job’s vruntine to lowest time in current tree
when waking up

implementation details
use red-black tree to insert job at logarithmic time

Linux Scheduler CFS 3

You might also like