Improving Disk Performance

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.

Adjusting Disk Parameters

Just as hdparm can read disk parameters, it can write them. Table 2.3 summarizes some of the parameters you can pass to ATA disks to modify their settings.

Table 2.3: hdparm Parameters for Improving Disk Performance





0,1, or3

Enables (1 or3) or disables p) 32-bit

data transfers between the CPU and

ATA controller. Mode 1 is a normal

enabling; 3 enables the mode using a

special sync sequence required by

some chipsets.





0 or 1

Enables (1) or disables p) DMA transfer mode.


Positive integers

Sets the speed of a CD-ROM. This parameter normally isn't needed. Its main use is in lowering a drive's speed to better read a scratched disc.


Power-of-two integers (2,4, 8, etc.)

Sets the number of sectors exchanged per transfer cycle. Most drives work best with a value of 16 or32, but some drives require lower values (4 or 8, typically). A value of 0 disables multisector transfer, causing transfers of one sector at a time.


0 to5

Sets the PIO mode used by the drive. Higher modes produce better performance, but not all drives support all modes. Setting the wrong mode may hang the computer.


0 or 1

Enables (1) or disables P) the ability of the system to unmask the IRQ of a drive. In general, enabling this feature results in increased system responsiveness, but it's been known to cause unreliable operation with some controllers. Do not capitalize this option; the capital -U option unregisters (disables) an interface!


sdmax, mdmax, orudmax

Sets the ATA transfer mode. On modern systems, a value of udmax, where x is the UltraDMA mode, enables that mode, which produces the best performance. Older drives may require use of the mdmax or sdmax modes to set multiword or




simple DMA modes, respectively.

(Again, x is the DMA mode number.)

Table 2.1 summarizes DMA transfer


As a general rule, drives power up in a mode that's optimal, and most distributions have configuration scripts that either don't change these settings or that also set drives for optimal performance. Occasionally, though, this isn't the case, so you may need to experiment with hdparm options and then set up a local configuration script to do the job automatically when you reboot, as described in Chapter 9, "Bypassing Automatic Configurations to Gain Control." In these cases, a line such as the following should do the trick:

hdparm -d1 -X udma5 /dev/hda

Of course, you may need to adjust the ATA transfer mode (udma5 in this example) to suit your drives and host adapter. In some cases, including additional options from Table 2.3 can improve performance further.

Warning Both the -d and -X parameters are potentially very dangerous. Don't play with them idly unless you're prepared to hang your computer. Note The hdparm performance-tweaking parameters apply only to ATA devices; you can't use these options to improve the performance of SCSI devices. SCSI host adapters are much smarter than ATA controllers, so SCSI devices don't need these tweaks. You may be able to use driver options to improve the performance of some SCSI devices, though.

Adjusting Driver Parameters

Chapter 1 described the process of passing parameters to the kernel or to individual modules. Although rare, some ATA and SCSI drivers support options that can affect performance. Consult the driver's documentation for details. Check for documentation files in the/usr/src/linux/Documentation directory. (Red Hat uses linux-2.4 rather than linux in this pathname.)

Spinning Down a Disk to Save 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, as an energy-saving measure, spinning down a disk when it's not in use is sometimes desirable. Doing so is particularly helpful on laptop computers, on which a spinning hard disk can greatly reduce battery life. Therefore, hdparm supports the -S option to set this feature. Unfortunately, the encoding of this feature is rather odd, as outlined in Table 2.4.

Table 2.4: Power-Saving Options Set with hdparm -S




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


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


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


21 minutes.


Drive-specific timeout value.


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:

You can place this command in a startup script, as described in Chapter 9, to have it run automatically whenever you boot. One caveat concerning disk power-saving options is that Linux is a very disk-intensive OS. The system may need to access the disk at unexpected times, even if nobody is actively using the computer. Thus, power savings may be smaller under Linux than under some OSs. Powering up a drive also takes time, but typically it takes well under 10 seconds. For this reason, you may prefer to forego the energy-saving mode on desktop systems or when a laptop is plugged into a power supply.

Team LIB

Team LIB

^ previous

0 0

Post a comment