Scrub 擦洗
Scrub is a pass over all filesystem data and metadata and verifying the
checksums. If a valid copy is available (replicated block group profiles) then
the damaged one is repaired. All copies of the replicated profiles are validated.
擦洗是对所有文件系统数据和元数据进行遍历,并验证校验和。如果存在有效副本(复制的块组配置文件),则会修复损坏的副本。所有复制的配置文件的副本都会被验证。
Note 注意
Scrub is not a filesystem checker (fsck) and does not verify nor repair
structural damage in the filesystem. It really only checks checksums of data
and tree blocks, it doesn’t ensure the content of tree blocks is valid and
consistent. There’s some validation performed when metadata blocks are read
from disk (Tree checker) but it’s not extensive and cannot substitute
full btrfs-check(8) run.
擦洗不是文件系统检查器(fsck),不会验证或修复文件系统中的结构损坏。它实际上只检查数据和树块的校验和,不确保树块的内容是有效和一致的。当从磁盘读取元数据块时会执行一些验证(树检查器),但这并不全面,不能替代完整的 btrfs-check(8)运行。
The user is supposed to run it manually or via a periodic system service. The
recommended period is a month but it could be less. The estimated device bandwidth
utilization is about 80% on an idle filesystem.
用户应该手动运行它或通过定期系统服务运行。推荐的周期是一个月,但也可以更短。估计设备带宽利用率在空闲文件系统上约为 80%。
The scrubbing status is recorded in /var/lib/btrfs/
in textual files named
scrub.status.UUID for a filesystem identified by the given UUID. (Progress
state is communicated through a named pipe in file scrub.progress.UUID in the
same directory.) The status file is updated every 5 seconds. A resumed scrub
will continue from the last saved position.
擦洗状态记录在名为 scrub.status.UUID 的文本文件中,用于由给定 UUID 标识的文件系统。 (进度状态通过同一目录中的名为 scrub.progress.UUID 的命名管道进行通信。)状态文件每 5 秒更新一次。恢复的擦洗将从上次保存的位置继续。
Scrub can be started only on a mounted filesystem, though it’s possible to
scrub only a selected device. See btrfs scrub start for more.
只能在已挂载的文件系统上启动擦洗,尽管可以仅擦洗选定的设备。有关更多信息,请参阅 btrfs scrub start。
Bandwidth and IO limiting
带宽和 IO 限制
Note 注意
The ionice(1) may not be generally supported by all IO schedulers and
the options to btrfs scrub start may not work as expected.
ionice(1) 可能不被所有 IO 调度程序普遍支持,而 btrfs scrub start 的选项可能不会按预期工作。
In the past when the CFQ IO scheduler was generally used
the ionice(1) syscalls set the priority to idle so the IO would not
interfere with regular IO. Since the kernel 5.0 the CFQ is not available.
在过去,当 CFQ IO 调度程序通常被使用时,ionice(1)系统调用将优先级设置为空闲,因此 IO 不会干扰常规 IO。自内核 5.0 以来,CFQ 不再可用。
The IO scheduler known to support that is BFQ, but first read the
documentation before using it!
已知支持该功能的 IO 调度器是 BFQ,但在使用之前请先阅读文档!
For other commonly used schedulers like mq-deadline it’s recommended to use
cgroup2 IO controller which could be managed by e.g. systemd
(documented in systemd.resource-control
). However, starting scrub like that
is not yet completely straightforward. The IO controller must know the physical
device of the filesystem and create a slice so all processes started from that
belong to the same accounting group.
对于其他常用的调度器,如 mq-deadline,建议使用 cgroup2 IO 控制器,可以由例如 systemd 进行管理(在 systemd.resource-control
中有文档记录)。然而,像这样开始扫描还不是完全直接的。IO 控制器必须知道文件系统的物理设备并创建一个切片,以便所有从该切片启动的进程都属于同一会计组。
$ systemd-run -p "IOReadBandwidthMax=/dev/sdx 10M" btrfs scrub start -B /
Since linux 5.14 it’s possible to set the per-device bandwidth limits in a
BTRFS-specific way using files /sys/fs/btrfs/FSID/devinfo/DEVID/scrub_speed_max
.
This setting is not persistent, lasts until the filesystem is unmounted.
Currently set limits can be displayed by command btrfs scrub
limit.
自 Linux 5.14 以来,可以使用文件 /sys/fs/btrfs/FSID/devinfo/DEVID/scrub_speed_max
以 BTRFS 特定的方式设置每个设备的带宽限制。此设置不是持久的,持续到文件系统卸载。当前设置的限制可以通过命令 btrfs scrub limit 显示。
$ echo 100m > /sys/fs/btrfs/9b5fd16e-1b64-4f9b-904a-74e74c0bbadc/devinfo/1/scrub_speed_max
$ btrfs scrub limit /
UUID: 9b5fd16e-1b64-4f9b-904a-74e74c0bbadc
Id Limit Path
-- --------- --------
1 100.00MiB /dev/sdx