# XFS

**XFS** 是一种 64 位[日志文件系统](https://www.edgepedia.org/zh/journaling-file-system)，最初由硅谷图形公司（Silicon Graphics, Inc.，SGI）为其 IRIX 操作系统开发，后来移植到 Linux，现已成为红帽企业版 Linux 的默认文件系统。<sup>[1](https://www.scs.stanford.edu/nyu/01fa/sched/xfs.pdf)</sup><sup> • </sup><sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup> 它从一开始就为可扩展性而设计，使用 B+ 树取代传统的线性文件系统结构，用分配组实现并行，用预写日志实现快速崩溃恢复。<sup>[1](https://www.scs.stanford.edu/nyu/01fa/sched/xfs.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 起源 | 由 SGI 为 IRIX 设计；设计于 1993 年 10 月在内部传阅，1994 年 12 月在 IRIX 5.3 中交付客户<sup>[3](https://xfs.org/docs/xfsdocs-xml-dev/XFS_User_Guide/tmp/en-US/html/ch01s02.html)</sup><sup> • </sup><sup>[1](https://www.scs.stanford.edu/nyu/01fa/sched/xfs.pdf)</sup> |
| 进入 Linux | 由 SGI 移植（USENIX ATC 2000）；2001 年 5 月 1 日发布面向 Linux 2.4 的 XFS 1.0<sup>[4](https://www.usenix.org/conference/2000-usenix-annual-technical-conference/porting-sgi-xfs-file-system-linux)</sup><sup> • </sup><sup>[5](https://lwn.net/2001/0503/a/xfs-1.0.php3)</sup> |
| 默认状态 | 红帽企业版 Linux 的默认文件系统（自 RHEL 7 起）<sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup> |
| 容量限制 | RHEL 10 支持的文件系统大小最高达 1024 TiB；RHEL 7.0 GA 支持 500 TB，稀疏文件的最大文件偏移量为 8 EB<sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup><sup> • </sup><sup>[6](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/pdf/performance_tuning_guide/index)</sup> |
| 核心结构 | 每个分配组最大 1 TB；B+ 树用于空闲空间、目录、区段映射和索引节点跟踪<sup>[7](https://www.kernel.org/pub/linux/utils/fs/xfs/docs/xfs_filesystem_structure.pdf)</sup><sup> • </sup><sup>[1](https://www.scs.stanford.edu/nyu/01fa/sched/xfs.pdf)</sup> |
| 完整性 | 元数据日志；自版本 5（2012 年）起，采用自描述元数据，每个对象带 CRC32c 校验和；不对数据做校验和<sup>[8](https://docs.kernel.org/filesystems/xfs/xfs-online-fsck-design.html)</sup><sup> • </sup><sup>[9](https://www.usenix.org/system/files/fast26-gupta.pdf)</sup> |
| 调整大小 | 支持在线扩容；没有收缩 XFS 文件系统的工具<sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup> |

## 历史

最初的 XFS 设计于 1993 年 10 月在 SGI 内部传阅。<sup>[3](https://xfs.org/docs/xfsdocs-xml-dev/XFS_User_Guide/tmp/en-US/html/ch01s02.html)</sup> SGI 的设计论文将 XFS 描述为一种通用 Unix 文件系统，既可在内存 16 兆字节、单磁盘的工作站上运行，也可在内存数吉字节、磁盘容量数太字节的大型 SMP 服务器上运行。<sup>[1](https://www.scs.stanford.edu/nyu/01fa/sched/xfs.pdf)</sup> XFS 于 1994 年 12 月在 IRIX 5.3 的一个版本中交付客户，并从 1996 年初的 IRIX 6.2 开始成为所有 SGI 系统上安装的默认文件系统。<sup>[1](https://www.scs.stanford.edu/nyu/01fa/sched/xfs.pdf)</sup>

**移植到 Linux。** SGI 将 XFS 移植到 Linux 操作系统，以解决传统 Linux 文件系统的局限，并在 2000 年 USENIX 年度技术会议上展示了这项工作；论文涵盖文件系统接口、XFS 中的缓冲区缓存、卷管理层次，以及 SGI 为此次移植所做的法律障碍审查。<sup>[4](https://www.usenix.org/conference/2000-usenix-annual-technical-conference/porting-sgi-xfs-file-system-linux)</sup> 2001 年 5 月 1 日，SGI 发布了面向 Linux 2.4 内核的 XFS 1.0，免费提供，具备快速崩溃恢复、直接 I/O、空间预分配、事务记录的配额、访问控制列表、扩展属性，以及与 IRIX XFS 文件系统的磁盘格式兼容性。<sup>[5](https://lwn.net/2001/0503/a/xfs-1.0.php3)</sup> Linux 实现至今仍与 IRIX 版本保持磁盘格式兼容。<sup>[10](https://www.kernel.org/doc/html/latest/admin-guide/xfs.html?highlight=fstrim)</sup> 红帽从 RHEL 7 开始将 XFS 设为 RHEL 的默认文件系统。<sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup>

## 架构

**分配组。** XFS 文件系统被划分为若干大小相等的块，称为分配组（AG）。每个 AG 最大可达 1 太字节（512 字节 × 2<sup>31</sup>），与底层设备的扇区大小无关，并维护自己的空间使用、索引节点分配和次级元数据，因此几乎可以把它看作一个独立的文件系统。<sup>[7](https://www.kernel.org/pub/linux/utils/fs/xfs/docs/xfs_filesystem_structure.pdf)</sup> 多个 AG 使 XFS 能够并行处理大多数操作，而不会随着并发访问数量的增加而降低性能。<sup>[7](https://www.kernel.org/pub/linux/utils/fs/xfs/docs/xfs_filesystem_structure.pdf)</sup> 第一个 AG 保留的唯一全局信息是整个文件系统的空闲空间和索引节点总数；启用惰性超级块计数功能后，这些信息仅在文件系统正常卸载时才更新到磁盘。<sup>[7](https://www.kernel.org/pub/linux/utils/fs/xfs/docs/xfs_filesystem_structure.pdf)</sup>

**B+ 树。** XFS 广泛使用 B+ 树：用于跟踪空闲区段而非位图，用于索引目录项而非线性查找结构，用于管理超出索引节点内直接指针所能容纳范围的文件区段映射，以及用于跟踪散布在文件系统中的动态分配索引节点。<sup>[1](https://www.scs.stanford.edu/nyu/01fa/sched/xfs.pdf)</sup> 在每个分配组内，空闲空间由两棵 B+ 树跟踪，一棵按块号索引，另一棵按空闲区段大小索引，因此 XFS 可以快速找到给定块附近或给定大小的空闲空间。<sup>[11](https://kernel.googlesource.com/pub/scm/fs/xfs/xfs-documentation/%2B/refs/heads/master/design/XFS_Filesystem_Structure/allocation_groups.asciidoc)</sup>

几乎所有 XFS 元数据都是动态分配的。唯一固定位置的元数据是分配组头、超级块（SB）、AGF、AGFL 和 AGI；所有其他元数据结构都必须通过遍历文件系统结构来发现。<sup>[12](https://github.com/torvalds/linux/blob/master/Documentation/filesystems/xfs/xfs-self-describing-metadata.rst)</sup>

## 日志

XFS 使用预写日志来确保对文件系统元数据的更改具有原子性和可恢复性。<sup>[13](https://code.googlesource.com/linux/torvalds/linux/%2B/78273df7f646f8daf2604ec714bea0897cd03aae/Documentation/filesystems/xfs/xfs-delayed-logging-design.rst)</sup> 默认情况下，所有高层事务都是异步的：事务提交并不保证修改已到达稳定存储，不过日志子系统提供全局顺序保证，因此如果某项更改在恢复后仍然存在，那么所有更早提交的元数据更改也都会存在。需要同步点的操作（如 fsync）会强制刷写日志。<sup>[13](https://code.googlesource.com/linux/torvalds/linux/%2B/78273df7f646f8daf2604ec714bea0897cd03aae/Documentation/filesystems/xfs/xfs-delayed-logging-design.rst)</sup>

日志在磁盘上要么作为文件系统内保留的块区段存在，要么作为单独的日志设备存在。<sup>[14](https://kernel.googlesource.com/pub/scm/fs/xfs/xfs-documentation/%2B/14bbbf56779842217982894a4499f6cb212f655f/design/XFS_Filesystem_Structure/journaling_log.asciidoc)</sup> 由于对同一对象的重复操作会在日志缓冲区中留下许多过时副本，XFS 实现了延迟日志，在将事务更改写入日志之前先在内存中累积；其既定目标是在不改变磁盘格式的前提下，将写入日志的元数据量减少至少一个数量级。<sup>[13](https://code.googlesource.com/linux/torvalds/linux/%2B/78273df7f646f8daf2604ec714bea0897cd03aae/Documentation/filesystems/xfs/xfs-delayed-logging-design.rst)</sup> 默认有 8 个日志缓冲区，每个 32 kB，可通过挂载选项增加到 256 kB。<sup>[13](https://code.googlesource.com/linux/torvalds/linux/%2B/78273df7f646f8daf2604ec714bea0897cd03aae/Documentation/filesystems/xfs/xfs-delayed-logging-design.rst)</sup> 配额元数据本身就是一等公民，是一种日志化的元数据对象，因此配额系统在崩溃后无需漫长的一致性检查即可保持一致。<sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup>

## 元数据完整性与自描述元数据

从 2012 年的 XFS 版本 5 开始，几乎所有磁盘块头的格式都经过更新，以记录魔数、校验和、UUID、所有者代码、块的磁盘地址和日志序列号。当从磁盘加载块缓冲区时，这些字段确认该块属于当前文件系统，并且位于其应在的地址，这使检查工具能够忽略不属于此处的所谓元数据，并使文件系统能够检测丢失的写入。<sup>[8](https://docs.kernel.org/filesystems/xfs/xfs-online-fsck-design.html)</sup> 自 Linux 3.15（2014 年）起，XFS 支持自描述元数据，包括保护超级块、索引节点、目录和分配组头等结构免受静默损坏的每对象 crc32 校验和。<sup>[9](https://www.usenix.org/system/files/fast26-gupta.pdf)</sup> 选择 CRC32c 是因为 XFS 元数据块长度不超过 64 kB，因此 32 位 CRC 足以检测多位错误。<sup>[15](https://docs.kernel.org/6.11/filesystems/xfs/xfs-self-describing-metadata.html)</sup>

XFS 不对文件数据块做校验和；只有元数据在文件系统层面进行验证。<sup>[9](https://www.usenix.org/system/files/fast26-gupta.pdf)</sup> 当 XFS 遇到不可恢复的元数据错误时，它会关闭文件系统并返回 `EFSCORRUPTED` 错误，它还支持可配置的错误处理。<sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup> 较旧的 V4 磁盘格式缺乏元数据校验和、强化验证以及 2038 年之后的时间戳，已被弃用：可以在内核构建时禁用挂载 V4 文件系统的功能（自 2025 年 9 月起默认不允许挂载），并且将从 2030 年 9 月起从代码库中完全移除支持。<sup>[10](https://www.kernel.org/doc/html/latest/admin-guide/xfs.html?highlight=fstrim)</sup>

## 检查与修复

Linux 上的 XFS 历来依赖离线工具 `xfs_repair`；更早的检查器 `xfs_check` 只能在未挂载的文件系统上运行，已被弃用。<sup>[8](https://docs.kernel.org/filesystems/xfs/xfs-online-fsck-design.html)</sup> 在线 fsck 设计由三部分组成：验证元数据的内核驻留代码、修复元数据的内核驻留代码，以及用户空间驱动程序 `xfs_scrub`，它在七个工作阶段中协调运行中文件系统的检查和修复。<sup>[8](https://docs.kernel.org/filesystems/xfs/xfs-online-fsck-design.html)</sup> 由于持有目录、扩展属性及类似元数据的文件分支可能消耗与整个文件系统一样多的空间，在线修复会在隐藏的临时文件中暂存新结构，然后原子地交换所有文件分支映射以提交修复。<sup>[8](https://docs.kernel.org/filesystems/xfs/xfs-online-fsck-design.html)</sup> 在线 fsck 并非离线修复的完全替代品：它必须遵循与常规文件系统操作相同的锁定规则，完整运行可能比离线检查耗时更长。<sup>[8](https://docs.kernel.org/filesystems/xfs/xfs-online-fsck-design.html)</sup>

在此机制基础上，Linux 7.0 为 XFS 格式的驱动器增加了自动自愈系统，其中 `xfs_healer` 守护进程在后台运行，可以自动发起有针对性的修复。<sup>[16](https://www.pcgamer.com/software/linux/the-new-linux-7-0-kernel-is-here-and-as-always-its-all-about-lots-of-little-improvements-rather-than-one-significant-update/)</sup>

## 性能及与 ext4 的比较

红帽的指导原则是：除非有特定用例需要 ext4，否则一般使用 XFS。XFS 在高带宽（大于 200 MB/s）和超过 1000 IOPS 的环境中表现最佳，尤其是在处理数百兆字节的大文件和高 I/O 并发时；与 ext4 相比，它在元数据操作上消耗更多 CPU 资源，且不支持收缩。<sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup> 红帽还指出，XFS 在单线程、元数据密集型工作负载下性能相对较低。<sup>[17](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/pdf/managing_file_systems/getting-started-with-xfs_managing-file-systems)</sup>

独立基准测试表明，情况因访问模式而异。在 Phoronix 于配备 PCIe 5.0 NVMe SSD 的 AMD EPYC 都灵服务器上进行的 Linux 7.0 文件系统测试中，XFS 总体领先，在 4 KB 随机写入中通常最快，在 2 MB 顺序写入中大幅领先，而 ext4 在若干缓冲和直接随机读取用例中获胜。<sup>[18](https://www.phoronix.com/review/linux-70-filesystems/2)</sup> 具体与 ext4 相比，XFS 支持更大的最大文件系统大小（红帽文档中为 1024 TiB 对 50 TiB），使用动态索引节点分配而非 ext4 固定的 2<sup>32</sup> 索引节点上限，并且在遇到不可恢复的元数据错误时关闭，而 ext4 默认继续操作。<sup>[2](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)</sup>

## 近期发展

当前 XFS 工作的两个方向旨在解决其长期存在的完整性缺口。一篇 USENIX FAST '26 论文描述了文件系统保护信息（Filesystem Protection Information，FS-PI），其中文件系统在支持 PI 的硬件上直接生成并验证完整性元数据；在 XFS 中，FS-PI 引入了原生数据校验和，首次扩展了数据完整性保证。<sup>[19](https://www.usenix.org/conference/fast26/presentation/gupta)</sup> 另外，在线检查和修复基础设施已与自动系统管理相结合，使 XFS 的自主自愈最大限度地提高服务可用性。<sup>[8](https://docs.kernel.org/filesystems/xfs/xfs-online-fsck-design.html)</sup>

## References

1. [XFS: A high-performance journaling file system (SGI design paper)](https://www.scs.stanford.edu/nyu/01fa/sched/xfs.pdf)
2. [Chapter 1. Overview of available file systems, Managing file systems, Red Hat Enterprise Linux 10](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/managing_file_systems/overview-of-available-file-systems)
3. [A Brief History of XFS, XFS User Guide, xfs.org](https://xfs.org/docs/xfsdocs-xml-dev/XFS_User_Guide/tmp/en-US/html/ch01s02.html)
4. [Porting the SGI XFS File System to Linux, USENIX ATC 2000](https://www.usenix.org/conference/2000-usenix-annual-technical-conference/porting-sgi-xfs-file-system-linux)
5. [SGI announces XFS filesystem 1.0 release, LWN.net (May 1, 2001)](https://lwn.net/2001/0503/a/xfs-1.0.php3)
6. [Performance Tuning Guide, Red Hat Enterprise Linux 7](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/pdf/performance_tuning_guide/index)
7. [XFS Algorithms & Data Structures, kernel.org](https://www.kernel.org/pub/linux/utils/fs/xfs/docs/xfs_filesystem_structure.pdf)
8. [XFS Online Fsck Design, The Linux Kernel documentation](https://docs.kernel.org/filesystems/xfs/xfs-online-fsck-design.html)
9. [Advancing Data Integrity in Linux (FAST '26 paper PDF), USENIX](https://www.usenix.org/system/files/fast26-gupta.pdf)
10. [The SGI XFS Filesystem, The Linux Kernel documentation](https://www.kernel.org/doc/html/latest/admin-guide/xfs.html?highlight=fstrim)
11. [XFS Filesystem Structure: Allocation Groups, xfs-documentation repository](https://kernel.googlesource.com/pub/scm/fs/xfs/xfs-documentation/%2B/refs/heads/master/design/XFS_Filesystem_Structure/allocation_groups.asciidoc)
12. [XFS Self Describing Metadata, Linux kernel documentation (torvalds/linux)](https://github.com/torvalds/linux/blob/master/Documentation/filesystems/xfs/xfs-self-describing-metadata.rst)
13. [XFS Logging Design, Linux kernel documentation](https://code.googlesource.com/linux/torvalds/linux/%2B/78273df7f646f8daf2604ec714bea0897cd03aae/Documentation/filesystems/xfs/xfs-delayed-logging-design.rst)
14. [XFS Filesystem Structure: Journaling Log, xfs-documentation repository](https://kernel.googlesource.com/pub/scm/fs/xfs/xfs-documentation/%2B/14bbbf56779842217982894a4499f6cb212f655f/design/XFS_Filesystem_Structure/journaling_log.asciidoc)
15. [XFS Self Describing Metadata, Linux 6.11 kernel documentation](https://docs.kernel.org/6.11/filesystems/xfs/xfs-self-describing-metadata.html)
16. [The new Linux 7.0 kernel is here, PC Gamer](https://www.pcgamer.com/software/linux/the-new-linux-7-0-kernel-is-here-and-as-always-its-all-about-lots-of-little-improvements-rather-than-one-significant-update/)
17. [Getting started with XFS, Managing file systems, Red Hat Enterprise Linux 9](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/pdf/managing_file_systems/getting-started-with-xfs_managing-file-systems)
18. [Linux 7.0 File-System Benchmarks With XFS Leading The Way, Phoronix](https://www.phoronix.com/review/linux-70-filesystems/2)
19. [Advancing Data Integrity in Linux, USENIX FAST '26](https://www.usenix.org/conference/fast26/presentation/gupta)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/xfs

English original: https://www.edgepedia.org/xfs
