The “out of space” problem of btrfs
Anyone who uses btrfs should know about the “out of space” problem of btrfs. Here i try to briefly explain how this can happen.
When btrfs gets into the “out of space” situation, it no longer has any room to move to free itself. Then no more file operations can take place. Often you can’t even delete files.
The solution is explained in the manjaro btrfs wiki.
But how does the problem actually arise?
Let’s take a quick look at some made-up scenarios to get to the bottom of the problem.
30% used, without cleanup
Assuming btrfs would not perform any background cleanup.
Now the volume would be out of space, even though only 30% is occupied.
30% used, with cleanup
But btrfs does regular cleanup when it has the opportunity. This could then go something like this:
Now about 50% would be allocated, although only 30% is occupied. But this is no problem. A suitable balance would be able to reduce allocated further up to 30%, but that does not bring any significant advantage. Btrfs only has to move a few chunks during cleanup.
50% used
Btrfs cleans up regularly when it has the opportunity.
Now about 70% would be allocated, although only 50% is occupied. But this is no problem. A suitable balance would be able to further reduce allocated up to 50%, but Btrfs has to move a number of chunks for cleanup. A balance of 50% would help btrfs get things right.
70% used, sufficient time for cleanup
Btrfs cleans up regularly when it has the opportunity.
Now over 90% would be allocated at times, although only 70% is occupied. And that could become a problem. A suitable balance would relax the situation up to 70%. If btrfs follows up with the cleanup, in this case it does not lead to → Out of Space
70% used
Btrfs cleans up regularly if it has the opportunity.
Now over 90% would be allocated at times, although only 70% is occupied. And that is now becoming a problem. Apparently btrfs has little time for ongoing cleanup in this scenario. A suitable balance would significantly relax the situation up to 70%. If btrfs fails to cleanup, this will result in → Out of Space
These scenarios are
- invented
- exaggerated
But essentially they make the following points clear:
- btrfs requires no manual or automatic maintenance up to 50% used
- btrfs needs a watchful eye on allocated from 70% used
- the value of allocated % is a good indicator of whether btrfs is keeping up with the cleanup or is overwhelmed
Use the following command to investigate allocated space:
Difficulty: ★☆☆☆☆
sudo btrfs filesystem usage / |grep -E 'Dev.+(allocated|size)| Used:'
Device size: 1.76TiB
Device allocated: 1.46TiB
Device unallocated: 303.94GiB
Used: 1.29TiB
The solution is explained in the manjaro btrfs wiki.
or you can investigate visually with
Difficulty: ★★★☆☆
sudo pacman -S btrfs-heatmap
info btrfs-heatmap
- black = free
- white = data
- grey = partially filled chunks
- blue = metadata
A balance collects gray chunks and writes black and white ones