# 宏内核

宏内核是一种操作系统架构，整个操作系统——包括进程管理、文件系统、设备驱动和内存管理——作为一个单一的整体程序，在一个被称为内核空间的特权地址空间中运行。<sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup> UNIX 等传统操作系统就是这样构建的，自 1969 年 Unix 诞生以来，这种设计一直是事实上的标准。<sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup><sup> • </sup><sup>[2](https://web.mit.edu/ha22286/www/papers/MEng21_2.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义性特征 | 所有操作系统组件都驻留并运行于同一地址空间——内核空间，任何组件都可以不受限制地直接调用另一组件的函数<sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup> |
| 性能 | 与微内核相比，上下文切换更少、消息传递更少，因为组件之间通过共享内存中的过程调用进行通信<sup>[3](https://wiki.osdev.org/Monolithic_Kernel)</sup> |
| 主要弱点 | 无故障隔离：任何组件（甚至设备驱动）发生故障，都可能导致整个系统崩溃，或使系统落入攻击者之手<sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup><sup> • </sup><sup>[4](https://arxiv.org/abs/2404.08716)</sup> |
| 模块化 | Linux 和 FreeBSD 等现代宏内核以内核模块的形式加载驱动和其他功能，这些模块仍在内核空间中运行<sup>[3](https://wiki.osdev.org/Monolithic_Kernel)</sup><sup> • </sup><sup>[5](https://docs.freebsd.org/en/books/handbook/book/index.html)</sup> |
| 主要替代方案 | 微内核仅在内核中保留最少量的服务，其余服务作为用户空间进程运行，通过消息传递进行通信<sup>[6](https://linux-kernel-labs.github.io/refs/heads/master/lectures/intro.html)</sup> |

## 结构与运作

在宏内核设计中，操作系统作为一个大程序运作。由于每个组件共享同一地址空间，文件系统、虚拟内存管理器、进程管理器和设备驱动之间的通信是直接的函数调用，而非进程间消息。这使得组件之间的交互简单而快速，模块交互在过程调用方面的开销很低。<sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup>

同一共享地址空间也是该架构的核心隐患。这种架构不提供故障隔离，意味着单个组件的故障可能拖垮整个系统，因此其容错能力不如按模块组织起来的设计。<sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup>一项针对主流系统的安全分析从攻击者的角度指出了这一点：由于所有内核功能都驻留于单一共享地址空间，一个缺陷——哪怕存在于设备驱动这类非核心部分——就可能使整个操作系统落入攻击者的控制之下。<sup>[4](https://arxiv.org/abs/2404.08716)</sup>

## 宏内核与微内核

微内核架构采取相反的思路：内核只包含足以让运行中的进程之间进行消息传递的代码，而宏内核会在内部运行的服务——如文件系统和设备驱动——则作为独立的用户空间进程运行。<sup>[6](https://linux-kernel-labs.github.io/refs/heads/master/lectures/intro.html)</sup>好处是隔离性。如果某个服务崩溃，可以在不影响整个系统的情况下重启，且以完全特权运行的代码更少。<sup>[6](https://linux-kernel-labs.github.io/refs/heads/master/lectures/intro.html)</sup><sup> • </sup><sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup>代价是性能，因为每次服务请求都要跨越用户-内核边界，而这些边界跨越通常比直接调用更慢。<sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup><sup> • </sup><sup>[3](https://wiki.osdev.org/Monolithic_Kernel)</sup>

[GNU Hurd](https://www.edgepedia.org/zh/gnu-hurd) 具体地展示了微内核这一替代方案。它是一组运行在 [Mach](https://www.edgepedia.org/zh/mach-kernel) 微内核之上的服务器，实现了文件系统、网络协议和文件访问控制——这些功能在 Linux 等类 Unix 内核中是在内部实现的。<sup>[7](https://www.gnu.org/software/hurd/doc/hurd_1.html)</sup>

混合内核是一种中间立场，介于两种设计之间，融合了宏内核、微内核和插件式架构的特点；Windows 被认为采用了这种方法。<sup>[8](https://teaching.os.rwth-aachen.de/LKP/lecture/lkp-lecture.html)</sup><sup> • </sup><sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup>

## 塔能鲍姆-托瓦兹之争

两种设计之间的权衡催生了操作系统历史上最著名的论战之一。1992 年，阿姆斯特丹自由大学计算机科学教授、MINIX 教学操作系统作者安德鲁·S·塔能鲍姆（Andrew S. Tanenbaum）在 comp.os.minix 新闻组的一篇帖子中批评 Linux，认为微内核优于宏内核，因此 Linux 已经过时。<sup>[9](https://www.obriain.com/training/linux_cis/odp/Topic_1-Introduction_to_GNULinux_odp-Notes.pdf)</sup>

后来的历史从实践层面给出了回答。Linux 最初是为实验性的 PC 操作系统开发而设计的，后来却被用于数十亿个应用场景，从高性能计算到个人电脑、基于 Android 的移动设备、路由器、智能手表和智能电视。<sup>[2](https://web.mit.edu/ha22286/www/papers/MEng21_2.pdf)</sup>到 2025 年 1 月，该内核已从 1991 年的大约 1 万行代码增长到超过 4000 万行，全球最强超级计算机 TOP500 排行榜上的全部 500 套系统都运行着 Linux。<sup>[11](https://www.techradar.com/pro/its-35-years-since-linus-torvalds-first-revealed-linux-calling-it-just-a-hobby-how-wrong-he-was)</sup>

## 宏内核内部的模块化

现代宏内核并非铁板一块。Linux 以动态加载的内核模块形式提供驱动；尽管可以加载，它们仍被加载到内核空间中并在其中运行，这就是 Linux 仍被归类为宏内核的原因。<sup>[3](https://wiki.osdev.org/Monolithic_Kernel)</sup>FreeBSD 走了类似的道路。传统上它使用宏内核——一个支持固定设备列表的大程序，改变内核行为需要编译并重启进入新内核。如今 FreeBSD 的大部分内核功能都包含在可动态加载和卸载的模块中，该项目称之为模块化内核，不过某些安全环境仍要求将功能静态编译进去。<sup>[5](https://docs.freebsd.org/en/books/handbook/book/index.html)</sup>

这种模块化改变了内核的维护方式，却没有改变其安全模型。由于加载的模块与核心内核在同一特权空间中执行，故障隔离问题依然存在，因此关于宏内核安全的研究提出以隔间化——将内核代码拆分为相互隔离的隔间——作为补救措施。<sup>[4](https://arxiv.org/abs/2404.08716)</sup>

## 宏内核的应用场景

宏内核设计主导着主流计算。在 80x86/PC 架构上，完全没有可加载模块机制的纯宏内核很罕见，但在嵌入式系统中更为常见。<sup>[3](https://wiki.osdev.org/Monolithic_Kernel)</sup>架构的选择仍然是需求与权衡的问题，而非已有定论的问题；操作系统设计已经产生了宏内核、分层式、微内核和混合式等结构，各有其适合的目标。<sup>[1](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)</sup>

## References

1. [Fundamental OS Concepts, Introduction to Computer Science, OpenStax (Rice University)](https://openstax.org/books/introduction-computer-science/pages/6-2-fundamental-os-concepts)
2. [The monolithic kernel arc, MIT MEng paper](https://web.mit.edu/ha22286/www/papers/MEng21_2.pdf)
3. [Monolithic Kernel, OSDev Wiki](https://wiki.osdev.org/Monolithic_Kernel)
4. [Securing Monolithic Kernels using Compartmentalization, arXiv:2404.08716](https://arxiv.org/abs/2404.08716)
5. [FreeBSD Handbook, Chapter 10: Configuring the FreeBSD Kernel](https://docs.freebsd.org/en/books/handbook/book/index.html)
6. [Introduction, Linux Kernel Labs lectures](https://linux-kernel-labs.github.io/refs/heads/master/lectures/intro.html)
7. [Hurd Reference Manual: Introduction, GNU Project](https://www.gnu.org/software/hurd/doc/hurd_1.html)
8. [Linux Kernel Programming, RWTH Aachen lecture notes](https://teaching.os.rwth-aachen.de/LKP/lecture/lkp-lecture.html)
9. [What is a Monolithic kernel?, training notes on the Tanenbaum critique](https://www.obriain.com/training/linux_cis/odp/Topic_1-Introduction_to_GNULinux_odp-Notes.pdf)
10. [History, Linux Documentation Project](https://www.iitk.ac.in/LDP/LDP/intro-linux/html/sect_01_01.html)
11. [It's 35 years since Linus Torvalds first revealed Linux, TechRadar](https://www.techradar.com/pro/its-35-years-since-linus-torvalds-first-revealed-linux-calling-it-just-a-hobby-how-wrong-he-was)

---
*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/monolithic-kernel

English original: https://www.edgepedia.org/monolithic-kernel
