Lottery Scheduling: Flexible Proportional-Share Resource Management
by Carl Waldspurger and William Weihl
Notes by Daniel Switkin switkin@cs.cornell.edu
The Basics
The key idea is to allocate resources in a random drawing, where each competing
thread holds a number of lottery tickets proportional to its priority. This has
the following nice properties:
- Proportion of tickets not only controls proportion of resources received,
but also dictates response time (more tickets == sooner first lottery win).
- Very fine grained levels of priority, dynamically adjustable.
- Actual distribution of resources gets more accurate over time, i.e. increasingly
matches the proportion of lottery tickets.
- No conventional starvation since probabilistically even a thread with one ticket
will eventually get run.
Modular Resource Management
- Ticket Transfers - The ability to lend your tickets to another client
you may be waiting on. This coincidentally solves the priority inversion dillemma.
- Ticket Inflation - The ability to mint more tickets to boost your rights
to a resource. Can be useful with...
- Ticket Currencies - Resource rights expressed in local units, this
currency being funded by a previous currency (and ultimately by the base currency).
- Compensation Tickets - A technique to restore the proportion of resources
intended for a thread which does not consume its entire allocation on each pass.
Implementation Details
The authors essentially did a rough hack which had about the same overhead as the
default scheduling algorithm in Mach 3.0. The following notes apply:
- Requires a fast and fair random number generator.
- O(n) time if done poorly, easily improved to O(log(n)) with a tree.
- Currencies involve the time and complexity of conversion between units for
the flexibility they offer. This freedom typically involves insulating currencies
from each other, so that additional threads spawned in process A may slow A down,
but will have no effect on process B.
- Ticket transfers were implemented through messaging.
Conclusion
- Modern processor speeds ensure that actual proportions of resources come into
line very quickly and accurately with ticket proportions.
- Processes could provide feedback for dynamic priorities.
- Is the notion of currencies worth the complexity?
- Do we need this level of priority granularity?
- Is proportional allocation more desirable than traditional priority scheduling?