Considering some btrfs optimizations

My installation is a few months old, maybe 4 months.
Decided to run the first defrag yesterday, but before I checked the disk usage, it was about 21GB.
After the defrag, noticed that the space used increased to 26GB.

Since the info above is specifically saying about “break” links, I decided to test my system and everything was working perfectly.

In my opinion, which could be premature and with little knowledge about the technical stuff, is that these links that “break” are only for the snapshots, but they still work, they just consume more space after the defrag.

Decided then to erase my snapshots and my system is now using 16GB of space…

1 Like

Thanks for sharing! It confirms then:

indeed, that is exactly what appears to me that happened

1 Like

Just speculating: I wonder if there might be possible to exclude some volumes from defraging to workaround this increase of space usage :thinking:

edit- I don’t think so. I am out of my depth of course :sweat_smile:

Isn’t it better to defragment only the really fragmented data?

1 Like

You can, but I don’t think its going to help.

btrfs-assistant (dalto’s app)
image

See, I’m taking snapshots from /, which allows me to recover my system, to boot into snapshots and etc.

So, assuming that every user also takes snapshots from / so they can be able to perform the tasks above, and the fragmented data is located in / which contains the system, how not to defrag / ?

1 Like

Not sure:

btrfs filesystem defragment [options] <file>|<dir> [<file>|<dir>...]

Could it be possible to specify explicitly the directories to be defraggede and leave out some?

This certainly makes sense. Just don’t know how to go about in practice to do so.

image
https://btrfs.readthedocs.io/en/latest/btrfs-filesystem.html

1 Like

I have managed with the autodefrag mount setting and the instructions on this page:

I have found that I don’t need to use the defrag command.

2 Likes

Sounds great!
Thanks for the link! I’ll look int it.

The autodefrag was the default in the previous EnOS installation (calamares)
However there was a regression with that option in kernel as per image below.

image
https://wiki.archlinux.org/title/btrfs

Since then I decided not to use it anymore…
Also, keep in mind that if you monitor the disk usage by typing: iotop -a, you will see that btrfs is writing to the disk more often with the autodefrag option.

2 Likes

Yes. I know the topic. As far as I know it has been fixed long ago.

I haven’t noticed a noticeable difference on my machine when I’ve looked into it with iotop.
I don’t run torrents on btrfs file system, it may be one reason why usage is not rising.

But I noticed several gigabytes of writing with the iostat program (before and after) the defrag command.

Choices, choices.

3 Likes

Yes, it is fixed…
But still, it writes constantly to the disk, same happens with the discard async option, thus I prefer to run both once in a while…

Exactly :slight_smile:

3 Likes

A bit off-topic but related to btrfs and mounting.

I use to mount the root of a btrfs partition into a directory in order to being able to browse all the contained subvolumes like you would with “regular” directories. I use the following line:

sudo mount -t btrfs /dev/nvme0n1p2 /btrfs

I wonder if (some of) the mount options for mounting subvolumes should be applied here as well. Or any others?

I look forward your suggestions.

If you use the same options on all your subvolumes, you should use those options there as well. It may or may not make much difference depending on how you use that mountpoint.

Many of the btrfs options actually apply to all subvolumes of the same filesystem. For example, if you look at findmnt /btrfs you will probably see that compression and some other options are being applied to it even though you didn’t specify them explicitly.

If you want to explicitly mount the root you should probably use subvolid=5. What you are currently doing is mounting the default subvolume which is currently set to /. If you ever changed the default subvolume, what you have mounted there would change too.

1 Like

Thank you @dalto for the reply!

Here is findmnt /btrfs from how I usually mount the partition as mentioned above:

TARGET SOURCE         FSTYPE OPTIONS
/btrfs /dev/nvme0n1p2 btrfs  rw,relatime,compress=lzo,ssd,space_cache,subvolid=5,subvol=/

Mounting it with subvolid=5:

mount -o subvolid=5 /dev/nvme0n1p2 /btrfs

gives the exact same output for findmt /btrfs as above.

For comparison:

findmnt /
TARGET SOURCE                            FSTYPE OPTIONS
/      /dev/nvme0n1p2[/@arch-gnome-root] btrfs  rw,noatime,compress=lzo,ssd,space_cache,subvolid=256,subvol=/

The only difference, as far as I can see, is between relatime and noatime (which I have in fstab).

I just use /btrfs occasionally to copy some file or folder into the running system.

/dev/nvme0n1p2 contains some subvolumes for other Arch systems with different DEs (Plasma and Cinnamon) and one with WM (i3).

Should I be specifying noatime in the mount command for it to match the mount options for the subvolumes in /etc/fstab?

Yes. That just guarantees it won’t change later if the default subvol changes.

I would match them.

1 Like

Great! I’ll do so!
Thanks for the support! I appreciate it.

1 Like

Well, honestly I am not that techie, but I will just make a suggestion (taking the title of the topic). I hope BTRFS developers would consider.

The unfamous problem of BTRFS and Baloo always indexing snapshots. There are a few bugs filed with Baloo.

My question/suggestion is:
Why not let BTRFS give the user the option that BTRFS takes snapshots of only the file system not ‘/home’ to avoid that problem.

I am not that techie and I do not know if there is a way to avoid reindexing each snapshot of “/home”

This is the only thing preventing me from using BTRFS though I would love to. (some of my posts when I was on EOS a few months ago shows the hell of Baloo indexing all the time)

Sorry if I interrupted. I am just posting this because I love the concept of BTRFS and snapshots, while I love Baloo as I have lots of papers, research… books), but I can’t have them both!

Honestly I can’t tell if such issue should be filed as a bug with Baloo or with BTRFS, or both should cooperate to overcome this!

I tried system on BTRFS and “/home” on EXT4 but it didn’t work OK with me.

This is already entire controllable in btrfs. You decide which subvolumes you want to snapshot. That being said, snapshots of /home are, to me, the most valuable and important snapshots.

I don’t even vaguely understand why this is an issue. Baloo has an easy UI which allows you to decide what you do and don’t want to index. Why can’t you simply exclude the snapshots?

Neither. They both already support this.

This seems like a setup or a design issue to me. I have hundreds of snapshots of /home and none of them are getting indexed. I don’t even have them excluded by baloo.