Gentoo Wiki ArchivesGentoo Wiki

Hdparm

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc


Please improve it in any way that you see fit, and remove this notice {{Cleanup}} from the article. For tips on cleaning and formatting see Cleanup process


Contents

Introduction

Hdparm is a tool that allows you to set IDE device settings. This includes things such as DMA modes, transfer settings and various other settings that can help improve the speed of your hard disks and CDROMs. These settings are not enabled by default, so you will probably want to enable them. This guide is also intended to provide more up-to-date information on hdparm settings and inform the user how to check what settings are supported so that the optimum settings for the drive can be used. Many hdparm guides simply tell people to enable specific modes such as '-X33' or '-c1', and as most of these guides are now out-of-date many people end up using those older settings when better, newer options may now be used. By speeding up your hard drives you should get a faster system. It should also help solve stuttering DVD playback or extremely slow burning.

Note: much of this document is tailored towards standard IDE connected devices. If you use SATA or SCSI, look at using sdparm instead of hdparm.

Notice (RAID and such)

HDParm is the root of all evil with Software/BIOS-RAID.

Most disks do not sync evenly with DMA enabled, the more drives you have the less speed you should set.

Installing hdparm

Firstly check if hdparm is already installed on your system by typing the following as root:

emerge -n hdparm

Getting information about your different drives

Different drives have different capabilities, so in order to configure them you must know what they are capable of doing. # hdparm -i /dev/hdX should give you the information you need (replace hdX with your drive)

Udev systems also allow for drives to be accessed with a slightly more understandable filename.

For hard drives (replace X with the disc number): hdparm -i /dev/discs/disc#/disc, and for CDROMs: hdparm -i /dev/cdroms/cdrom#/cdrom

You should get something similar to the following

Code: hdparm -i /dev/hdd

Model=WDC WD80EB-28CGH2, FwRev=24.84G24, SerialNo=WD-WMA9N7936819
Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq }
RawCHS=15509/16/63, TrkSize=57600, SectSize=600, ECCbytes=40
BuffType=DualPortCache, BuffSize=768kB, MaxMultSect=16, MultSect=16
CurCHS=15509/16/63, CurSects=15633072, LBA=yes, LBAsects=15633072
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes:  pio0 pio1 pio2 pio3 pio4
DMA modes:  mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 *udma2 udma3 udma4 udma5
AdvancedPM=no WriteCache=enabled
Drive conforms to: device does not report version:

* signifies the current active mode

You will want to repeat this process for each IDE HDD/CDROM you have. Pay attention to the MaxMultSect and maximum mode available from the PIO/DMA/UDMA modes.

Benchmarking devices

hdparm -tT

hdparm includes a handy benchmark mode, which should allow you to see how much of a speed improvement each of the different settings gives you. When running a benchmark it is recommended that you close all programs that could interfere with the results. Ideally do it from the console, rather than in a xterm with xorg running. To perform a benchmark, issue a command like the following - once again replacing X with your drive letter:

# hdparm -tT /dev/hdX

You should then get some speed results like the following:

Code: hdparm -tT /dev/hdX
/dev/hdd:
Timing cached reads:   496 MB in  2.00 seconds = 247.42 MB/sec
Timing buffered disk reads:   60 MB in  3.03 seconds =  19.81 MB/sec

It is recommended that you benchmark all your drives and save the results before you start tweaking them, so that you can tell how much of an improvement you are getting.

For example, the following test was run on a hard drive supporting UDMA6:

Code: hdparm -tT /dev/hdX
/dev/hda:
Timing cached reads:   1104 MB in  2.00 seconds = 551.53 MB/sec
Timing buffered disk reads:  170 MB in  3.00 seconds =  56.58 MB/sec

Here's a hard drive set to low, slow settings:

Code: # hdparm -cuda /dev/hda
/dev/hda:
 IO_support   =  0 (default 16-bit)
 unmaskirq    =  0 (off)
 using_dma    =  0 (off)
 readahead    = 256 (on)

And here is its performance information:

Code: # hdparm -tT /dev/hda
/dev/hda:
Timing cached reads:   344 MB in  2.08 seconds = 165.37 MB/sec
Timing buffered disk reads:   10 MB in  3.48 seconds =   2.87 MB/sec

This is the same hard drive, after rebuilding the kernel with the Cotroller's drivers and DMA enabled (see below: "I get "Operation not permitted" errors on setting DMA (-d1)"):

Code: # hdparm -cuda /dev/hda
/dev/hda:
 IO_support   =  1 (32-bit)
 unmaskirq    =  1 (on)
 using_dma    =  1 (on)
 readahead    = 256 (on)

And this is the performance statistics for those settings:

Code: # hdparm -tT /dev/hda
/dev/hda:
 Timing cached reads:   464 MB in  2.01 seconds = 231.06 MB/sec
 Timing buffered disk reads:   54 MB in  3.06 seconds =  17.65 MB/sec
Note: The IDE Controller in this system doesn't support higher udma levels than udma4, so with a newer controller and udma6 you will probably get better improvements.

bonnie++

Sometimes hdparm -tT won't show any differences when tweaking hdparm settings, or will show inaccurate results. bonnie++ does more accurate and in-depth analysis of the hard drive speed. Here is a comparison from my system (hdparm -tT gave ~ 260/570 kbps for cached/buffered reads in BOTH cases):

Code: # hdparm -d0 -u0; bonnie++
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
minihenk       300M  3224  52  6115  14  2980  27  3588  89  5687  25  81.8   1
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16   285  96 +++++ +++ 17444  91   286  95 +++++ +++  1012  89
minihenk,300M,3224,52,6115,14,2980,27,3588,89,5687,25,81.8,1,16,285,96,+++++,+++,17444,91,286,95,+++++,+++,1012,89
Code: # hdparm -d1 -u1 -X udma5; bonnie++
Version  1.03       ------Sequential Output------ --Sequential Input- --Random-
                    -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
minihenk       300M  6058  95 13055  27  5570  11  6650  88 12852  12  89.5   1
                    ------Sequential Create------ --------Random Create--------
                    -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP
                 16   282  95 +++++ +++ 17567  92   288  96 +++++ +++  1038  92
minihenk,300M,6058,95,13055,27,5570,11,6650,88,12852,12,89.5,1,16,282,95,+++++,+++,17567,92,288,96,+++++,+++,1038,92

Changing device settings

Warning: Changing settings could possibly damage your hardware or make your system unstable. Most newer drives should cope fine but do so at your own risk!

Note: These setting will be removed upon a system reboot. After you have found the optimal settings for your hard drive, you must follow the instructions below to make them load at bootup.

Checking current settings

Some settings can be checked by omitting the number used to set it. For instance to check the current DMA mode setting:

# hdparm -d /dev/hda

Some setting however will not work, such as the xfer mode (-X) will set the xfer mode to 0 rather than giving you the current setting or like write-caching (-W) will ask you to give the setting. You can generally find out all the setting on a current drive with a simple

# hdparm /dev/hda

This should give you something similar to the following:

Code: hdparm /dev/hda
/dev/hda:
multcount    = 16 (on)
IO_support   =  3 (32-bit w/sync)
unmaskirq    =  1 (on)
using_dma    =  1 (on)
keepsettings =  0 (off)
readonly     =  0 (off)
readahead    = 256 (on)
geometry     = 15509/16/63, sectors = 8004132864, start = 0

Or use a hdparm -i as described above for more advanced settings such as transfer mode.

DMA mode -d

Changing DMA modes can sometimes cause some older systems to lockup, you have been warned!

The first mode you will probably want to enable is DMA. DMA is important to enable. You will want to enable DMA on DVD drives if you want to watch or burn DVD's -- without turning on DMA your DVD playback is likely to stutter, and burning can take over an hour rather than a few minutes. It also has a much higher chance of failing. Enabling DMA on normal cdroms or hard drives is also highly recommended. It should improve speeds a great deal and reduce cpu load. You must have the DMA option for your chipset compiled in your kernel -- it should appear under "Device Drivers>ATA/ATAPI/MFM/RRL support"; select the specific option for your chipset. You can use the following command to check what your IDE chipset is:

# lspci |grep -i ide

To enable DMA on a device type the following:

# hdparm -d1 /dev/hda

Now run a benchmark and see how much of an improvement you have received.

Xfer mode (PIO/SDMA/MDMA/UDMA) -X

DMA actually has several different possible xfer modes. These are PIO 1-4 (Programmed IO), SDMA 0-2 (Single-word DMA), MDMA 0-2 (Multi-word DMA) and UDMA 0-5 (Ultra-DMA). These modes are set with the following command, replace ## with the desired mode and hda with your drive:

# hdparm -X## /dev/hda

Generally the higher the mode, the better. Here is a list of different xfer modes and their corresponding number:

0123456
PIO0809101112
SDMA161718
MDMA323334
UDMA64656667686970

E.g. To set UDMA6:

# hdparm -X70 /dev/hda

You can also select the desired mode by specifing the name of the mode:

# hdparm -X udma6 /dev/hda

For most modern hard drives you will probaly want to use a UDMA mode. After enabling a xfer mode run a hdparm -i to ensure that the mode has actually been set. Once you have set the desired mode try another benchmark.

Note: hdparm man-page claims that the best mode is set by the drive itself on startup. My own tests have the same result. I only got worse performance by fiddling around with this parameter.

32-bit IO_SUPPORT -c

You can set 32-bit IO support with the -c# flag. There are 4 different levels of IO_Support

0default 16-bit
132-bit
216-bit
332-bit w/sync

If possible you will probably want option 1. However, some chipsets do support 32 bit I/O, but have compatibility problems. These chipsets need the sync option, which slows things down a tiny bit. They should use option 3. Only if you experience problems with both options 1 and 3, use option 0 or 2. Most (but not all) newer chipsets work fine with option 1. Here is how you can enable 32 bit I/O on your chipset.

# hdparm -c1 /dev/hda

This setting changes how the data is moved from the PCI bus to the controller. It can double your throughput.

Note that this flag will only affect controllers running on one of the PCI ports. Standard IDE controllers do not benefit.

MultSect -m

When you did hdparm -i on your drive you should have a section MaxMultSect. You can set you MultSect to this with the -m flag shown in the following command, replace # with your MaxMultSect:

# hdparm -m# /dev/hda

This controls how many sectors are fetched from the disk in a single I/O interrupt. Most newer drives should be able to handle a MultSect of 16, or 8 for older ones. Changing this setting should reduce system resources from disk access and also increase disk bandwidth. Note that this is only relevant for PIO modes, and not for DMA modes, where high numbers of sectors are always used, up to 256 on older drives, and up to 65535 on newer drives. The vast majority of drives in use today will be set by the kernel to use a (U)DMA mode by default, making this option irrelevant.

unmaskirq -u

You can enable unmaskirq with the following:

# hdparm -u1 /dev/hda

Enabling unmasking lets Linux unmask other interrupts while handling a disk interrupt, allowing your system to do other similar tasks at the same time and should improve overall system response time.

Spindown -S

Warning: The '-S' option is not compatible with the use of the app-laptop/laptop-mode-tools (see Disk Power Management).
If you are looking for a good powersaving policy for your laptop, the best is to read the whole Power Management Guide.

This Option controls the Spindown of your drive.

# hdparm -Sx /dev/hda

The Time (in seconds) after which the Drive spins down is the value of your x multiplied with 5 From the manpage:

A value of zero means "timeouts are disabled": the device will not automatically enter standby mode.
Values from 1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes.
Values from 241 to 251 specify from 1 to 11 units of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours.
A value of 252 signifies a  timeout  of  21  minutes.
A value of 253 sets a vendor-defined timeout period between 8 and 12 hours.
A value of 255 is interpreted as 21 minutes plus 15 seconds.
The value 254 is reserved.
Note that some older drives may have very different interpretations of these values.

Example:

hdparm -S12 /dev/hda

Now the drive spins down after 1 minute. (12x5=60s) To turn it off choose x=0.

Acoustic Management -M

# hdparm -Mx /dev/hda

128 is the quiet-modus. If you set x to 254 you will get the maximum of speed, but you can also choose a number between.

Power Management -B

This Option controls the Power Management of your drive.

# hdparm -Bx /dev/hda

Set x to 1 to get the maximum powersave or set x to 255 to turn off the Power Management.You can also choose a number between.

Write-Caching -W

Write-caching can be enabled with the following:

# hdparm -W1 /dev/hda

Write-Caching has been reported to have problems with journaling filesystems (For instance ext3 and Reiser), and it is recommended that you don't enable it on such systems.

Read-lookahead -A

Read-lookahead can be enabled with the following:

# hdparm -A1 /dev/hda

Readahead -a

The readahead fs setting can be changed with:

# hdparm -a# /dev/hda

My hard drives have 256 already automatically set.

What's the readahead? Well, each time a file sector is read on the hard drive, the system will read some further sectors of that file, just in case. Indeed most often those further sectors will soon be asked for... The amount of sectors are given in the hdparm -a n /dev/hdx command. This allows for a gain sometimes. Actually a lot of times, since it allows a software to start up to three times faster! Now the problem is in some cases reading further sectors is pointless or even a loss of time. Suppose a server that handles a giant database file. It accesses random tiny parts of the database at a time. If each time a few bytes of the file are being accessed, a whole bunch of 1024 further sectors of the file are read, this represents a severe loss of performance. So, setting a low readahead on such a server can greatly enhance performance.

A readahead lower than 8 sectors means no readahead.

Making the hdparm options permanent

Now that you have worked out your ideal hdparm option, you need to edit the /etc/conf.d/hdparm file to ensure that the setting are reloaded next time your system is rebooted (on RedHat, the file is /etc/sysconfig/harddisks).

You should be presented the following file:

File: /etc/conf.d/hdparm (default)
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-apps/hdparm/files/hdparm-conf.d.3,v 1.2 2004/09/06 02:17:08 swegener Exp $

# You can either set hdparm arguments for each drive using hdX_args,
# discX_args, cdromX_args and genericX_args, e.g.
#
# hda_args="-d1"
# disc1_args="-d1"
# cdrom0_args="-d1"

# or, you can set hdparm options for ALL drives using all_args, e.g.
#
# all_args="-d1"

If most of your drives will be using the same setting, modify the all_args line to reflect your desired hdparm settings. Here is an example file, hda and hdb are standard hard drives that support UDMA-5, hdc only supports UDMA-2 and hdd is a cdrom with readahead of 8 and only supporting UDMA-0, as its a basic cdrom no write caching is needed.

File: /etc/conf.d/hdparm (Sample)
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-apps/hdparm/files/hdparm-conf.d.3,v 1.2 2004/09/06 02:17:08 swegener Exp $

# You can either set hdparm arguments for each drive using hdX_args,
# discX_args, cdromX_args and genericX_args, e.g.
#
# hda_args="-d1"
# disc1_args="-d1"
# cdrom0_args="-d1"

# or, you can set hdparm options for ALL drives using all_args, e.g.
#
#all_args="-d1"
hda_args="-A1 -d1 -u1 -c3 -X69 -W1 -m16"
hdb_args="$hda_args"
hdc_args="-A1 -d1 -u1 -c3 -X66 -W1 -m16"
hdd_args="-A1 -d1 -u1 -c3 -X64 -m16 -a8"

Lastly, add hdparm to be run at boot:

# rc-update add hdparm boot

Troubleshooting

hdparm -i shows a UDMA mode however nothing happens when i try and set that mode

This is most likely because your mother board doesn't support the higher ATA modes required to run this mode. If you are sure that your mother board supports the mode make sure that the device is attached to the correct IDE plug on the mother board. Different ATA specifications have different coloured sockets on the motherboard.

Here is a list of the different UDMA modes and the ATA requirement:

UDMAATA
0ATA 16
1ATA 24
2ATA 33
3ATA 44
4ATA 66
5ATA 100
6ATA 133

I get "Operation not supported" errors on even basic commands such as 'hdparm -i'

You are probaly attempting to use hdparm on a SATA or some other bizarre drive. hdparm currently has very limited support for SATA drives however these drives are generally setup automatically to use most of the more decent settings. You should be able to get the basic information (without the -i) and benchmarking to work. Try benchmarking the drive to check if you are getting good speeds (generally above 1000MB for cached reads and above 50MB for buffered reads).

sdparm is virtually the same as hdparm. blktool is an alternatative to hdparm with some support for SATA and SCSI drives.

I get "Operation not permitted" errors on setting DMA (-d1)

Your kernel is not supporting these IDE instructions. After compiling the kernel with all settings right, the same error returns, and this is a bug / sloppy hardware problem (my experience). You might want to try to compile your IDE chipset extension into the kernel, NOT AS A MODULE. That way this code loads before IDE_GENERIC and the problem is gone.

If the latter is not helpful, check your BIOS settings. For example, using ASUS's "enhanced IDE" mode which is labeled as native to Win2K/XP will cause your system to come to a crawl. There may be several other BIOS settings for your drive that will cause performance problems. If you have BIOS options available for your drive, make sure they look right to you before you endeavor to refine your Kernel.

Other BIOS settings to look out for concern the mixing between SATA and IDE devices. If you have a SATA drive but Linux is seeing it as IDE (i.e. it appears as /dev/hd*, rather than /dev/sd*) then your BIOS is emulating IDE, and you may not be able to persuade hdparm to do anything useful. You'll have to change your BIOS settings to present the drive as SATA. If you do this, be careful to ensure that your BIOS is still trying to boot off the correct drive; if you have some other IDE drive connected it may try to boot off that instead of your SATA drive (giving a "non-system disk or disk error" or the like). These various settings can be scattered across different pages of the BIOS setup, so be persistent!

Hard disk on master, CD/DVD drive on slave IDE channel: CD/DVD drive is limiting transfer mode of master

If you cannot set the UDMA mode of your hard disk higher than that of your CD drive, something may be wrong with your kernel configuration. For example, if you know you have an PIIX chipset, then do not activate "Generic PCI IDE Chipset Support" in "Device Drivers->ATA/ATAPI/MFM/RLL support", but use the appropriate driver ("Intel PIIXn chipsets support"). I had both options activated and wondered why it would not work correctly.

References

TODO

Concerns or Compliments? Please use the Discussion section.

Retrieved from "http://www.gentoo-wiki.info/Hdparm"

Last modified: Wed, 27 Aug 2008 19:33:00 +1000 Hits: 161,499

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.