BTRFS raid-1:哪个设备读取?

Ale*_*huk 5 btrfs

我有一个具有以下配置的 raid-1:

$ btrfs fi show
Total devices 2 FS bytes used 203.31GiB
        devid    1 size 224.00GiB used 206.03GiB path /dev/sda
        devid    2 size 224.00GiB used 206.03GiB path /dev/mmcblk0p4
Run Code Online (Sandbox Code Playgroud)

/dev/mmcblk0p4快又/dev/sda

什么决定了哪个设备将获得 IO 读取,有没有办法控制它?

osg*_*sgx 5

从 Linux 内核的 5.0 版本开始,有一个代码来决定将使用镜像阵列的哪一部分。它使用进程的 pid 来选择可用的条带之一:

https://elixir.bootlin.com/linux/v5.0/source/fs/btrfs/volumes.c

static int find_live_mirror(struct btrfs_fs_info *fs_info, ...
{ ...
    if (map->type & BTRFS_BLOCK_GROUP_RAID10)
        num_stripes = map->sub_stripes;
    else
        num_stripes = map->num_stripes;

    preferred_mirror = first + current->pid % num_stripes;
Run Code Online (Sandbox Code Playgroud)

当数据替换处于活动状态时,还有用于更改首选的附加逻辑。但是当前的代码在“旋转”选择逻辑上没有“SSD”。

Timofey Titovets在2017年和2018年提出了一个补丁来实现搜索ssd作为首选使用,但仍然没有被接受:

Btrfs:增强非旋转设备 Timofey Titovets 的 raid1/10 平衡启发式。2017 年 12 月 27 日,星期三

当前 btrfs raid1/10 balancer blance 对镜像的请求,基于 pid % num of mirrors。...

如果镜像之一是非旋转的,则所有读取请求都将移动到非旋转设备。...

PS 受 md-raid1 读平衡启发

https://www.spinics.net/lists/linux-btrfs/msg80033.html [PATCH V5] Btrfs:enchanse raid1/10 balance heuristic,2018 年 7 月 7 日

https://patchwork.kernel.org/patch/10681671/ [V8] Btrfs:增强 raid1/10 平衡启发式,2018 年 11 月 14 日

  • 另一篇关于 btrfs raid1 ssd+hdd 的文章:https://superuser.com/questions/874673/btrfs-raid1-ssd-non-ssd。还要感谢 phoronix 帖子 https://www.phoronix.com/scan.php?page=news_item&px=RAID-1-10-Balance-Patch 提供补丁链接。 (2认同)