Btrfs defragmentation is important to avoid
performance degradation. Unfortunately btrfs filesystem defragment
is not recursive neither does it report the changes made.
To help performing Btrfs defragmentation Dmitry wrote a small shell script which might be useful to determine fragmentation threshold by counting number of extents in directory and to start defragmentation only when needed. Script provides visual feedback for defragmentation process and reports number of eliminated extents.
We hope this script will be helpful to maintain best performance on your Btrfs file system(s).