MLFQ想同时解决周转时间和响应时间,那当系统运行时,调度器如何学习负载特性使得更好做出调度决策?
Basic Rules:
Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t).
Rule 2: If Priority(A) = Priority(B), A & B run in RR.
MLFQ根据观察到job的行为来变动其优先级,高优先级更大概率获得时间片。如何改变优先级?
Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue).
Rule 4a: If a job uses up an entire time slice while running, its priority is reduced (i.e., it moves down one queue).调度器把每个job首先当做short job,随着时间增长降低优先级,变成long-running job。
Rule 4b: If a job gives up the CPU before the time slice is up, it stays at the same priority level.在job执行大量I/O操作而在time slice没用完前放弃CPU,则不惩罚它的优先级。
尽管看起来很公平,依旧存在两大问题:
一、过多交互jobs占用所有CPU时间,long-running jobs被饿死。
二、有的用户重写调度算法,将自己关心的job在每用到99%时间片后发出I/O请求来保持优先级,从来掌握CPU。
三、如果long-running job转变为交互式job,由于优先级没提上来,依然不会被优先处理。
优先级提升:
• Rule 5: After some time period S, move all the jobs in the system to the topmost queue.同时解决1和3问题。当然这会牵涉出S如何合理设置问题。
Better Accounting:
问题2是由规则4a和4b引起的,则我们应该给不同优先级的队列设置合理的时间片。
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).