5

Problem background

One great thing about btrfs is its ability to effectively use drives with different sizes, but I just learnt that this is not true for its default RAID-0 (striped) profile.

I wanted to use RAID-0 with three drives: 8, 4, and 4 TB, and was hoping to get a total of 16 TB: The first half of the 8 TB can be striped with the first 4 TB drive, and the second half can be striped with the second 4 TB drive.

However, according to the (very useful) btrfs disk usage calculator I would only get 12 TB: Each chunk would be striped on all three drives, and that leaves 4 TB unused on my 8 TB drive. This is also mentioned in an answer to the question Using btrfs RAID0 with different drive sizes results in low space available.

Illustration

This is what I expected to happen:
btrfs striping for RAID-0 if it works like I want it to

…and this is what is actually happening:
btrfs default striping for RAID-0

What does the manual say?

After perusing mkfs.btrfs I figure that this is because the default RAID-0 profile sets a minimum number of devices to 2, but does not have an upper limit. This means that a data block will be striped on as many devices it can find in the pool. This can of course be a reasonable option and it makes complete sense.

While playing with the btrfs disk usage calculator I found that I can get what I want by setting the maximum number of devices to 2. This would still stripe my data over two drives to get some extra speed, but limit the striping to two devices so that it can use a lot more of the available space. To me this is a very beneficial trade-off, and I assume I am not alone in thinking so.

The question

I did not find a way to change the maximum number of devices when creating a filesystem.

  • Is this even possible?
  • If so, how can I change it?
  • If I do change it, will the other tools understand the layout?

3 Answers 3

3

You cannot do it out of the box, but it might be possible with some luck and effort.

The thing is, at the moment (as of btrfs-progs 5.7), there's no way to pass custom min/max stripe counts in mkfs.btrfs. The online space calculator also contains a remark to this effect under Preset RAID levels:

Note that these are the only parameter settings supported by btrfs at present.

I have tried various combinations of mkfs.btrfs with two drives, btrfs device add of the third drive and btrfs balance (using 8+4+4 GiB LVs as the "drives"). Unfortunately, while I often managed to store more than 12 GiB of data on the FS, I never came close to the desired 16 GiB. According to btrfs device usage, I always end up with some mix of chunks striped over 2 and 3 drives.

That said, it might be possible to use a custom stripe count in mkfs.btrfs by tinkering with the code. The chunk layout is set up in btrfs_alloc_chunk() in volume.c in btrfs-progs. That function calls init_alloc_chunk_ctl() to translate the RAID preset into stripe counts. min_stripes is set to 2 for RAID0 and num_stripes (which is the stripe count actually used to create the chunk) is set to min(ctl->max_stripes, ctl->total_devs). Here, max_stripes is a chunk-type-dependent limit set in btrfs_alloc_chunk().

You can thus modify that routine to clamp num_stripes to the desired value (2) and use such modified mkfs.btrfs to create a filesystem that behaves the way you want. I don't have time to test that hypothesis thoroughly, so there's some chance that you'll run into bugs in the kernel or btrfs-progs, but IMHO it has a fair chance of working. After all, the on-disk layout that you're after still often occurs when you use unmodified tools and add/remove devices (like in my tests above), so it should be supported in principle. But I wouldn't be too surprised if a later device add/balance messed the layout up again.

1

The need for this kind of parameter has been registered as a project idea worth implementing:

https://btrfs.wiki.kernel.org/index.php/Project_ideas#Limits_on_number_of_stripes_.28stripe_width.29

As of 2022-02-12, it says that nobody has claimed working on it and no patches have been sent to the mailing list.

0

This answers your problem but not the question stated in the title:

With Linux 5.15, btrfs allows RAID0 on a single drive ("degenerate raid"). This allows you to use your full 16TB, albeit at potentially sub-optimal performance distribution:

The first 12TB would have a stripe width of 3 (as visualised in your question) and the last 4TB would have a stripe width of 1.

Depending on your needs, that could be a positive or negative.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.