btrfs

BTRFS raid-1: which device gets the reads?


I have a raid-1 with the following configuration:

$ 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

/dev/mmcblk0p4 is fast and /dev/sda is slow

What determines what device would get the IO reads and is there a way to control that?


Solution

  • As of 5.0 version of the Linux kernel, there is a code to decide which part of mirrored array will be used. It uses pid of process to select one of available stripes:

    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;
    

    There is additional logic for changing preferred when data replacement is active. But current code has no "SSD" over "rotational" selection logic.

    Timofey Titovets proposed a patch to implement searching for ssd to use it as preferred in 2017 and 2018 years, but it is still not accepted:

    Btrfs: enchanse raid1/10 balance heuristic for non rotating devices Timofey Titovets. Wed, 27 Dec 2017

    Currently btrfs raid1/10 balancer blance requests to mirrors, based on pid % num of mirrors. ...

    If one of mirrors are non rotational, then all read requests will be moved to non rotational device. ...

    P.S. Inspired by md-raid1 read balancing

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

    https://patchwork.kernel.org/patch/10681671/ [V8] Btrfs: enhance raid1/10 balance heuristic, Nov 14, 2018