1 outline for today objectives: –linux scheduler –lottery scheduling
TRANSCRIPT
![Page 1: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/1.jpg)
1
Outline for Today• Objectives:
– Linux scheduler– Lottery scheduling
![Page 2: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/2.jpg)
2
Linux Scheduling Policy
• Runnable process with highest priority and timeslice remaining runs (SCHED_OTHER policy)– Dynamically calculated priority
• Starts with nice value• Bonus or penalty reflecting whether I/O or compute
bound by tracking sleep time vs. runnable time: – sleep_avg – accumulated during sleep up to
MAX_SLEEP_AVG (10 ms default)– decremented by timer tick while running
![Page 3: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/3.jpg)
3
Linux Scheduling Policy– Dynamically calculated timeslice
• The higher the dynamic priority, the longer the timeslice:
– Recalculated every round when “expired” and “active” swap
– Exceptions for expired interactive • Go back on active unless there are starving expired tasks
Low priorityless interactive
High prioritymore interactive
10ms 150ms 300ms
![Page 4: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/4.jpg)
4
.
.
.
.
.
.
Runqueue for O(1) Scheduler
active
expired
priority array
priority array
.
.
.
.
.
.
priority queue
priority queue
priority queue
priority queue
Higher prioritymore I/O300ms
lower prioritymore CPU10ms
![Page 5: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/5.jpg)
5
.
.
.
.
.
.
Runqueue for O(1) Scheduler
active
expired
priority array
priority array
.
.
.
.
.
.
priority queue
priority queue
priority queue
priority queue
10
![Page 6: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/6.jpg)
6
.
.
.
.
.
.
Runqueue for O(1) Scheduler
active
expired
priority array
priority array
.
.
.
.
.
.
priority queue
priority queue
priority queue
priority queue
1
0
X
X
![Page 7: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/7.jpg)
7
Linux Real-time
• No guarantees• SCHED_FIFO
– Static priority, effectively higher than SCHED_OTHER processes*
– No timeslice – it runs until it blocks or yields voluntarily
– RR within same priority level
• SCHED_RR– As above but with a timeslice.
* Although their priority number ranges overlap
![Page 8: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/8.jpg)
8
Diversion: Synchronization
• Disable Interrupts
• Busywaiting solutions - spinlocks– execute a tight loop if critical section is busy– benefits from specialized atomic (read-mod-
write) instructions
• Blocking synchronization– sleep (enqueued on wait queue) while critical
section is busy.
![Page 9: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/9.jpg)
9
Support for SMP• Every processor has its
own private runqueue• Locking – spinlock
protects runqueue• Load balancing – pulls
tasks from busiest runqueue into mine.
• Affinity – cpus_allowed bitmask constrains a process to particular set of processors
• load_balance runs from schedule( ) when runqueue is empty or periodically esp. during idle.
• Prefers to pull processes from expired, not cache-hot, high priority, allowed by affinity
P P P P
Memory
$ $ $ $
Symmetric mp
![Page 10: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/10.jpg)
10
Lottery SchedulingWaldspurger and Weihl (OSDI 94)
![Page 11: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/11.jpg)
11
Claims
• Goal: responsive control over the relative rates of computation
• Claims:– Support for modular resource management– Generalizable to diverse resources– Efficient implementation of proportional-share
resource management: consumption rates of resources by active computations are proportional to relative shares allocated
![Page 12: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/12.jpg)
12
Basic Idea
• Resource rights are represented by lottery tickets– abstract, relative (vary dynamically wrt
contention), uniform (handle heterogeneity)– responsiveness: adjusting relative # tickets
gets immediately reflected in next lottery
• At allocation time: hold a lottery;Resource goes to the computation holding the winning ticket.
![Page 13: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/13.jpg)
13
Fairness
• Expected allocation is proportional to # tickets held - actual allocation becomes closer over time.
• Number of lotteries won by clientE[w] = n p where p = t/T
• Response time (# lotteriesto wait for first win)E[n] = 1/p
w # winst # ticketsT total # tickets n # lotteries
![Page 14: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/14.jpg)
14
Example List-based Lottery
10 2 5 1 2
T = 20
Random(0, 19) = 15
10 12 17Summing:
![Page 15: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/15.jpg)
15
Bells and Whistles
• Ticket transfers - objects that can be explicitly passed in messages– Can be used to solve priority inversions
• Ticket inflation– Create more - used among mutually trusting clients to
dynamically adjust ticket allocations
• Currencies - “local” control, exchange rates
• Compensation tickets - to maintain share
– use only f of quantum, ticket inflated by 1/f in next
![Page 16: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/16.jpg)
16
Kernel Objects
1000base
ticket
amount
currencyC_name
300
Backingtickets
Issued tickets
Activeamount
Currencyname
![Page 17: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/17.jpg)
17
base
alice bob
task1
task2
task3
thread2 thread3 thread4thread1
3000
200
500
100
100
2000base
1000base
200alice
200 task2
300task2
100task3
100bob100
alice
100task1
0
1 alice =5 base
1 task2=.4 alice =2 base
1 bob =20 base
![Page 18: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/18.jpg)
18
base
alice bob
task1
task2
task3
thread2 thread3 thread4thread1
3000
300
500
100
100
2000base
1000base
200alice
200 task2
300task2
100task3
100bob100
alice
100task1
100
1 alice =3.33 base
1 task2=.4 alice =1.33 base
1 bob =20 base
![Page 19: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/19.jpg)
19
Example List-based Lottery
10 task2 2bob 5 task3 1
base
2bob
T = 3000 base
Random(0, 2999) = 1500
![Page 20: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/20.jpg)
20
Compensation
• A holds 400 base, B holds 400 base
• A runs full 100msec quantum,B yields at 20msec
• B uses 1/5 allotted timeGets 400/(1/5) = 2000 base at each subsequent lottery for the rest of this quantum – a compensation ticket valued at 2000 - 400
![Page 21: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/21.jpg)
21
Ticket Transfer
• Synchronous RPC between client and server
• create ticket in client’s currency and send to server to fund it’s currency
• on reply, the transfer ticket is destroyed
![Page 22: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/22.jpg)
22
Control Scenarios
• Dynamic ControlConditionally and dynamically grant ticketsAdaptability
• Resource abstraction barriers supported by currencies. Insulate tasks.
![Page 23: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/23.jpg)
23
UI
• mktkt, rmtkt, mkcur, rmcur
• fund, unfund
• lstkt, lscur, fundx (shell)
![Page 24: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/24.jpg)
25
Relative Rate Accuracy
![Page 25: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/25.jpg)
26
Fairness Over Time
![Page 26: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/26.jpg)
27
Client-ServerQuery Processing Rates
![Page 27: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/27.jpg)
28
Controlling Video Rates
![Page 28: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/28.jpg)
29
Insulation
![Page 29: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/29.jpg)
30
Other Kinds of Resources• Claim: can be used for any resource where
queuing is used• Control relative waiting times for mutex locks.
– Mutex currency funded out of currencies of waiting threads
– Holder gets inheritance ticket in addition to its own funding, passed on to next holder (resulting from lottery) on release.
• Space sharing - inverse lottery, loser is victim(e.g. in page replacement decision, processor node preemption in MP partitioning)
![Page 30: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/30.jpg)
31
Lock Funding
Waiting thread
1
lock
1
Waiting thread
1
holding thread
1
t t
bt
![Page 31: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/31.jpg)
32
Lock Funding
New holding thread
1
lock
1
Waiting thread
1
Old holding thread
1
t
bt
![Page 32: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling](https://reader034.vdocuments.mx/reader034/viewer/2022051517/56649e9e5503460f94b9fa91/html5/thumbnails/32.jpg)
33
Mutex Waiting Times