Defragmentation 磁盘碎片整理 

Defragmentation of files is supposed to make the layout of the file extents to be more linear or at least coalesce the file extents into larger ones that can be stored on the device more efficiently. The reason there’s a need for defragmentation stems from the COW design that BTRFS is built on and is inherent. The fragmentation is caused by rewrites of the same file data in-place, that has to be handled by creating a new copy that may lie on a distant location on the physical device. Fragmentation is the worst problem on rotational hard disks due to the delay caused by moving the drive heads to the distant location. With the modern seek-less devices it’s not a problem though it may still make sense because of reduced size of the metadata that’s needed to track the scattered extents.
文件的碎片整理应该使文件范围的布局更线性,或者至少将文件范围合并为更大的范围,以便更有效地存储在设备上。需要进行碎片整理的原因源于 BTRFS 构建在 COW 设计之上并且是固有的。碎片化是由于就地重写相同文件数据而引起的,必须通过创建一个可能位于物理设备上的远程位置的新副本来处理。碎片化是由于将驱动器磁头移动到远程位置而引起的延迟,是旋转硬盘上最严重的问题。对于现代无寻道设备来说,这不是问题,尽管由于需要跟踪分散范围而仍然有意义。

File data that are in use can be safely defragmented because the whole process happens inside the page cache, that is the central point caching the file data and takes care of synchronization. Once a filesystem sync or flush is started (either manually or automatically) all the dirty data get written to the devices. This however reduces the chances to find optimal layout as the writes happen together with other data and the result depends on the remaining free space layout and fragmentation.
正在使用的文件数据可以安全地进行碎片整理,因为整个过程发生在页面缓存内部,即缓存文件数据的中心点并负责同步。一旦文件系统同步或刷新启动(无论是手动还是自动),所有脏数据都会被写入设备。然而,这会降低找到最佳布局的机会,因为写操作与其他数据同时发生,结果取决于剩余的空闲空间布局和碎片化情况。

Warning 警告

Defragmentation does not preserve extent sharing, e.g. files created by cp --reflink or existing on multiple snapshots. Due to that the data space consumption may increase.
碎片整理不会保留范围共享,例如由 cp --reflink 创建的文件或存在于多个快照中的文件。因此,数据空间消耗可能会增加。

Defragmentation can be started together with compression on the given range, and takes precedence over per-file compression property or mount options. See command btrfs filesystem defrag.
可以在给定范围上同时启动碎片整理和压缩,并优先于每个文件的压缩属性或挂载选项。请参阅命令 btrfs filesystem defrag。