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).