11

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?

Aleksandr Levchuk
  • 3,751
  • 4
  • 35
  • 47
  • What is your linux kernel version? What is the "sda" (is it hdd)? In 2017 and 2018 patch "Btrfs: enchanse raid1/10 balance heuristic for non rotating devices" was proposed, but it still not accepted. md-raid1 should have ssd over hdd logic. Do you know about ZFS and ssd-hdd balancing? – osgx Mar 28 '19 at 23:35
  • my kernel is 4.19.25 – Aleksandr Levchuk Mar 28 '19 at 23:37

1 Answers1

9

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

osgx
  • 90,338
  • 53
  • 357
  • 513
  • so then the preferred device is determined based on whether the user process pid is odd or even? – Aleksandr Levchuk Mar 28 '19 at 23:38
  • 1
    Yes, with current code in kernel and mirror of two devices, even pids goes for first device and odd for second. You may patch your kernel with "V8" patch and recompile (due to `EXPORT_SYMBOL_GPL(part_in_flight)` part, full kernel recompilation is needed), or you may try to refork your process until you will get right oddness of pid. – osgx Mar 28 '19 at 23:41
  • 2
    Another post about btrfs raid1 ssd+hdd: https://superuser.com/questions/874673/btrfs-raid1-ssd-non-ssd. Also thanks to phoronix post https://www.phoronix.com/scan.php?page=news_item&px=RAID-1-10-Balance-Patch for links to the patch. – osgx Mar 29 '19 at 01:23
  • I'm curious as to the behaviour on BTRFS RAID 1 with > 2 drives. I understand the raid1 profile still only has 1 stripe (num_stripes = 1), so all data is duplicated just twice, even over N > 2 drives (unless RAIDC3 or RAIDC4 is used). How does btrfs decide on which disks to put each stripe? If the number of disks is odd, or drive sizes are unequal, a disk may share both stripes also? – Ryan Dec 09 '20 at 00:26