Fix random lengthy pauses in OS X by correcting bad blocks
If your Mac regularly and randomly pauses with the spinning color wheel, it may be because of bad blocks on the hard drive. Here is how to correct bad blocks for Macintosh systems running OS X.
If you find your Mac is running slowly, generally there are a few things you can do, including running a general maintenance routine, deleting unneeded files to keep at least 10 percent of your boot drive free, increasing the installed RAM, and quitting unused applications (both foreground and background) that you may have installed. In addition to this, one possible cause of slowdowns is if your hard drive contains undetected bad blocks, and forcing the system to remap them can result in things running smoothly again.
Hard disks are "block-based" storage systems, meaning that their writing surfaces are organized into grids of storage compartments. The standard compartment size has been 512 bytes, though some modern drives are beginning to use 4KB block sizes for better efficiency and performance. Regardless of its size, each block is organized with a data section and an error correction section, along with sections for timing gaps and block identifiers.
When a block is read, all of its components (error correction and data) are picked up by the drive head and are initially processed by the drive controllers. Normally the data component is intact so the controllers just pass it along to the system; however, if for some reason a section of data cannot be read then the drive uses the error correction component to rebuild the missing data. The error correction component is essentially a unique key that, along with enough healthy data, can be used to reassemble a certain degree of missing data. However, this can only be done up to a point, so if too much of the block's data cannot be read, then the error correction will not work and the whole block will no longer be readable. When a block becomes unreadable like this, it is considered to be a "bad block."
Normally drives contain spare blocks that will be recruited as regular blocks go bad; however, this will not always happen dynamically, especially if an established filesystem on the drive has that block flagged as being in use. As a result, if your drive has bad blocks and your system tries to access them, the drive may try numerous times to reread the entire block and use the error correction to rebuild the data. This will pause all data output from the drive and cause I/O slowdowns, timeouts, and hangs, resulting in the system grinding to a halt and showing the spinning color wheel cursor.
Generally, when bad blocks are causing slowdowns the hard drive will not show too much activity and there may be only a few periodic click sounds coming from the drive as it pauses its reading while it tries to read and correct the bad block. During this time, applications may respond for a few seconds before hanging. When the drive eventually moves on from its attempts to read the bad block, the various system processes will resume and continue to function normally.
Depending on the data that the bad block contained, you might see I/O errors show up in the console, or you might see an error message onscreen either from the system or from an application. Many times bad blocks only cause temporary hangups, but sometimes they can cause full-system hangs that can require you to reset your system.
Recently MacFixIt reader "Ron" wrote in with such an issue:
Every time I type or try to do anything like close a window the color wheel comes up and starts spinning. Nothing works without a pause and the color wheel comes up and spins for minutes. I read and performed your article maintenance routine; I used OnyX to clean and rebuild caches. Rebooted the first time and it took ten minutes, rebooted the second time and it took 15 minutes. I have a 500 GB hard drive with 428 GB available.
These behaviors that Ron reported are classic symptoms of bad blocks on the filesystem. Luckily, tackling bad blocks is fairly easy, especially with modern methods that are available for backing up and restoring the system.
A hard drive can be forced to remap bad blocks by formatting it and forcing the drive to read and write to each block on the disk. The quick way to do this is to write zeros to the surface of the drive when formatting it, though some drive utilities have extensive "break-in" routines for drives that will read and write to each block in multiple ways to test the integrity of the block (these routines can take several days to complete, but are more thorough than just writing zeros).
Formatting a drive will erase all data from it, but with either Time Machine or a system cloning tool you can back up your data, format the drive, and then restore your data to the drive and be free of any bad blocks slowing you down. Therefore, to fix slowdowns from bad blocks, first make sure you have a backup drive available that can contain all of your boot drive's data, and then follow these steps:
Back up your data.
Use Time Machine or a system cloning utility to create a full and restorable backup of your data. If you suspect bad blocks, then when cloning you might consider not using a "block-level" copy process, since this will likely run into problems.
Boot to the utilities DVD.
If you have a boot DVD for a tool like Drive Genius or another drive utility, then boot to that; if not, use your OS X installation DVD (once you select your language, open Disk Utility from the Utilities menu).
Format the drive.
Using your selected utility, format the drive and check for bad blocks. If you are using Disk Utility, click the Erase tab, click the Options button, and then select the option to write zeros to the disk (you do not need to do multipass erase options, as this will provide no additional benefit for managing bad blocks). Writing to zeros may take a couple of hours depending on the size of the drive, but when done the drive will have remapped any blocks that were not reliably read.
Restore the OS installation.
If you have used Time Machine to create your backup, boot to your OS X installation DVD (if you are not using Disk Utility) and use the option in the Utilities menu to restore from backup. Attach your Time Machine drive and then proceed with the restoration, selecting the newest backup as the one to restore to your system. If you have used a system cloning tool, then attach the cloned drive and boot off of it (hold the Option key at start-up to select it from the boot menu). When you are booted to the cloned drive, run your cloning utility to copy the installation back to the computer's main boot drive.
An optional approach here is to perform a full reinstallation of the OS from your installation DVD, and then migrate your data, applications, and settings from either the clone or the Time Machine backups using Apple's Migration Assistant.