OSTEP Chapter 9: Scheduling: Proportional Share

OSTEP: Scheduling: Proportional Share

This series mainly completes the after-school homework of Introduction to Operating Systems (Operating Systems: Three Easy Pieces ), and also involves some summaries and insights of each chapter. Most of the questions do not have a standard answer. Students are welcome to find disputes and errors. discuss together.

related resources

Website:http://www.ostep.org/

Homework:https://github.com/remzi-arpacidusseau/ostep-homework/

Column: Introduction to Operating Systems (ostep)

Answers to exercises

The exercises in this chapter need to be used lottery.py. First use them -hto view the usage help:

yzy@yzy-virtual-machine:~/ostep-homework/cpu-sched-lottery$ python3 lottery.py -h
Usage: lottery.py [options]

Options:
  -h, --help            show this help message and exit
  -s SEED, --seed=SEED  the random seed
  -j JOBS, --jobs=JOBS  number of jobs in the system
  -l JLIST, --jlist=JLIST
                        instead of random jobs, provide a comma-separated list
                        of run times and ticket values (e.g., 10:100,20:100
                        would have two jobs with run-times of 10 and 20, each
                        with 100 tickets)
  -m MAXLEN, --maxlen=MAXLEN
                        max length of job
  -T MAXTICKET, --maxticket=MAXTICKET
                        maximum ticket value, if randomly assigned
  -q QUANTUM, --quantum=QUANTUM
                        length of time slice
  -c, --compute         compute answers for me

1. Use the following commands to execute:

python3 lottery.py -s 1 -j 3 -c
python3 lottery.py -s 2 -j 3 -c
python3 lottery.py -s 3 -j 3 -c

2. Run this command python3 lottery.py -l 10:1,10:100 -c.

The probability of task 0 running will be very small. Probabilistically, job 0 will run 1/101 of the time. This imbalance is unfair to tasks with few tickets, which will get little running time.

3. Run the following commands respectively. You can see that the number of lottery tickets is the same, and they should have the same running time, that is, the running ends at the same time. However, during the actual running, the ending time has a relatively large deviation:

python3 lottery.py -s 0 -l 100:100,100:100 -c
python3 lottery.py -s 2 -l 100:100,100:100 -c
python3 lottery.py -s 1 -l 100:100,100:100 -c

4. Quantum scale is the time slice size. As the time slice gets smaller, the probability of lottery proportion formation becomes more accurate.

Summary and insights

  • The purpose of proportional share scheduling is to ensure that each job gets a certain proportion of CPU time , not to optimize turnaround and response times.
  • The lottery number ratio represents the CPU usage ratio . For example, A owns 75 lottery tickets and B owns 25 lottery tickets. This mechanism ensures that A has 75% of the running time and B has 25% of the running time.
  • Lottery tickets can be issued and transferred and used to fulfill different functions.
  • The operating system generates a random number from 0 to the total number of lottery tickets, and then selects the process to be run based on the random number .
  • Lottery scheduling has a certain degree of randomness. Step scheduling can solve this problem, but step scheduling requires global status and is not flexible enough.
  • Both step scheduling and lottery scheduling are not widely used because they cannot solve IO problems well .
  • In some specific scenarios, proportional shares play a unique role . For example, VM's ESX system uses proportional allocation to share memory.

Guess you like

Origin blog.csdn.net/doreen211/article/details/125589002