Btrfs auto defragmentation

Hi, I bought a hard drive and formatted it to Btrfs in order to make it a NAS server. :smiley:
Btrfs has this nice feature to automatically defrag the hard drive, and it can be turned on in the mounting option. :wink:
(See #2 in https://www.thegeekdiary.com/how-to-tune-btrfs-filesystem-for-better-performance/)

My question is, is this option enabled by default in dietpi-drive_manager? Or do I have to manually mount the drive to enable that option?

Hi,

I donā€™t think it will be added by default.

However you could use Drive Manager to mount your hdd and check mount options afterwards on /etc/fstab and try to add your option if needed.

Indeed not added by default currently, also not applicable on non-spinning drives, but good to know this exists. Edit /etc/fstab for now, but note that or is overwritten on every drive manager run.

Iā€™ll add the option to v6.29, either as default on spinning drives or optional to toggle in UI.

Thank you very much for replying!
Iā€™m so excited to see it in future updates!

I read a bid through some man pages and actually autodefrag on BTRFS seems to be generally not recommended currently due to CPU usage and caching that is done and especially with large files. Iā€™ll definitely add it as non-default option only with link to related man pages and recommendations.

Do you face any issues that you want this option?

I didnā€™t face any issues yet, but Iā€™m dealing with a HDD and thought defrag may make it perform better.

Will the command line defragment it?

https://docs.oracle.com/en/operating-systems/oracle-linux/7/admin/ol7-use-case1-btrfs.html

I guess it would be the mount point

btrfs filesystem defragment filesystem_name

Also read up on itā€¦until the drive/drives get really full does it really start causing fragmentation
https://serverfault.com/questions/519852/does-btrfs-balance-also-defragment-files

I ran the command on my Orange Pi PC running openmediavault with a 1TB laptop drive

btrfs balance start /srv/drive~~~~

Just make sure you run it on a mounted btrfs filesystem

Here are the ā€œgotchasā€ on a btrfs system
https://btrfs.wiki.kernel.org/index.php/Gotchas#Fragmentation
https://btrfs.wiki.kernel.org/index.php/UseCases#How_do_I_defragment_many_files.3F

Yeah it seems like that commands works. Good enough for me. And according to those ā€œgotchasā€, I guess Iā€™ll do it manually when necessary. Thanks for the reply and suggestions!