# 混合内核

混合内核是一种操作系统内核架构，它结合了宏内核与微内核的特征：许多操作系统服务像在微内核中那样运行于用户空间，但部分服务仍像在宏内核中那样保留在内核空间，旨在将宏内核方案的速度与较简单的设计，同微内核方案的模块化与稳定性结合起来。<sup>[1](https://run.unl.pt/bitstream/10362/34368/1/Ferreira_2017.pdf)</sup> 最著名的例子是微软的NT内核——从[Windows NT](https://www.edgepedia.org/zh/windows-nt)起，它一直为Windows提供动力——以及苹果在macOS和iOS中的XNU内核。<sup>[1](https://run.unl.pt/bitstream/10362/34368/1/Ferreira_2017.pdf)</sup><sup> • </sup><sup>[2](https://github.com/apple/darwin-xnu?ref=developer-insider)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 许多功能运行于用户空间，但部分保留在内核空间，介于宏内核与微内核设计之间<sup>[1](https://run.unl.pt/bitstream/10362/34368/1/Ferreira_2017.pdf)</sup> |
| Windows NT结构 | 一个职责极少的核心内核（KE），由执行体层（Ex）执行更高层的策略<sup>[3](https://techcommunity.microsoft.com/blog/windowsosplatform/one-windows-kernel/267142)</sup> |
| XNU的构成 | 卡内基梅隆大学的Mach内核，加上FreeBSD组件，再加上IOKit——一个C++驱动应用程序接口（API）<sup>[2](https://github.com/apple/darwin-xnu?ref=developer-insider)</sup> |
| OS X中的Mach | Mach与其他内核组件链接进单一内核地址空间，主要是为了性能<sup>[4](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Mach/Mach.html)</sup> |
| 内核内放置的实测效果 | 在Mach 3.0上，将服务器移入内核使RPC性能提高到三倍，Unix系统调用提高20%到一倍<sup>[5](https://www.usenix.org/conference/usenix-mach-iii-symposium/kernel-servers-mach-30-implementation-and-performance)</sup> |
| 微内核基线 | 在AIM基准测试中，L4Linux的吞吐量仅比原生Linux低5%，而MkLinux的相应损失则高出5到7倍<sup>[6](https://os.inf.tu-dresden.de/pubs/sosp97/)</sup> |
| 当前方向 | 苹果和微软都在将驱动代码移出内核：DriverKit让驱动运行于用户空间，微软预计内核模式代码将大幅减少<sup>[7](https://developer.apple.com/system-extensions/)</sup><sup> • </sup><sup>[8](https://www.windowscentral.com/microsoft/windows-11/microsoft-is-raising-the-bar-and-making-major-changes-to-how-drivers-are-built-and-verified-on-windows-11-heres-the-important-details)</sup> |

## 在宏内核与微内核之间的位置

在宏内核中，所有操作系统服务都在内核空间中运行，拥有完全特权访问，用自己的代码和内存空间管理系统。在微内核中，内核只保留进程管理、进程间通信（IPC）和内存分配等最小功能集，并将其他服务交给用户空间守护进程，这些守护进程可以像普通程序一样启动和停止。微内核需要更多的上下文切换和消息传递，这使其在概念上更慢，但更少的内核空间代码使其更稳定、更易于更改。<sup>[1](https://run.unl.pt/bitstream/10362/34368/1/Ferreira_2017.pdf)</sup>

混合内核将部分服务保留在内核空间，让另一些服务运行于用户空间。其宣称的动机是将宏内核的速度与较简单的设计，同微内核的模块化、执行稳定性和安全性结合起来。<sup>[1](https://run.unl.pt/bitstream/10362/34368/1/Ferreira_2017.pdf)</sup> 这条边界是设计选择而非固定规则，该类别涵盖从相当不同的起点构建的系统，包括为性能而吸收服务的微内核，以及组织为分层模块的宏内核式设计。

## Windows NT

Windows NT内核的组织方式是一个小核心加若干服务层。微软将其描述为类似微内核，因为核心内核（KE）职责极少，而执行体层（Ex）执行所有更高层的策略。<sup>[3](https://techcommunity.microsoft.com/blog/windowsosplatform/one-windows-kernel/267142)</sup> 执行体是内核模式组件的统称，这些组件为设备驱动提供服务，包括对象管理、内存管理、进程与线程管理、输入/输出管理和配置管理。<sup>[9](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/windows-kernel-mode-executive-support-library)</sup> 内核模式驱动作为执行体的一部分运行，执行体管理I/O、即插即用、内存、进程与线程以及安全。<sup>[10](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/types-of-windows-drivers)</sup>

第三个内核模式组件是硬件抽象层（HAL），它将内核、设备驱动和执行体与平台特定的硬件差异隔离开来。<sup>[11](https://ptacts.uspto.gov/ptacts/public-informations/petitions/1554714/download-documents?artifactId=-I8wof5ABIE_atpLKT8KYvp2XFRbCIxEoR2SAa_p_eFR0m_6KoWOUgQ)</sup> HAL例程使内核和设备驱动在具有相同CPU架构的平台上二进制兼容。<sup>[12](https://www.bitsavers.org/pdf/microsoft/windows_NT_4.0/Baker_-_The_Windows_NT_Device_Driver_Book_1997.pdf)</sup>

**起源。** Windows NT由戴夫·卡特勒（Dave Cutler）和一个包括众多前DEC VMS工程师的团队从零构思，构建为一个完全的32位操作系统，具有可移植内核、抢占式多任务和内存保护。首个版本[Windows NT 3.1](https://www.edgepedia.org/zh/windows-nt-3-1)于1993年发布，在当时颇为沉重，要求80386配12 MB内存，而当时4 MB才是常态。代号Daytona的Windows NT 3.5于1994年发布，对系统进行了调优和加速，微软还提供了面向MIPS、DEC Alpha以及后来PowerPC处理器的版本，体现了HAL设计中内置的可移植性目标。<sup>[13](https://www.tomshardware.com/software/windows/microsofts-pivotal-windows-nt-3-5-release-made-it-a-serious-contender-31-years-ago-today)</sup>

## XNU与Darwin

苹果的XNU是一个混合内核——随运行于macOS和iOS的[Darwin](https://www.edgepedia.org/zh/darwin-operating-system)操作系统一同发布——它将[卡内基梅隆大学](https://www.edgepedia.org/zh/carnegie-mellon-university)（Carnegie Mellon University）创造的[Mach](https://www.edgepedia.org/zh/mach-kernel)内核与源自FreeBSD的组件以及IOKit（一个用于驱动开发的C++应用程序接口（API））融合在一起。<sup>[2](https://github.com/apple/darwin-xnu?ref=developer-insider)</sup> OS X内核环境包括Mach内核、BSD、I/O Kit、文件系统和网络组件，它们被统称为内核。<sup>[14](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Architecture/Architecture.html)</sup>

BSD层主要源自FreeBSD，提供文件系统、网络、UNIX安全模型、系统调用支持、BSD进程模型以及许多POSIX应用程序接口（API）。<sup>[14](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Architecture/Architecture.html)</sup> Mach管理处理器资源，如CPU使用和内存，处理调度，提供内存保护，并提供以消息传递为中心的基础设施，包括IPC原语、RPC、SMP调度器支持和虚拟内存。<sup>[14](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Architecture/Architecture.html)</sup>

**服务为何被合并。** Mach 3.0最初被构想为一个能够独立运行的通信微内核，I/O、文件系统和网络栈等服务作为用户模式服务器运行。然而在OS X中，Mach与其他内核组件链接进单一内核地址空间，主要是为了性能：链接组件之间的直接调用比在独立任务之间发送消息或进行RPC快得多。苹果称由此产生的模块化结构比宏内核所能允许的更健壮、更可扩展，且没有纯微内核的性能损失。<sup>[4](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Mach/Mach.html)</sup>

## 性能证据

混合内核所权衡的取舍已被直接测量。[犹他大学](https://www.edgepedia.org/zh/university-of-utah)（University of Utah）一项关于Mach 3.0的研究发现，微内核系统的性能问题很大程度上来自维护独立保护域、穿越软件层以及使用语义丰富的IPC机制的成本。允许在性能关键路径上合并保护域，同时在健壮性重要的地方保留边界，使RPC性能提高到三倍，对服务器的Unix系统调用提高20%到一倍，并在大型基准测试上获得4-13%的提升。<sup>[5](https://www.usenix.org/conference/usenix-mach-iii-symposium/kernel-servers-mach-30-implementation-and-performance)</sup> 同一研究指出，过去的微内核开发者一再发现将用户模式代码移入内核的诱惑过于强烈，这表明需要一种允许部分代码位于内核的混合模型。<sup>[5](https://www.usenix.org/conference/usenix-mach-iii-symposium/kernel-servers-mach-30-implementation-and-performance)</sup>

同址放置的成本也有记录。一个更快的MkLinux版本使用了运行在微内核地址空间内内核模式下的同址服务器，这提高了通信效率，但违反了微内核系统的地址空间边界，削弱了安全性和稳定性。<sup>[6](https://os.inf.tu-dresden.de/pubs/sosp97/)</sup> 在比较的另一侧，L4第二代微内核表明，精心构建的微内核不必慢：L4Linux在AIM基准测试中的吞吐量仅比原生Linux低5%，而同址MkLinux的相应损失高出5倍，用户级MkLinux则高出7倍。<sup>[6](https://os.inf.tu-dresden.de/pubs/sosp97/)</sup>

## 当前方向：将代码移出内核

两个旗舰混合内核都在减少在内核模式下运行的第三方代码量。在macOS上，用DriverKit构建的驱动运行于用户空间，在那里它们无法危及系统的安全或稳定性；在macOS 11及更高版本中，如果存在等效的DriverKit方案，内核就不会加载内核扩展（kext）。<sup>[7](https://developer.apple.com/system-extensions/)</sup><sup> • </sup><sup>[15](https://developer.apple.com/documentation/SystemExtensions/implementing-drivers-system-extensions-and-kexts?changes=latest__8)</sup> 用于网络和端点安全的系统扩展同样在没有内核级访问权限的情况下扩展macOS。<sup>[7](https://developer.apple.com/system-extensions/)</sup>

微软已宣布改变Windows驱动的构建和签名方式，提高已签名驱动的认证门槛，并表示预计未来几年内核模式下运行的代码将大幅减少，包括网络、摄像头、USB、打印机和存储驱动，由标准化的Windows驱动以及扩展的内置驱动和应用程序接口（API）集合取代。Windows继续支持第三方内核模式驱动。<sup>[8](https://www.windowscentral.com/microsoft/windows-11/microsoft-is-raising-the-bar-and-making-major-changes-to-how-drivers-are-built-and-verified-on-windows-11-heres-the-important-details)</sup> 框架层反映了同样的划分：Windows驱动框架同时包括内核模式驱动程序框架（KMDF）和用户模式驱动程序框架（UMDF）。<sup>[16](https://learn.microsoft.com/windows-hardware/drivers/wdf/porting-i-o-handling)</sup>

## References

1. [Ferreira (2017). Hybrid Kernels, master thesis, Universidade Nova de Lisboa.](https://run.unl.pt/bitstream/10362/34368/1/Ferreira_2017.pdf)
2. [apple/darwin-xnu, GitHub repository README.](https://github.com/apple/darwin-xnu?ref=developer-insider)
3. [One Windows Kernel, Microsoft Community Hub.](https://techcommunity.microsoft.com/blog/windowsosplatform/one-windows-kernel/267142)
4. [Mach Overview, Apple Kernel Programming Guide (archive).](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Mach/Mach.html)
5. [Lepreau, Hibler, Ford, Law, Orr (1993). In-Kernel Servers on Mach 3.0: Implementation and Performance, USENIX Mach III Symposium.](https://www.usenix.org/conference/usenix-mach-iii-symposium/kernel-servers-mach-30-implementation-and-performance)
6. [Härtig, Hohmuth, Liedtke, Schönberg, Wolter (1997). The Performance of µ-Kernel-Based Systems, SOSP, Dresden University of Technology.](https://os.inf.tu-dresden.de/pubs/sosp97/)
7. [System Extensions, Apple Developer.](https://developer.apple.com/system-extensions/)
8. [Microsoft driver signing and resiliency changes for Windows 11, Windows Central.](https://www.windowscentral.com/microsoft/windows-11/microsoft-is-raising-the-bar-and-making-major-changes-to-how-drivers-are-built-and-verified-on-windows-11-heres-the-important-details)
9. [Windows Kernel-Mode Executive Support Library, Microsoft Learn.](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/windows-kernel-mode-executive-support-library)
10. [Types of Windows Drivers, Microsoft Learn.](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/types-of-windows-drivers)
11. [The Windows NT kernel architecture diagram, USPTO record.](https://ptacts.uspto.gov/ptacts/public-informations/petitions/1554714/download-documents?artifactId=-I8wof5ABIE_atpLKT8KYvp2XFRbCIxEoR2SAa_p_eFR0m_6KoWOUgQ)
12. [Baker (1997). The Windows NT Device Driver Book, bitsavers.](https://www.bitsavers.org/pdf/microsoft/windows_NT_4.0/Baker_-_The_Windows_NT_Device_Driver_Book_1997.pdf)
13. [Microsoft's pivotal Windows NT 3.5 release, Tom's Hardware.](https://www.tomshardware.com/software/windows/microsofts-pivotal-windows-nt-3-5-release-made-it-a-serious-contender-31-years-ago-today)
14. [Kernel Architecture Overview, Apple Kernel Programming Guide (archive).](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Architecture/Architecture.html)
15. [Implementing drivers, system extensions, and kexts, Apple Developer Documentation.](https://developer.apple.com/documentation/SystemExtensions/implementing-drivers-system-extensions-and-kexts?changes=latest__8)
16. [Windows Driver Frameworks, Microsoft Learn.](https://learn.microsoft.com/windows-hardware/drivers/wdf/porting-i-o-handling)

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

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