Testing and Optimizing Disk Performance under Linux





To test your disk’s performance, use the hdparm utility. This program’s main purpose is to display and set various ATA parameters that influence performance. The program can also run basic performance tests. The -t parameter tests disk read speed, while the -T parameter tests Linux’s disk cache performance. The cache speed is important to overall disk performance, but for purposes of testing, you don’t want the cache to interfere with raw disk performance tests. You can combine the two tests, and hdparm will apply correction factors to separate the two measures. Following the -Tt parameter, you specify the hard disk you want to test as follows:

# /sbin/hdparm -Tt /dev/hdb

2007-11-27-141732_1280x800_scrot

In order to get reliable results, you should perform these tests on a system that’s otherwise not doing much, and especially not performing any disk-intensive tasks.
What’s poor performance? This depends on the disk. You should be able to find detailed specifications for your disk on the manufacturer’s website. You need to find the specification for sustained transfer speeds to and from the disk’s media.

If you believe your disk speed is deficient, you should search for a reason for the problem. In the case of ATA disks, the -v parameter to hdparm produces a summary of disk settings:

# /sbin/hdparm -v /dev/hdb

2007-11-27-141754_1280x800_scrot

The most important setting displayed by this output is the using_dma item. This setting reveals whether the controller is using direct memory access (DMA) mode, in which the controller directly transfers data between the disk and the computer’s memory. The alternative is programmed input/output (PIO) mode, in which the computer’s CPU mediates all transfers. DMA mode is generally faster than PIO mode, and DMA transfers impose a lower CPU load, so disk accesses should not slow down CPU-intensive programs as much.

If Linux isn’t running your disks in an optimal mode, you can use hdparm to adjust its settings. In some cases, you can apply driver-specific options to your ATA driver. Finally, one issue of disk performance doesn’t relate to speed, but it is important to laptop users: energy use. You can configure the disks to spin down when they haven’t been accessed for some time, thereby saving energy.

Normally, a computer’s hard disks spin whenever the computer is turned on. This feature makes disk access swift, because there’s no need to begin spinning the disk to access a file; however, it consumes a fair amount of power. Therefore, spinning down a disk when it’s not in use is helpful. Doing so is particularly helpful on laptop computers, on which a spinning hard disk can greatly reduce battery life. hdparm supports the -S option to set this feature.

Value Meaning

0 Power-saving mode disabled; disk never goes into low-power mode.

1–240 Time in 5-second multiples; for instance, 12 means 60 seconds.

241-251 Units of 30 minutes (241), 60 minutes (242), and so on through 5.5 hours (251).

252 21 minutes.

253 Drive-specific timeout value.

255
21 minutes and 15 seconds.

For instance, to set the disk to power down after ten minutes of inactivity, you could type the following command:

# hdparm -S120 /dev/hda



Subscribe without commenting


Leave a Reply

Note: Any comments are permitted only because the site owner is letting you post, and any comments will be removed for any reason at the absolute discretion of the site owner.