CS139-lecture-20211005

CPU scheduling cont. #

I/O Bursts #

image_2021-10-05-13-40-00 image_2021-10-05-13-40-16 image_2021-10-05-13-40-20

Round robin #

Round robin strives on optimizing average response time.

image_2021-10-05-13-41-58

If we make the value of \( q \) too small, we will have a lot of overhead due to context switches.

image_2021-10-05-13-49-59 image_2021-10-05-13-50-14 image_2021-10-05-13-51-34 image_2021-10-05-13-53-01 image_2021-10-05-13-53-06

Priority scheduling #

Technically, shortest job first is a type of priority scheduling (prioritizing shortest burst time).

image_2021-10-05-13-53-16 image_2021-10-05-13-57-05

Multilevel queue #

image_2021-10-05-13-57-14 image_2021-10-05-13-57-20 image_2021-10-05-14-00-47 image_2021-10-05-14-00-55 image_2021-10-05-14-05-18

Scheduling in Linux (CFS) #

image_2021-10-05-14-01-18

Priority levels are 0-139.

  • The smaller the priority number, the higher the priority.
  • The higher priority processes have larger time quantums.
  • Feedback based on sleep time (waiting/idle)
    • longer sleep processes are usually interactive, so we bump up the priority (lower value)
    • shorter sleep processes are usually computational process, so we bump the priority down (higher value)
  • The run queue is 2 arrays of tasks

Real time

  • important programs
  • priority levels 0-99

Time sharing

  • user programs
  • priority levels 100-140
  • default is 120

image_2021-10-05-14-16-44

Picking the next item in the array is constant time. When we create a process, we add it to the corresponding task list, based on priority.

When the active array is exhausted, it is swapped with the expired array.

However, this scheduling algorithm has some problems

  • performance of interactive processes can be slow
  • fairness issue

Linux’s new CFS (Completely Fair Scheduler) addresses these problems:

image_2021-10-05-14-21-47

  • CFS uses a red-black tree for its run queue
  • The value that the red-black tree is ordered is called vruntime, which is the “virtual run time” that is a function of the run time.

image_2021-10-05-14-30-02

  • CFS scheduling always picks leftmost node, the smallest value (smallest vruntime value)
  • periodically address vruntime and compare to the leftmost, if it is still smaller we will allow the process to continue to run. When the vruntime surpasses the leftmost in the run queue tree, it will switch to the new smaller value. (Similar to shortest run time, but we’re looking at the history)
  • vruntime progress rate depends on priority
    • progress rate faster for low priority
    • progress rate slower for high priority
  • note that only 1 tree is used, for all priority

image_2021-10-05-14-39-45