XFS PVR/DVR maintenance

Last year, I purchased an HDTV tuner card and started using my computer as a Personal Video Recorder, or PVR. Basically, a small program records a tv show to the hard drive. This did quite well until March when it would stop recording after 5 seconds to 15 minutes for no apparent reason.

After about a month of research, I had ruled out just about everything under the sun. Then, it hit me … the file system might need defraging. The file system I am using is XFS, and they can get fragmented over time, especially if you have big files (HD-MPEGs) and little free space.

The command to defrag all mounted (and keeps them read-write) XFS filesystems is:

xfs_fsr -v

After running this, shows started recording better, but still stopped. So, I wanted to see just how fragmented everything was. I found this command:

xfs_db -r /dev/sda3

That starts an interactive XFS debug session for sda3, my XFS partition. Three useful commands are freesp, frag and quit. frag reported over 15% fragmentation and freesp reported a lot of small blocks and very few large blocks.

Finally, I got to the heart of the matter: defrag programs do not operate efficiently with less than a certain amount of free space. My drive had 20GB free out of 250GB total. I deleted a few HD shows to bring it up to 45GB free and ran the defrag command again.

Voila! Less than 6% fragmentation and plenty of free big blocks. My recordings are almost flawless now. At least they don’t stop for no reason. So, if you’ve got an XFS file system:

  • make sure to run the xfs_fsr command regularly
  • if you’re filesystem is still fragmented, burn/remove some junk and repeat