XFS is a very solid file system and does not develop fragmentation to the same degree as other less advanced filesystems, however, some fragmentation may occur over time, especially if your drive is almost full and you shut down the machine overnight, so that the filesystem optimizer (fsr_xfs) doesn't get a chance to run.
Normally, fsr_xfs, the program responsible for optimizing and reorganizing XFS filesystems, runs once a week at 3am; this article will show you how to manually run this tool, but first, let's see what degree of fragmentation our filesystems show ...
xfs_db is a powerful tool you shouldn't play with before reading the manpage.
There are two versions of xfs_db: 32- and 64-bit. The manpage says that xfs_db64 should be used if xfs_db runs out of memory, but it is available only on 64-bit systems.
The xfs_db command that is of interest is 'frag', which prints info about fragmentation (there are also some other interesting commands available, take a look at the manpage).
You must be root to use xfs_db, so do a 'su' first:
$ su -
The '-r' flag will open the filesystem read-only, which is always a good idea. Choose a volume and pass it as the parameter:
# xfs_db -r /hw/disk/root
An "xfs_db: " prompt will appear, where commands can be entered (use the '-c' option to xfs_db and pass the command directly).
xfs_db: frag actual 90661, ideal 89916, fragmentation factor 0.82% xfs_db: quit
And another one, this time with the '-c' option:
# xfs_db -c frag -r /hw/disk/dks1d4s0 actual 268502, ideal 264356, fragmentation factor 1.54%
Not bad for a system that has been in use for more than 2 years without running fsr_xfs.
If desired, repeat this process for any other drives on the system, otherwise let's move on to fsr_xfs ...
This is a very straightforward utility: when it runs, it reorganizes files on all mounted filesystems. Maximum runtime can be specified with the '-t' option (the default is 7200 seconds [2 hours]). Note that some linux distributions call this tool xfs_fsr.
I've decided to give it 3.5 hours, though it only used about one and a half (this is because it automatically terminates after 10 passes).
# fsr_xfs -t 12600 fsr_xfs -m /etc/mtab -t 12600 -f /var/tmp/.fsrlast_xfs ... / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 / startino=0 /disk2 startino=0 Completed all 10 passes
Now, if we check the fragmentation factors of the drives, they should be lower than before (not zero, because open and really large files can't be moved).
# xfs_db -c frag -r /hw/disk/root actual 90231, ideal 89915, fragmentation factor 0.35% # xfs_db -c frag -r /hw/disk/dks1d4s0 actual 264723, ideal 264356, fragmentation factor 0.14%
Much better :)
Share your opinion