XFS just like EXT4 (I wrote a post about it last year) supports online defragmentation, to manage those volumes on CentOS and Fedora “xfsprogs” package is needed.
Fragmentation level of XFS volumes can be checked with the command:
[root@CentOS ~]$ xfs_db -c frag -r /dev/sdb1 actual 4491, ideal 4006, fragmentation factor 10.80%
To perform online defragmentation of XFS volumes run the following command:
[root@CentOS ~]$ xfs_fsr -v /dev/sdb1 /mnt/data1 start inode=0 ino=205 ino=205: file busy ino=201 ino=201 already fully defragmented.
The defragmentation process can take a very long time, if performed on a remote machine I strongly suggest to use “screen” or a similar tool to prevent accidental disconnections which would probably result in files corruption.