7 disk defragmenters to boost performance
When a file is saved to the hard disk drive we assume that it is stored in one continuous block on the disk surface and that each file is a complete, whole and separate object. This is true quite a lot of the time, but it doesn't always happen and not all the files on the disk drive are stored as a continuous block from start to finish.
Many files that are on the disk are split into lots of small fragments with a bit of file stored here, a bit there and the rest somewhere else. Fragments of a file can be scattered all over the disk surface and they aren't always located near to each other. You don't notice that files are split up into small fragments and stored all over the disk surface because OS X keeps track of where all the fragments are and when you want the file it goes and gets each part in the right order and reassembles the original file.
You may be wondering why and how files become split like this, and it doesn't seem a logical thing for an operating system to do. To see how files can become split into two or more fragments when they are saved, imagine that you saved three files called A, B and C. This is how they are organised on the disk surface:
If you then delete file B there will be a gap between file A and C where B used to be stored, like this:
If you then you save file D OS X might start saving it in the first bit of empty space it finds, but if there isn't sufficient room for it, the rest is stored in the next bit of free space:
You can see that part of file D is stored in the space left by B and the rest is stored after file C. File D is now in two fragments. The advantage of splitting files when they are saved and filling in the gaps between existing files is that it makes very efficient use of the space on the disk because every little bit gets used. If a file could only be saved if there was a large enough space to store it as a complete block without any breaks you could end up with a situation where there was lots of free space on a disk, but you couldn't save a file because there wasn't a free block big enough (years ago some disks actually used to be like this!). You would be able to save a small file like a text document, but a large video clip might not be able to be saved.
The disadvantage of filling in all the little spaces when a file is saved is that when the file is read back from the disk the operating system has to go and find all the parts. Accessing a badly fragmented file takes longer than one that is saved as a single block because OS X has to jump around fetching the fragments. Disk performance suffers and the computer gradually slows down over time.
This is one of the reasons why new computers are fast, but then they slow down as they become older. It's partly because the disk contents become disorganised and increasingly fragmented. Fortunately, a utility called a disk defragmenter is able to reorganises the disk contents and it pieces together the fragments of files and resaves them as complete blocks. This improves the performance of the disk drive and in turn this speeds up the computer.
Macs don't need defragmenting do they?
This is a popular myth, but like all myths there is actually some truth in it. If the hard disk drive is large and there is a lot of free space then file fragmentation is minimal. This means that it is hardly worth defragmenting and you won't notice much of a performance boost afterwards. In addition to this, modern hard disk drives are much faster than they used to be and the read head can jump very quickly from fragment to fragment when a file is being read, so little time is lost reading fragmented files.
What's more, OS X performs a certain amount of defragging and optimising during normal use. It uses a technique called adaptive hot file clustering. It basically tracks file usage and those files that are accessed the most (called hot files) are moved to a special area area of the disk (the metadata zone). They are defragmented and saved as a contiguous block next to each other. Files in this area - your most used files - can be accessed faster than those rarely accessed files elsewhere on the disk. This is a continuous process and hot files are moved into and out of the metadata zone as their temperature (the frequency with with they are accessed) changes.
This does not mean that the disk doesn't need defragmenting. Space is needed in order to move the files around and only the most frequently accessed files are defragged. Also the metadata zone has a limited size and this means that large files won't fit and therefore aren't moved to it and defragged. When a disk is nearly full the fragmentation will be the most severe and this is when defragmentation offers the most benefit.
There's also annecdotal evidence and people that have defragmented their disks sometimes report quite significant speed increases, so it is well worth trying if your Mac is running slowly.
Preparing for defragmentation
Defragmentation involves moving files around on the disk drive and this inevitably has some risk associated with it. It's not that defragmenters are unreliable, its that when a file is moved from one place to another there is always a small chance it could become corrupted, or it could be placed on a dodgy sector on the hard disk surface that can't hold data reliably.
It is essential that you have a backup of any important files before you start defragmenting. You should also run Disk Utility and check the disk for errors. Verify the disk and verify disk permissions, then only go ahead and defrag if Disk Utility gives the drive a clean bill of health.
Files that are in use cannot be defragmented, so to completely defrag the boot disk you really need to boot from a different drive. If you defrag the boot disk you'll defrag most files, but not quite all of them. Still, it's better than nothing. Defragmenting is an overnight job. Set it going and go to bed - you don't want to sit and watch it!
Third party disk defragmenters do a more thorough job of defragging than OS X, so let's take a look at some utilities that can reassemble fragmented files and boost performance.