# 多级反馈队列

多级反馈队列（MLFQ）是一种CPU调度算法，它在不同优先级上维护多个就绪队列，并根据观察到的行为在队列之间移动进程，使交互式作业停留在靠近顶部的位置，而长时间运行的批处理作业则下沉到较低层级。它通过允许这种移动，改进了固定的多级队列设计——在后者中进程被永久分配到一个队列。这种移动就是名称中的“反馈”。<sup>[1](https://rda.sliit.lk/entities/publication/ea70e9a3-710d-44f4-b2c3-5ad8e73dc472)</sup><sup> • </sup><sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup>

| 关键事实 | 详情 |
|---|---|
| 核心机制 | 多个优先级队列；每个队列内部采用轮转；进程在当前层级耗尽其时间配额后即被降级，这不必发生在单个时间片到期之时，而提前让出CPU的进程则留在原级或上升<sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup><sup> • </sup><sup>[3](https://www.cosmiclearn.com/opsys/sched_multilevel_feedback.php)</sup> |
| 饥饿控制 | 周期性的优先级提升将所有可运行任务移至顶层队列并重置其层级配额<sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup> |
| 实际部署 | Windows NT（2000、XP、Vista、7、Server）、Mac OS X、2.6之前的Linux、Solaris、NetBSD和FreeBSD<sup>[4](https://cseweb.ucsd.edu/classes/sp20/cse120-b/lectures/lec8.pdf)</sup> |
| Windows实现 | 基于优先级的抢占式调度器，围绕具有32个固定优先级层级的MLFQ构建，并对前台工作施行动态提升<sup>[5](https://www.digitalcitizen.life/scheduler-behavior-in-windows-vs-linux-how-tasks-are-prioritized-differently/)</sup> |
| Linux的替代 | Linux 2.6中的O(1)调度器，以及2.6.23之后的完全公平调度器，取代了早期的MLFQ<sup>[4](https://cseweb.ucsd.edu/classes/sp20/cse120-b/lectures/lec8.pdf)</sup> |
| 报告的性能 | 在一项Spark工作负载模拟中，MLFQ给出了最低的周转时间和等待时间，最早到达比率为97.3，且无截止时间违规<sup>[6](https://eurekamag.com/research/109/305/109305552.php)</sup> |

## 工作原理

**队列与时间片。** 调度器维护一组就绪队列，每个优先级一个，最高优先级的队列最先被服务。在单个队列内部，进程以轮转方式运行：每个进程获得固定的时间片，当进程在当前层级用完其时间配额时，就被降级到下一个较低优先级的队列，因此仅凭时间片到期并不一定导致降级。<sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup><sup> • </sup><sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC11066403/)</sup><sup> • </sup><sup>[14](https://ops-class.org/slides/2016-02-29-schedulingstory/)</sup><sup> • </sup><sup>[15](https://www.ece.villanova.edu/~rperry/os/Chapters/08-cpu-sched-mlfq/all-notes.html)</sup> 较低的队列通常获得更长的时间片，因此已经表现出CPU密集型特征的进程以更长的切片运行，切换开销更小。<sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup>

**降级与提升。** 反馈规则是决定性特征。在当前层级用完时间配额的进程被降级到下一个较低队列，无论其间是否有让出或阻塞。在时间片到期之前让出CPU的进程——例如等待输入或输出——被视为交互式的，留在原级或向上移动。这使调度器能够在事先不知道作业长度的情况下近似最短作业优先的行为：短作业在顶层队列中迅速完成，而长作业则逐渐下沉。<sup>[3](https://www.cosmiclearn.com/opsys/sched_multilevel_feedback.php)</sup><sup> • </sup><sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup>

**优先级提升。** 仅靠降级最终会使长批处理作业无限期地留在底部，而新到达的作业垄断较高的队列。为防止这种饥饿，内核周期性地执行全局提升：每个可运行任务都被移至顶层队列，其配额被重置，从而使低层级任务恢复响应性。<sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup><sup> • </sup><sup>[3](https://www.cosmiclearn.com/opsys/sched_multilevel_feedback.php)</sup>

**钻空子与记账。** 任何仅在进程消耗完整时间片时才将其降级的规则都可能被利用：进程可以在时间片即将到期前发出自愿让出，从而永远留在顶层队列，垄断CPU。防御措施包括按挂钟时间而非按每个时间片的行为来记录最近的CPU使用量，使让出不会重置记录，以及限制进程在降级前可在某一层级停留多久的配额。<sup>[3](https://www.cosmiclearn.com/opsys/sched_multilevel_feedback.php)</sup><sup> • </sup><sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup>

## 在实际操作系统中的使用

MLFQ一直是若干主要系统的调度器。[Windows NT](https://www.edgepedia.org/zh/windows-nt)及其后续版本（2000、XP、Vista、7和Server）、Mac OS X、2.6版本之前的Linux、Solaris、NetBSD和FreeBSD都使用或曾使用多级反馈队列。<sup>[4](https://cseweb.ucsd.edu/classes/sp20/cse120-b/lectures/lec8.pdf)</sup> 这种方法可追溯到早期的分时系统：CTSS使用了优先级队列，被认为是首个以多级反馈方式处理该问题的系统，而大约1967年的第一个Multics调度器即源自它。<sup>[8](https://ftp.cs.wisc.edu/par-distr-sys/papers/LinuxSched-SPE2007.pdf)</sup><sup> • </sup><sup>[9](https://multicians.org/mult-sched.html)</sup>

**Windows。** Windows实现了一个基于优先级的抢占式调度器，围绕具有32个固定优先级层级的MLFQ构建，并带有动态提升。<sup>[5](https://www.digitalcitizen.life/scheduler-behavior-in-windows-vs-linux-how-tasks-are-prioritized-differently/)</sup> 当普通优先级类中的进程被带到前台时，调度器会提升与前台窗口相关联的进程的优先级类，使其至少与任何后台进程一样高，系统既可以提升也可以降低动态优先级，以保持系统响应性并避免线程得不到处理器时间。<sup>[10](https://learn.microsoft.com/en-us/windows/win32/procthread/priority-boosts)</sup> 这些启发式规则偏向桌面响应性：与应用程序交互会立即将其线程提升到后台工作之上。<sup>[5](https://www.digitalcitizen.life/scheduler-behavior-in-windows-vs-linux-how-tasks-are-prioritized-differently/)</sup>

**Linux。** Linux在2.6系列中放弃了MLFQ设计，先是改用O(1)调度器，然后在2.6.23之后改用[完全公平调度器](https://www.edgepedia.org/zh/completely-fair-scheduler)，后者按虚拟运行时间将可运行任务排列在红黑树中，而不是将它们放入优先级队列。<sup>[4](https://cseweb.ucsd.edu/classes/sp20/cse120-b/lectures/lec8.pdf)</sup> 这两种设计反映了不同的目标：Windows通过自动启发式提升偏向交互式和GUI任务的极低延迟，而Linux的公平份额模型将显式的nice值——从最高优先级的-20到最低优先级的+19——映射为权重，追求数学上成比例的公平性，适合服务器和批处理工作负载。<sup>[5](https://www.digitalcitizen.life/scheduler-behavior-in-windows-vs-linux-how-tasks-are-prioritized-differently/)</sup>

## 变体与调优

队列数量、每层时间片、配额和提升间隔都是可调参数，它们的选择决定了交互延迟与批处理吞吐量之间的平衡。<sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup> 一种研究变体用动态时间片取代固定时间片：第一个队列以小时间片对短突发进程进行轮转，而第二个队列采用最短作业优先方案，并将其时间片设为剩余进程的平均突发时间。<sup>[11](https://scholar.unair.ac.id/en/publications/multilevel-feedback-queue-efficient-scheduling-and-implementation/)</sup> 理论研究还将反馈调度器分析为单服务器模型，其中作业被插入的位置是其已获得服务的函数，这一族包括轮转和先来先服务作为特例。<sup>[12](https://epubs.siam.org/doi/10.1137/0203012)</sup>

## 性能

比较研究将MLFQ列为较强的通用算法之一。2022年IEEE的一项比较将其与先来先服务、最短作业优先、最短剩余时间优先、基于优先级、轮转和多级队列调度并列考察，强调其适应性是显著特征。<sup>[1](https://rda.sliit.lk/entities/publication/ea70e9a3-710d-44f4-b2c3-5ad8e73dc472)</sup> 在发表于《国际自组网与普适计算杂志》的一项基于Python的[Apache Spark](https://www.edgepedia.org/zh/apache-spark)作业调度模拟中，MLFQ在FIFO、公平、最早截止时间优先、轮转、最短作业优先、最小松弛优先和优先级调度中始终表现最佳，在所测试的工作负载条件下实现了最低的周转时间和等待时间、97.3的最早到达比率，且无截止时间违规。<sup>[6](https://eurekamag.com/research/109/305/109305552.php)</sup> 一项对新型多级反馈队列调度器的相关评估发现，与动态尽力而为调度器相比，其在响应时间上取得了有益的结果。<sup>[13](https://www.ijcttjournal.org/archives/ijctt-v13p124)</sup>

权衡仍然是该设计固有的那些：奖励让出的启发式规则可能被利用，低优先级工作依赖于提升间隔，而众多可调参数使行为取决于工作负载，无法得到保证。<sup>[2](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)</sup><sup> • </sup><sup>[3](https://www.cosmiclearn.com/opsys/sched_multilevel_feedback.php)</sup>

## References

1. [S. Pemasinghe and S. Rajapaksha, "Comparison of CPU Scheduling Algorithms: FCFS, SJF, SRTF, Round Robin, Priority Based, and Multilevel Queuing," 2022 IEEE R10-HTC, pp. 318-323](https://rda.sliit.lk/entities/publication/ea70e9a3-710d-44f4-b2c3-5ad8e73dc472)
2. [Multilevel Queues and Feedback Queues, AlgoMaster.io](https://algomaster.io/learn/operating-systems/multilevel-queues-and-mlfq)
3. [Multilevel Feedback Queue (MLFQ) Scheduling, CosmicLearn](https://www.cosmiclearn.com/opsys/sched_multilevel_feedback.php)
4. [Scheduling Algorithms in OSes, CSE 120 lecture notes, UC San Diego](https://cseweb.ucsd.edu/classes/sp20/cse120-b/lectures/lec8.pdf)
5. [Scheduler Behavior in Windows vs Linux, Digital Citizen](https://www.digitalcitizen.life/scheduler-behavior-in-windows-vs-linux-how-tasks-are-prioritized-differently/)
6. [V. P. Verma, S. Kumar, N. S. Naik, "Optimising job scheduling in Apache Spark," International Journal of Ad Hoc and Ubiquitous Computing 52(3): 145-157](https://eurekamag.com/research/109/305/109305552.php)
7. [Study and evaluation of CPU scheduling algorithms, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC11066403/)
8. [Comparison of interactivity in Linux 2.6 and MLFQ schedulers, Software—Practice and Experience](https://ftp.cs.wisc.edu/par-distr-sys/papers/LinuxSched-SPE2007.pdf)
9. [The Multics Scheduler, Multicians.org](https://multicians.org/mult-sched.html)
10. [Priority Boosts, Win32 apps, Microsoft Learn](https://learn.microsoft.com/en-us/windows/win32/procthread/priority-boosts)
11. [Multilevel Feedback Queue: Efficient Scheduling and Implementation by Using Dynamic Quantum, Universitas Airlangga](https://scholar.unair.ac.id/en/publications/multilevel-feedback-queue-efficient-scheduling-and-implementation/)
12. [Analysis of a Feedback Scheduler, SIAM Journal on Computing](https://epubs.siam.org/doi/10.1137/0203012)
13. [Assessment of Response Time for New Multi Level Feedback Queue Scheduler, IJCTT vol. 13, no. 1](https://www.ijcttjournal.org/archives/ijctt-v13p124)
14. [ops-class.org, A Scheduling Story](https://ops-class.org/slides/2016-02-29-schedulingstory/)
15. [OSTEP Chapter 8](https://www.ece.villanova.edu/~rperry/os/Chapters/08-cpu-sched-mlfq/all-notes.html)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Operating systems › Operating system concepts

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/multilevel-feedback-queue

English original: https://www.edgepedia.org/multilevel-feedback-queue
