ReFS 上的块克隆Block cloning on ReFS

适用于:Windows Server 2019、Windows Server 2016、Windows Server(半年频道)Applies to: Windows Server 2019, Windows Server 2016, Windows Server (Semi-Annual Channel)

块克隆指示文件系统代表应用程序复制某个范围的文件字节,其中,目标文件可与源文件相同或不同。Block cloning instructs the file system to copy a range of file bytes on behalf of an application, where the destination file may be the same as, or different from, the source file. 遗憾的是,复制操作的系统成本较高,因为它们会触发很耗费资源的对基础物理数据的读取和写入。Copy operations, unfortunately, are expensive, since they trigger expensive read and writes to the underlying, physical data.

不过,ReFS 中的块克隆会以低成本的元数据操作形式执行复制,而不是对文件数据执行读取操作。Block cloning in ReFS, however, performs copies as a low-cost metadata operation rather than reading from and writing to file data. 因为 ReFS 支持多个文件共享相同的逻辑群集(卷上的物理位置),所以,复制操作仅需将文件的某个区域重新映射到单独的物理位置,并且将成本较高的物理操作转换为快速的逻辑操作。Because ReFS enables multiple files to share the same logical clusters (physical locations on a volume), copy operations only need to remap a region of a file to a separate physical location, converting an expensive, physical operation to a quick, logical one. 这使得能够更快地完成复制操作,并且生成与基本存储的更少 I/O。This allows copies to complete faster and generate less I/O to the underlying storage. 这一改进还会改善虚拟化工作负载,因为在使用块克隆操作时 .vhdx 检查点合并操作速度会明显加快。This improvement also benefits virtualization workloads, as .vhdx checkpoint merge operations are dramatically accelerated when using block clone operations. 此外,因为多个文件可以共享相同逻辑群集,所以,完全相同的数据不会实际存储多次,从而可提高存储容量。Additionally, because multiple files can share the same logical clusters, identical data isn't physically stored multiple times, improving storage capacity.

工作原理How it works

ReFS 上的块克隆将文件数据操作转换为元数据操作。Block cloning on ReFS converts a file data operation into a metadata operation. 为了实现此优化,ReFS 将引用计数引入其用于已复制区域的元数据中。In order to make this optimization, ReFS introduces reference counts into its metadata for copied regions. 此引用计数记录引用相同物理区域的不同文件区域的数目。This reference count records the number of distinct file regions that reference the same physical regions. 这允许多个文件共享相同的物理数据:This allows multiple files to share the same physical data:

在多个文件引用相同区域时显示引用计数更新

通过为每个逻辑群集保留引用计数,ReFS 不会破坏文件之间的隔离:写入共享区域会触发按写入分配的机制,在该机制中,ReFS 会为传入的写入分配新区域。By keeping a reference count for each logical cluster, ReFS doesn't break the isolation between files: writes to shared regions trigger an allocate-on-write mechanism, where ReFS allocates a new region for the incoming write. 该机制会保留共享逻辑群集的完整性。This mechanism preserves the integrity of the shared logical clusters.

示例Example

假定有两个文件,分别是 X 和 Y,每个文件都由三个区域构成,而每个区域都映射到单独的逻辑群集。Suppose there are two files, X and Y, where each file is composed of three regions, and each region maps to separate logical clusters.

两个文件分别具有三个不同区域,它们全都映射到引用计数为 1 的区域

现在,假定对于要按区域 E 的偏移量复制的区域 A 和 B,某一应用程序发出从文件 X 到文件 Y 的块克隆操作。将生成以下文件系统状态:Now suppose an application issues a block clone operation from File X to File Y, for regions A and B to be copied at the offset of region E. The following file system state would result:

引用计数对于块克隆区域显示 2

该文件系统状态展示块克隆区域的成功复制。This file system state reveals a successful duplication of the block cloned region. 因为 ReFS 通过仅更新 VCN 到 LCN 映射来执行此复制操作,所以,既不会读取物理数据,也不会覆盖文件 Y 中的物理数据。Because ReFS performs this copy operation by only updating VCN to LCN mappings, no physical data was read, nor was the physical data in File Y overwritten. 文件 X 和 Y 现在共享表中的引用计数所反映的逻辑群集。File X and Y now share logical clusters, reflected by the reference counts in the table. 由于没有实际复制数据,因此 ReFS 会减少卷上的容量消耗。Because no data was physically copied, ReFS reduces capacity consumption on the volume.

现在,假定该应用程序尝试覆盖文件 X 中的区域 A。ReFS 将复制共享区域,相应更新引用计数,并且执行对新复制区域的传入写入。Now suppose the application attempts to overwrite region A in File X. ReFS will duplicate the shared region, update the reference counts appropriately, and perform the incoming write to the newly duplicated region. 这确保保留文件之间的隔离。This ensures that isolation between the files is preserved.

通过写入新区域 G 和更新引用计数保留的隔离

在修改写入后,区域 B 仍由两个文件共享。After the modifying write, region B is still shared by both files. 请注意,如果区域 A 大于某个群集,则只会复制已修改的群集,并且剩余部分会保持共享。Note that if region A were larger than a cluster, only the modified cluster would have been duplicated, and the remaining portion would have remained shared.

功能限制和备注Functionality restrictions and remarks

  • 源和目标区域必须在某个群集边界开始和结束。The source and destination region must begin and end at a cluster boundary.
  • 克隆的区域必须在长度上小于 4GB。The cloned region must be less than 4GB in length.
  • 可映射到相同物理区域的最大文件区域数目为 8175。The maximum number of file regions that can map to the same physical region is 8175.
  • 目标区域不得超过文件的末尾。The destination region must not extend past the end of the file. 如果应用程序希望扩展具有克隆数据的目标,则它必须首先调用 SetEndOfFileIf the application wishes to extend the destination with cloned data, it must first call SetEndOfFile.
  • 如果源和目标区域处于用一个文件中,则它们不得重叠。If the source and destination regions are in the same file, they must not overlap. (应用程序可通过将块克隆操作拆分为多个不再重叠的块克隆来继续操作。)(The application may be able to proceed by splitting up the block clone operation into multiple block clones that no longer overlap).
  • 源文件和目标文件必须处于相同的 ReFS 卷上。The source and destination files must be on the same ReFS volume.
  • 源文件和目标文件必须具有相同的 完整性流 设置。The source and destination files must have the same Integrity Streams setting.
  • 如果源文件是稀疏的,则目标文件必须也是稀疏的。If the source file is sparse, the destination file must also be sparse.
  • 块克隆操作将破坏共享机会锁(也称作 2 级机会锁)。The block clone operation will break Shared Opportunistic Locks (also know as Level 2 Opportunistic Locks).
  • ReFS 卷必须已使用 Windows Server 2016 进行了格式化;此外,如果正在使用故障转移群集,则在格式化时群集功能级别必须已是 Windows Server 2016 或更高版本。The ReFS volume must have been formatted with Windows Server 2016, and if Failover Clustering is in use, the Clustering Functional Level must have been Windows Server 2016 or later at format time.

其他参考Additional References