Attempt #3: Better Accounting

Let's determine how the issue of gaming is handled in MLFQ by changing some rules!

We'll cover the following

Preventing gaming of scheduler

We now have one more problem to solve: how to prevent gaming of our scheduler? The real culprit here, as you might have guessed, are Rules 4a and 4b, which let a job retain its priority by relinquishing the CPU before the time slice expires. So what should we do?

The solution here is to perform better accounting of CPU time at each level of the MLFQ. Instead of forgetting how much of a time slice a process used at a given level, the scheduler should keep track; once a process has used its allotment, it is demoted to the next priority queue. Whether it uses the time slice in one long burst or many small ones does not matter. We thus rewrite Rules 4a and 4b to the following single rule:

  • 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 one queue).

Example

Let’s look at an example. The figure below shows what happens when a workload tries to game the scheduler with the old Rules 4a and 4b (on the left) as well the new anti-gaming Rule 4.

Get hands-on with 1400+ tech skills courses.