Thursday, December 07, 2006

Tip: OS X doesn't have a defragmentation tool because user's don't need to run one

A co-worker asked me yesterday if he needed to defragment his Mac. This is my co-worker's first Mac, and after being conditioned to Windows defragmentation he thought he should ask so he could keep his Mac running at top performance. I told him right away that OS X doesn't need to be defragmented, mostly because I had done some research on this in the past because I was conditioned to defrag coming from Windows. I came to the conclusion it was unneeded because OS X automatically and silently defrags files, and moves heavily requested files onto the fastest parts of the disk (more on this stuff later). I also told him no defrag needed because I hadn't defragged any Macs in the 3 years of owning and using Macs. This is one of the "Windows taxes" that you forget to tell people about that they don't have to do when they use Macs, since the pain is gone you kinda forget what all the fuss is about.

But my VersionTracker for OS X RSS feed showed a new version of iDefrag, 1.5.8, available for download, so I read their documentation and then Googled for some more information on fragmentation on OS X, specifically the default filesystem HFS+.

A few minutes later, I found pretty much the authoritative article, Fragmentation in HFS Plus Volumes by Amit Singh. Amit it seems is becoming the Mark Russinovich of the Mac OS X kernel. Amit's book, Mac OS X Internals: A Systems Approach may be the equivalent of Microsoft Windows Internals, Fourth Edition. I hear Santa is bringing me the OS X internals book...

Anyway, here is the conclusion to Amit's article:
Defragmentation on HFS+ volumes should not be necessary at all, or worthwhile, in most cases, because the system seems to do a ver good job of avoiding/countering fragmentatio .
For the more curious, I encourage you to read all of Amit's article. Two features in OS X help eliminate the need to manually defrag, Hot File Adaptive Clustering and On-the-fly Defragmentation. Amit's article contains excellent descriptions of both. There is an Apple support article on why defragmentation should not be needed, but there are specific scenarios that might cause heavier then usual fragmentation and OS X built-in techniques wouldn't suffice. This has to do entirely with heavy large file manipulation, since those files aren't earmarked for automatic and silent defrag since they most likely exceed the 20MB rule Amit mentions.

For comparison's sake, Windows XP has had the Prefetcher which does essentially the same thing as OS X's Hot File Adaptive Clustering combined with On-the-fly defragmentation, with one exception. OS X will defrag any file on open if it hits a bunch of conditions, again listed in Amit's article, Windows isn't doing that, only for the most used files. Vista goes get an Automatic Defragmenter.