Skip to content

Commit f4eac65

Browse files
committed
ops/qemu-kvm: TCG, binfmt
1 parent d8cd6f1 commit f4eac65

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

docs/ops/virtualization/qemu-kvm.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,23 @@ QEMU/KVM 是 Linux 服务器上常用的虚拟化方案。其分为运行在用
1616

1717
QEMU(Quick Emulator)是一个开源的虚拟化软件,它通过动态二进制翻译来模拟 CPU,并提供一系列的硬件模型,可以模拟多种外设硬件。QEMU 可以在没有硬件加速的情况下独立运行,但这样其中的 CPU 部分是模拟指令的执行,性能低下。
1818

19+
!!! note "QEMU TCG"
20+
21+
QEMU 内部使用 TCG(Tiny Code Generator)作为其模拟器,TCG 会将原始指令转换为 TCG 内部的 op,经过简单的优化后转换为主机指令并执行。TCG 不是专门为性能优化的,因此使用 TCG 运行程序或操作系统会有较大的性能损失。
22+
23+
对于跨架构系统级模拟(例如 x86 下运行 aarch64 的操作系统),目前 QEMU 基本上是唯一的通用方案。而如果需求只是运行用户态程序(例如在其他指令集下运行 x86 的游戏),那么目前有一些更快的方案:
24+
25+
- [Box86](https://github.com/ptitseb/box86) 和 [Box64](https://github.com/ptitseb/box64):在 ARM 上运行 x86(和 AMD64)的应用程序。
26+
- [FEX](https://github.com/FEX-Emu/FEX):同样也是在 ARM 上运行 x86 的程序。
27+
1928
此外 QEMU 也可以仅用于 CPU 指令和系统调用的翻译,不模拟硬件模型,这种模式称为 User Mode。主要用于运行不同于宿主系统 CPU 指令集的用户态二进制程序。
2029

30+
!!! note "binfmt_misc"
31+
32+
[binfmt_misc](https://docs.kernel.org/admin-guide/binfmt-misc.html) 是内核提供的运行非原生程序的方案——程序使用 binfmt_misc 注册自己能够处理的程序特征(例如开头是 `MZ` 的话,那么就是 Windows PE 程序),内核在遇到自己无法运行的程序的时候,就会查询 binfmt_misc。该功能对应的挂载点是 `/proc/sys/fs/binfmt_misc/`。
33+
34+
安装 `qemu-user-binfmt` 即可在 binfmt_misc 注册所有 QEMU 用户模式支持的架构。`systemd-binfmt.service` 会在启动时检查 [binfmt.d.5][binfmt.d.5] 中的目录,并进行信息注册。
35+
2136
### KVM
2237

2338
KVM(Kernel-based Virtual Machine)是一种基于 Linux 内核的开源虚拟化解决方案。KVM 将 Linux 转变成一个虚拟机监视器(Hypervisor)。它利用了现代处理器中的硬件虚拟化支持(例如 Intel VT-x 或 AMD-V),以实现高性能的虚拟化。它专注于以最小的开销在 Linux 上提供安全和隔离的虚拟环境,同时维持接近原生的性能。它向用户空间提供了虚拟 CPU 和内存子系统的配置和执行控制相关接口,但 KVM 不包含硬件模型,不能独立构成虚拟机。

includes/man.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
[adduser.conf.5]: https://manpages.debian.org/stable/adduser/adduser.conf.5.en.html
4747
[apt.conf.5]: https://manpages.debian.org/unstable/apt/apt.conf.5.en.html
4848
[apt_preferences.5]: https://manpages.debian.org/unstable/apt/apt_preferences.5.en.html
49+
[binfmt.d.5]: https://man7.org/linux/man-pages/man5/binfmt.d.5.html
4950
[deluser.conf.5]: https://manpages.debian.org/stable/adduser/deluser.conf.5.en.html
5051
[fstab.5]: https://man7.org/linux/man-pages/man5/fstab.5.html
5152
[gai.conf.5]: https://man7.org/linux/man-pages/man5/gai.conf.5.html

0 commit comments

Comments
 (0)