Checksumming 校验和计算
Data and metadata are checksummed by default, the checksum is calculated before
write and verified after reading the blocks from devices. The whole metadata
block has a checksum stored inline in the b-tree node header, each data block
has a detached checksum stored in the checksum tree.
默认情况下,数据和元数据会进行校验和计算,校验和在写入之前计算,在从设备读取块后进行验证。整个元数据块在 B 树节点头部内联存储有一个校验和,每个数据块在校验和树中有一个独立的校验和存储。
There are several checksum algorithms supported. The default and backward
compatible is crc32c. Since kernel 5.5 there are three more with different
characteristics and trade-offs regarding speed and strength. The following list
may help you to decide which one to select.
支持多种校验算法。默认和向后兼容的是 crc32c。自内核 5.5 开始,还有三种具有不同特性和速度、强度方面的权衡的算法。以下列表可能帮助您决定选择哪种算法。
- CRC32C (32bit digest) CRC32C(32 位摘要)
default, best backward compatibility, very fast, modern CPUs have instruction-level support, not collision-resistant but still good error detection capabilities
默认,最佳向后兼容性,非常快,现代 CPU 具有指令级支持,不具备抗碰撞能力,但仍具有良好的错误检测能力- XXHASH (64bit digest) XXHASH(64 位摘要)
can be used as CRC32C successor, very fast, optimized for modern CPUs utilizing instruction pipelining, good collision resistance and error detection
可用作 CRC32C 的继任者,非常快速,针对利用指令流水线的现代 CPU 进行了优化,具有良好的碰撞抵抗和错误检测能力- SHA256 (256bit digest) SHA256(256 位摘要)
a cryptographic-strength hash, relatively slow but with possible CPU instruction acceleration or specialized hardware cards, FIPS certified and in wide use
一个密码强度很高的哈希函数,相对较慢,但可能具有 CPU 指令加速或专用硬件卡,FIPS 认证并广泛使用- BLAKE2b (256bit digest) BLAKE2b(256 位摘要)
a cryptographic-strength hash, relatively fast with possible CPU acceleration using SIMD extensions, not standardized but based on BLAKE which was a SHA3 finalist, in wide use, the algorithm used is BLAKE2b-256 that’s optimized for 64bit platforms
一个密码强度很高的哈希函数,相对较快,可能使用 SIMD 扩展进行 CPU 加速,没有标准化,但基于 BLAKE,后者是 SHA3 决赛选手之一,广泛使用,所使用的算法是针对 64 位平台进行优化的 BLAKE2b-256
The digest size affects overall size of data block checksums stored in the
filesystem. The metadata blocks have a fixed area up to 256 bits (32 bytes), so
there’s no increase. Each data block has a separate checksum stored, with
additional overhead of the b-tree leaves.
摘要大小会影响文件系统中存储的数据块校验和的整体大小。元数据块有一个固定区域,最多为 256 位(32 字节),因此不会增加。每个数据块都有一个单独存储的校验和,带有 b 树叶子的额外开销。
Approximate relative performance of the algorithms, measured against CRC32C
using implementations on a 11th gen 3.6GHz intel CPU:
算法的大致相对性能,根据在第 11 代 3.6GHz 英特尔 CPU 上实现的 CRC32C 进行测量:
Digest |
Cycles/4KiB 周期/4KiB |
Ratio |
Implementation |
---|---|---|---|
CRC32C |
470 |
1.00 |
CPU instruction, PCL combination |
XXHASH |
870 |
1.9 |
reference impl. 参考实现 |
SHA256 |
7600 |
16 |
libgcrypt |
SHA256 |
8500 |
18 |
openssl |
SHA256 |
8700 |
18 |
botan |
SHA256 |
32000 |
68 |
builtin, CPU instruction 内建,CPU 指令 |
SHA256 |
37000 |
78 |
libsodium |
SHA256 |
78000 |
166 |
builtin, reference impl. 内置,参考实现 |
BLAKE2b |
10000 |
21 |
builtin/AVX2 内置/AVX2 |
BLAKE2b |
10900 |
23 |
libgcrypt |
BLAKE2b |
13500 |
29 |
builtin/SSE41 内置/SSE41 |
BLAKE2b |
13700 |
29 |
libsodium |
BLAKE2b |
14100 |
30 |
openssl |
BLAKE2b |
14500 |
31 |
kcapi |
BLAKE2b |
14500 |
34 |
builtin, reference impl. 内置,参考实现。 |
Many kernels are configured with SHA256 as built-in and not as a module.
The accelerated versions are however provided by the modules and must be loaded
explicitly (modprobe sha256) before mounting the filesystem to make use of
them. You can check in /sys/fs/btrfs/FSID/checksum
which one is used. If you
see sha256-generic, then you may want to unmount and mount the filesystem
again, changing that on a mounted filesystem is not possible.
Check the file /proc/crypto
, when the implementation is built-in, you’d find
许多内核都配置为将 SHA256 作为内置而不是作为模块。然而,加速版本是由模块提供的,必须在挂载文件系统之前显式加载它们(modprobe sha256)才能使用。您可以在 /sys/fs/btrfs/FSID/checksum
中检查使用的是哪个版本。如果看到 sha256-generic,则可能需要卸载并重新挂载文件系统,无法在已挂载的文件系统上更改。当实现内置时,请检查文件 /proc/crypto
,您会发现
name : sha256
driver : sha256-generic
module : kernel
priority : 100
...
while accelerated implementation is e.g.
而加速实现例如
name : sha256
driver : sha256-avx2
module : sha256_ssse3
priority : 170
...