OSTEP Chapter 8: Scheduling: Multi-level feedback queue

OSTEP: Scheduling: Multi-level feedback queue

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

This exercise requires running mlfq.py to complete. First run -hto get some usage methods:

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

Options:
  -h, --help            show this help message and exit
  -s SEED, --seed=SEED  the random seed
  -n NUMQUEUES, --numQueues=NUMQUEUES
                        number of queues in MLFQ (if not using -Q)
  -q QUANTUM, --quantum=QUANTUM
                        length of time slice (if not using -Q)
  -a ALLOTMENT, --allotment=ALLOTMENT
                        length of allotment (if not using -A)
  -Q QUANTUMLIST, --quantumList=QUANTUMLIST
                        length of time slice per queue level, specified as
                        x,y,z,... where x is the quantum length for the
                        highest priority queue, y the next highest, and so
                        forth
  -A ALLOTMENTLIST, --allotmentList=ALLOTMENTLIST
                        length of time allotment per queue level, specified as
                        x,y,z,... where x is the # of time slices for the
                        highest priority queue, y the next highest, and so
                        forth
  -j NUMJOBS, --numJobs=NUMJOBS
                        number of jobs in the system
  -m MAXLEN, --maxlen=MAXLEN
                        max run-time of a job (if randomly generating)
  -M MAXIO, --maxio=MAXIO
                        max I/O frequency of a job (if randomly generating)
  -B BOOST, --boost=BOOST
                        how often to boost the priority of all jobs back to
                        high priority
  -i IOTIME, --iotime=IOTIME
                        how long an I/O should last (fixed constant)
  -S, --stay            reset and stay at same priority level when issuing I/O
  -I, --iobump          if specified, jobs that finished I/O move immediately
                        to front of current queue
  -l JLIST, --jlist=JLIST
                        a comma-separated list of jobs to run, in the form
                        x1,y1,z1:x2,y2,z2:... where x is start time, y is run
                        time, and z is how often the job issues an I/O request
  -c                    compute answers for me

1. Run a simulation using two queues and two jobs:python3 mlfq.py -s 22 -q 3 -n 2 -j 2 -m 10 -M 0 -c

Comparing the above guide, it can be seen that this command uses -s 22the specified random seed to generate two tasks, and uses -q 3the specified time slice of 3. Other commands can be compared by yourself. The value of -s can be modified to use different random sources and specify different tasks.

yzy@yzy-virtual-machine:~/ostep-homework/cpu-sched-mlfq$ python3 mlfq.py -s 22 -q 3 -n 2 -j 2 -m 10 -M 0 -c

Job List:
  Job  0: startTime   0 - runTime   9 - ioFreq   0
  Job  1: startTime   0 - runTime   1 - ioFreq   0


Execution Trace:

[ time 0 ] JOB BEGINS by JOB 0
[ time 0 ] JOB BEGINS by JOB 1
[ time 0 ] Run JOB 0 at PRIORITY 1 [ TICKS 2 ALLOT 1 TIME 8 (of 9) ]
[ time 1 ] Run JOB 0 at PRIORITY 1 [ TICKS 1 ALLOT 1 TIME 7 (of 9) ]
[ time 2 ] Run JOB 0 at PRIORITY 1 [ TICKS 0 ALLOT 1 TIME 6 (of 9) ]
[ time 3 ] Run JOB 1 at PRIORITY 1 [ TICKS 2 ALLOT 1 TIME 0 (of 1) ]
[ time 4 ] FINISHED JOB 1
[ time 4 ] Run JOB 0 at PRIORITY 0 [ TICKS 2 ALLOT 1 TIME 5 (of 9) ]
[ time 5 ] Run JOB 0 at PRIORITY 0 [ TICKS 1 ALLOT 1 TIME 4 (of 9) ]
[ time 6 ] Run JOB 0 at PRIORITY 0 [ TICKS 0 ALLOT 1 TIME 3 (of 9) ]
[ time 7 ] Run JOB 0 at PRIORITY 0 [ TICKS 2 ALLOT 1 TIME 2 (of 9) ]
[ time 8 ] Run JOB 0 at PRIORITY 0 [ TICKS 1 ALLOT 1 TIME 1 (of 9) ]
[ time 9 ] Run JOB 0 at PRIORITY 0 [ TICKS 0 ALLOT 1 TIME 0 (of 9) ]
[ time 10 ] FINISHED JOB 0

Final statistics:
  Job  0: startTime   0 - response   0 - turnaround  10
  Job  1: startTime   0 - response   3 - turnaround   4

  Avg  1: startTime n/a - response 1.50 - turnaround 7.00

2. Use the help to complete this question:

// 图 8.2 单个长工作
python3 mlfq.py -n 3 -q 10 -l 0,200,0 -c

// 图 8.3 来了一个短工作
python3 mlfq.py -n 3 -q 10 -l 0,180,0:100,20,0 -c

//后续图也可对照使用帮助编写

3. Set up only one queue.

4. python3 mlfq.py mlfq.py -n 3 -q 10 -l 0,100,9:0,100,0 -i 1 -S -cRun the command and you will find that task 0 will always run at priority 2.

5. Run the following two commands respectively: you will find that after adding, -Iwhen a task IO ends, it will be placed at the front of the queue and will be run first. If it is not added -I, it will be run in the order in the original queue.

python3 mlfq.py -n 2 -q 10 -l 0,50,15:0,50,0 -i 1 -S -c
python3 mlfq.py -n 2 -q 10 -l 0,50,15:0,50,0 -i 1 -S -I -c

Summary and insights

  • MLFQ sets up many independent queues , each queue has a different priority , and a job can only exist in one priority queue . MLFQ runs high-priority jobs first , and jobs with the same priority are run using round-robin scheduling.
  • Every new job added is given the highest priority.
  • Once a job has exhausted its time quota for a tier, lower its priority. Over time, add all work to the highest priority.
  • The purpose of MLFQ design is to observe the operation of work and conduct reasonable scheduling. For short-running interactive work, you can get a very responsive experience. It also runs fairly well for long-running CPU-intensive jobs.

Guess you like

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