8.5. My Hard Drive Is Too Slow
The defaults associated with the latest Linux distributions do not take full advantage of the latest improvements in IDE/ATA (Integrated Drive Electronics/Advanced Technology Attachment) hard drives. For example, Linux is normally set to communicate with IDE/ATA hard drives in 16-bit mode. While this may seem irrational in current 32- and 64-bit environments, it helps Linux retain its reputation for extending the life of older hardware. If you don't have an older hard drive, you can modify the Linux defaults to take full advantage of its data-transfer capabilities.
Before running any of the commands in this annoyance, I strongly suggest that you back up the data on your hard drive. The commands described in this annoyance may stress your hard drive beyond its capabilities. For best results during the backup, set your computer to single-user mode (init 1), which reduces the load from most services and network connections.
In this annoyance, we focus on the hdparm command, based on a Freshmeat project of the same name (http://freshmeat.net/projects/hdparm). If you can't find this command, install an hdparm package native to your distribution; it's available for at least Red Hat/Fedora, SUSE, and Debian.
8.5.1. Hard Drive Defaults
Before adjusting any device, you should establish a baseline by figuring out the default settings and checking its performance. To that end, the following command tests the speed at which Linux can read data from your hard drive, directly (-t) and through a buffer (-T):
# hdparm -Tt /dev/hda /dev/hda: Timing buffer-cache reads: 384 MB in 2.01 seconds = 191.04 MB/sec Timing buffered disk reads: 66 MB in 3.06 seconds = 21.57 MB/sec
You may want to run this command more than once, to make sure that you have consistent baseline readings. I find small variations, under 20 percent, to be fairly common.
Next, find the baseline settings for communication between Linux and your hard drive:
# hdparm /dev/hda /dev/hda: multicount = 16 (on) IO_support = 0 (default 16-bit) unmaskirq = 0 (off) using_dma = 1 (on) keepsettings = 0 (off) readonly = 0 (off) readahead = 8 (on) geometry = 1940/240/63, sectors = 29336832, start = 0
Make a record of your hdparm parameters. If after making changes, you encounter problems, you can then return to your original parameters. Here is a description of the parameters:
There are a substantial number of additional hdparm options, listed on the associated manpage.
8.5.2. Adjusting Hard Drive Parameters
With the right hdparm command, you may be able to increase the effective speed of your hard drive. Given the number of settings, some trial and error is required. In other words, test the throughput of each change with the hdparm -Tt command.
I'll now detail some of the more common changes that you can make to IDE/ATA hard drive parameters. See the associated manpage for details.
Sometimes, hdparm will tell you if your hardware or distribution can't handle a setting associated with faster data transfer. For example, when I try to configure a multicount of 32 on three of my systems, I get the following result:
# hdparm -m32 /dev/hda /dev/hda: setting multicount to 32 HDIO_SET_MULTICOUNT: Invalid argument multicount = 16 (on)
No problem, time to try something else. When I try to configure 32-bit I/O support on my computers, I see the following:
# hdparm -c3 /dev/hda /dev/hda: setting 32-bit IO_support flag to 3 IO_support = 3 (32-bit w/sync)
Now that you've changed the setting, it's time to test the result. Run the hdparm -Tt command again. It's OK to run this command more than once, to see if the change is significant. If so, make a note of the change. You'll want to make sure Linux implements this change the next time you boot that computer.
You can set up commands such as hdparm -c3 in the appropriate configuration file, which varies by distribution: Debian uses /etc/hdparm.conf; SUSE uses settings in /etc/sysconfig/ide based on variables in /etc/init.d/boot.idedma; Red Hat Enterprise Linux uses /etc/sysconfig/harddisks. Starting with Fedora Core 5, Red Hat has deprecated the use of such configuration files; these settings can be added to /etc/rc.local.