I came across Scott Kaiser’s defrag.plscript a while back, and have found it useful for determining if the VxFS free extent map is fragmented. The script takes a file system as an option, and prints a one-line string to indicate if the file system should be defragmented:
$ defrag.pl /u01
/u01 is badly fragmented. Defragmentation is recommended.
If the script determines that the free extent map (the script doesn’t report on directory entry fragmentation) is fragmented, you can perform an online defragmentation by invoking fsadm with the “-e” (reorganize extents) and “-d” (reorganize directory entries) options:
$ /usr/lib/fs/vxfs/fsadm -v -e -d /u01
UX:vxfs fsadm: INFO: V-3-20287: using device /dev/vx/rdsk/oradg/oravol01
UX:vxfs fsadm: INFO: V-3-20223: directory reorganization complete
UX:vxfs fsadm: INFO: V-3-20261: extent reorg pass 1
AU: aun = 16, tfree = 32064, sfree = 384
aun = 16, seg = 0, nfrag = 95, fblks = 1690, devid = 0 start = 524288, len = 2048
req[0] fset 999 ino 32 blocks 1 off 0x0 len 1
req[0] fset 999 ino 33 blocks 1 off 0x0 len 1
UX:vxfs fsadm: ERROR: V-3-24364: reorg failed for fset 999 ino 33
req[0] fset 999 ino 34 blocks 1 off 0x0 len 1
req[0] fset 999 ino 35 blocks 1 off 0x0 len 1
req[0] fset 999 ino 36 blocks 1 off 0x0 len 1
req[0] fset 999 ino 37 blocks 1 off 0x0 len 1
req[0] fset 999 ino 38 blocks 1 off 0x0 len 1
[ ... ]
aun = 16, seg = 0, nfrag = 86, fblks = 5397, devid = 0 start = 524288, len = 6144
UX:vxfs fsadm: INFO: V-3-20262: extent reorg complete
I prefer to avoid fragmentation, and try to preallocate all files to avoid this issue (for dynamic applications this isn’t always possible). For further information please refer to the fsadm_vxfs(1m) manual page.