Operating Systems: Three Easy Pieces学习笔记 - Virtualization - Scheduling (3)

Scheduling: Proportional Share

Also known as a fair-share scheduler.
Instead of optimizing for turnaround or response time, a scheduler might instead try to guarantee that each job obtain a certain percentage of CPU time.
Crux: How to share the CPU proportionally

Basic Concept: Tickets Represent Your Share

Lottery scheduling achieves this probabilistically (but not deterministically) by holding a lottery every so often (say, every time slice).
The scheduler must know how many total tickets there are (100, for example here). It then picks a winning ticket, which is a number from 0 to 99. Assuming process A holds tickets 0 through 74 and process B 75 through 99, the winning ticket simply determines whether A or B runs. The scheduler then loads the state of that winning process and runs it. Therefore, the possibility of A getting executed is 75%, while B 25%.

Ticket Mechanisms

Ticket currency: Currency allows a user with a set of tickets to allocate tickets among their own jobs in whatever currency they would like; the system then automatically converts said currency into the correct global value
Ticket transfer: A process can temporarily hand off its tickets to another process
Ticket inflation: A process can temporarily raise or lower the number of tickets it owns, can be applied in an environment where a group of processes trust one another

Implementation

What we need: a good random number generator to pick the winning ticket, a data structure to track the processes, the total number of tickets

image.png

Organizing the list in sorted order from the highest number of tickets to the lowest can improve the speed.

Why Not Deterministic?

Stride Scheduling: A deterministic fair-share scheduler. See Page 88 of the book for more details
Advantage of lottery scheduling over stride scheduling: No global state. If a new job enters in the middle of the stride scheduling, it's hard to determine its pass value. If we set it to 0, this job would monopolize the CPU. However, in lottery scheduling, this will never happen as there is no global state per process.

Summary

Proportional-share scheduling is not widely adopted as CPU schedulers for the following reasons:

  1. It does not particularly mesh well with I/O
  2. It leaves open the hard problem of ticket assignment, i.e., how many tickets a process should have

你可能感兴趣的:(Operating Systems: Three Easy Pieces学习笔记 - Virtualization - Scheduling (3))