Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BTRFS raid-1: which device gets the reads?

Tags:

btrfs

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?

like image 486
Aleksandr Levchuk Avatar asked Mar 28 '19 23:03

Aleksandr Levchuk


People also ask

How does btrfs RAID work?

The btrfs balance operation will take some time. It reads in all of the FS data and metadata and rewrites it across all the available devices. Depending on the usage scenario that is not needed, one example would be adding a new device to a RAID 1 filesystem whose existing devices still have enough space left.

Is btrfs RAID 1 stable?

So, we'll repeat this once more: as a single-disk filesystem, btrfs has been stable and for the most part performant for years.

Do I need RAID with btrfs?

Btrfs is a modern Copy-on-Write (CoW) filesystem with built-in RAID support. So, you do not need any third-party tools to create software RAIDs on a Btrfs filesystem. The Btrfs filesystem keeps the filesystem metadata and data separately. You can use different RAID levels for the data and metadata at the same time.

Is btrfs stable now?

Btrfs is reliable and stable - when you're running it on a single disk. That's what tends to the default mode for operating system installs that use Btrfs. I use it on all my single-disk installs to get checksumming, COW, and transparent compression.


1 Answers

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

like image 161
osgx Avatar answered Dec 05 '22 20:12

osgx