| View previous topic :: View next topic |
| Author |
Message |
nukes Linux Guru

Joined: 29 Aug 2003 Posts: 4558
|
Posted: Thu Aug 26, 2004 10:37 pm Post subject: Tuning up your hard disks using hdparm. |
|
|
Tuning up your IDE hard disks using hdparm.
hdparm is a tool for altering various parameters associated with IDE
drives (Not SCSI). This involves things like the block prefetch, the DMA/PIO modes,
and a number of other things.
I'm writing this mini-how-to to help people get more from their system. People often
complain that Linux is a bit slow for them (which it can be) I haven't seen such
a post recently, but I know on TechIMO at least we always used to be talking
people through using hdparm.
As ever, you do all this at your own risk - nothing should go wrong, but it's your fault and not mine if it does.
hdparm can be used on a running system. It doesn't require filesystems on the disk to be unmounted in order to work, so you can play with it all you want. Some settings like -Y will require a hard reboot to get the disk back - use with caution.
All settings will be lost at reboot, so you can play around and find a config that suits you. Also, it can be useful to benchmark the drives using "hdparm -tT" which performs a buffer read and a disk read. For best results do it on a system with no other active processes (to remove external influence).
i.e.
| Code: |
nexus richard # hdparm -tT /dev/hde
/dev/hde:
Timing buffer-cache reads: 1584 MB in 2.00 seconds = 790.15 MB/sec
Timing buffered disk reads: 118 MB in 3.04 seconds = 38.77 MB/sec
nexus richard #
|
All the settings will be lost at reboot, but some distros have a configuration file you can edit to set the hdparm settings at boot. On Gentoo this is /etc/conf.d/hdparm.
Germ says that in Mandrake/RH (possibly other RH based systems) it is /etc/sysconfig/harddisks.
I don't use any other distros, but if people tell me where these files are, I'll add them
Each may have a slightly different syntax, but your distribution's documentation should cover it.
You could also put all the commands in your rc.local file. If you do so, you
might want to look at the -q switch to suppress output from the
Most of the information here is available in the hdparm manpage, but I know it
can be quite intimidating for all levels of user. It's still worth a read.
The syntax is quite simple, for example, to enable DMA on /dev/hda, you would do:
| Code: |
hdparm -d1 /dev/hda
|
The -d1 represents DMA enabled, -d0 would disable DMA.
Switches can be chained together on a single line, as you'll see shortly.
General performance improvements:
The first thing you would generally want to do is enable DMA and set the multicount and readahead to reasonable settings.
| Code: |
hdparm -d1 -m16 -A1 -a64 -u1 /dev/hda
|
Now, I'll take each of these in turn.
-d1 -- Enables DMA
-m16 -- Sets the number of sectors to use for IDE block mode (multicount)
-A1 -- Enables the auto-readahead feature of the drive
-a64 -- tells the drive how far to read ahead.
-u1 -- Enables unmasking of interrupts. Greatly improves performance.
Can cause problems with certain IDE chipsets on certain 2.0.x kernels.
The numbers beside the -a and -m can be changed, mess about if you like, but
I've found these to work quite well. The -d, -A, and -u are all boolean.
IMPORTANT
The manpage mentions being careful with the multicount flag, claiming that some controller/disk combinations can lead to filesystem corruption. More info is in the man page.
You can run "hdparm -i" on a hard disk to get the modes supported, and the maximum multicount setting.
Here's an example:
| Code: |
nexus richard # hdparm -i /dev/hde
/dev/hde:
Model=WDC WD400JB-00ETA0, FwRev=77.07W77, SerialNo=WD-WCAHL5369247
Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq }
RawCHS=16383/16/63, TrkSize=57600, SectSize=600, ECCbytes=74
BuffType=DualPortCache, BuffSize=8192kB, MaxMultSect=16, MultSect=16
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=78165360
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
nexus richard #
|
The "MaxMultiSect" is the number you should use for the multicount setting, It also lists the DMA modes you can use.
Here's the big one: UDMA modes.
I'm assuming that everyone has at least some sort of ATA hard disk, I can find
the codes for the other modes if you need them, just post here or PM me
To enable UDMA, you use -Xxx where xx is the transfer mode.
Here's how it stacks up:
-X64 : UDMA 0 (ATA 16)
-X65 : UDMA 1 (ATA 25)
-X66 : UDMA 2 (ATA 33)
-X67 : UDMA 3 (ATA 44)
-X68 : UDMA 4 (ATA 66)
-X69 : UDMA 5 (ATA 100)
-X70 : UDMA 6 (ATA 133)
Just add that to the hdparm command line, and you'll probably see the difference
straight away if you have one of the faster modes.
Remember that ATA66 and above require an 80-wire IDE cable (the extra 40 wires
are earthed to give some shielding)
Needless to say, specifying a mode faster than the drive/controller/cable can
handle will either just not work, or could wipe out the data on it.
Acoustic Management
You also use hdparm to set the speed of the disks (using -M). If you slow them down, they
are quieter and use less power, but also run slower. If you run them at full
speed, they're fast and use the normal amount of power.
The speed is represented by a single integer from 0 to 254, but the lowest one
you can have is 128.
Not all drives take notice of this, and the feature is still experimental. (in
hdparm 5.4 which I use at least)
So, to slow a drive right down, do:
| Code: | | hdparm -M128 /dev/hda |
and for full speed:
| Code: | | hdparm -M254 /dev/hda |
Power Management
To set the drives to spin down after, say 10 minutes of inactivity, use the -S
switch. This takes a number as it's option. The numbering is a little peculiar,
so I'll quote the manpage which will explain it better than I could.
| The hdparm team wrote: |
The encoding of the timeout value is somewhat
peculiar. 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, and the value 254 is reserved. 255 is interpreted as
21 minutes plus 15 seconds. Note that some older drives may
have very different interpretations of these values. |
On my system, I have it set to 180 (15 Min's) and it looks like this:
| Code: | | hdparm -S180 /dev/hda |
(remember that it's multiples of 5 seconds instead of just seconds or
minutes)
ANOTHER WARNING
Mmmna tells me there's a possibility that if the disk spins down, then restarts
before it's fully shut down, it could lead to an overload in some of the power
circuitry:
| mmmna wrote: |
Restarting a hot drive (one that has not been cooling for very long, say 2 seconds) may cause a startup situation to be allowed when the power circuits are still 'hot'. That startup scenario assumes the platters have stopped rotating. Thus, when the command to spin up is given, and the platters are stopped, and the power control circuitry has not cooled enough, then the surge currents are pushed through hot circuits and that is a possible overstress condition that I, as an engineering technician, had to be watchful for, when I was qualifying new new prototypes.
|
I can't seem to find a way to keep a drive shut down for a defined amount of time using hdparm. If you have any ideas, PM me or post.
Here's the setup on my system:
| Code: | | hdparm -d1 -A1 -m16 -u1 -a64 -X69 -S180 /dev/hda |
I run that on hda and hdg. hdg doesn't support ATA100, so I run it with X68
It's worth enabling DMA for CDROMs as well.
You may redistribute and modify this as you please. It would be nice if I was given credit, or if someone linked back to www.usalug.org, but I'm not too bothered
Nukes
nukes at usalug dot org
Thanks to Germ and Mmmna for their contributions.
[edit]
I made it a sticky just so it stays visible for a few days. I'll ditch the sticky status soon enough - don't worry 
_________________ Gentoo x86-64 2.6.29.1
FreeBSD 7-CURRENT
Arch x86 2.6.30
|
|
| Back to top |
|
lynch Moderator

Joined: 15 Nov 2003 Posts: 2647 Location: The Diamond State
|
|
| Back to top |
|
bluegroper New Member
Joined: 09 Sep 2004 Posts: 1
|
Posted: Thu Sep 09, 2004 11:27 am Post subject: Hdparm |
|
|
I'm trying to setup a small linux fileserver for home. Should be ideal, yes ?
Using a GA-60XE m/board, 256Mb PC-100 Ram, PIII-800 and some HDD's. BogoMips = 1602.
M/board has ATA/100 (aka udma5) on board. So I try a Seagate 40Gb ATA/100 drive.
Fresh install of ClarkConnect2.2. Test with hdparm -t. Speed is 56 Mb/sec. Looking for more.
So I try this with a 60Gb Maxtor ATA/133. Fresh install CC2.2 again. Of course it only using udma5.
Hdparm -t /dev/hda speed is 33 Mb/sec. Why slower ?
Next I install a brand new Promise Ultra133/TX2 pci card and try that with the Maxtor.
Fresh install of CC 2.2 again. (Good thing it only takes 10 minutes.)
I checks /var/log/dmesg and hdparm -i /dev/hde and confirm ATA/133, (aka udma6) is being used.
Hdparm -t /dev/hde speed still only 33 Mb/sec.
How come the slower drive, is seemingly faster ? And only using ATA/100 ?
Should I also be doing something in GA-60XE Bios to change the drive settings ? (I've tried Auto, Manual, LBA, None, etc all without effect.)
Anybuddy got any other ideas how to squeeze some extra performance out of this kit ?
TIA's
- BG
BTW(1), I do have multcount=16(on), IO_support=1(32 bit), and using_dma=1(on) each time.
BTW(2), I have tried to STF and RTFineM, but alas so far no solution
More TIA's too.
|
|
| Back to top |
|
Stuka Sr. Member
Joined: 15 Oct 2003 Posts: 1271 Location: Houston, TX
|
Posted: Thu Sep 09, 2004 2:41 pm Post subject: |
|
|
| The 33 Mb/sec number sounds a LOT like PIO, and not UDMA. I know you've checked that, so it seems odd that it's not getting better speed, but that's sure what it looks like on first inspection.
|
|
| Back to top |
|
nukes Linux Guru

Joined: 29 Aug 2003 Posts: 4558
|
Posted: Thu Sep 09, 2004 3:08 pm Post subject: |
|
|
| Check the output of "hdparm -i" for the disk. That should tell you whether the mode has been set and list certain options.
_________________ Gentoo x86-64 2.6.29.1
FreeBSD 7-CURRENT
Arch x86 2.6.30
|
|
| Back to top |
|
jbilas Advanced Member

Joined: 14 Sep 2004 Posts: 924 Location: New York, USA
|
|
| Back to top |
|
nukes Linux Guru

Joined: 29 Aug 2003 Posts: 4558
|
Posted: Wed Sep 15, 2004 10:27 am Post subject: |
|
|
I experimented with that one, but it actually slowed two of my disks down (according to the cache and disk tests):
| Code: | nexus richard # hdparm -tT /dev/hde
/dev/hde:
Timing cached reads: 1500 MB in 2.00 seconds = 749.74 MB/sec
Timing buffered disk reads: 72 MB in 3.00 seconds = 23.96 MB/sec
nexus richard # hdparm -c3 /dev/hde
/dev/hde:
setting 32-bit IO_support flag to 3
IO_support = 3 (32-bit w/sync)
nexus richard # hdparm -tT /dev/hde
/dev/hde:
Timing cached reads: 1508 MB in 2.00 seconds = 753.74 MB/sec
Timing buffered disk reads: 74 MB in 3.06 seconds = 24.16 MB/sec
nexus richard # hdparm -tT /dev/hda
/dev/hda:
Timing cached reads: 1568 MB in 2.00 seconds = 782.94 MB/sec
Timing buffered disk reads: 78 MB in 3.00 seconds = 25.96 MB/sec
nexus richard # hdparm -c3 /dev/hda
/dev/hda:
setting 32-bit IO_support flag to 3
IO_support = 3 (32-bit w/sync)
nexus richard # hdparm -tT /dev/hda
/dev/hda:
Timing cached reads: 1540 MB in 2.00 seconds = 769.35 MB/sec
Timing buffered disk reads: 78 MB in 3.16 seconds = 24.67 MB/sec
nexus richard #
|
It provided a slight improvement, but it only affects the link to the controller, not the disk itself. If it works for you, that's fine, but you still don't get great throughput from the drives.
_________________ Gentoo x86-64 2.6.29.1
FreeBSD 7-CURRENT
Arch x86 2.6.30
|
|
| Back to top |
|
jbilas Advanced Member

Joined: 14 Sep 2004 Posts: 924 Location: New York, USA
|
|
| Back to top |
|
schleyfox Ultimate Member

Joined: 25 Jan 2004 Posts: 2376 Location: In front of my computer
|
Posted: Wed Sep 15, 2004 8:19 pm Post subject: |
|
|
| I have a stupid n00b question, will this work on SATA? I mean they are more IDE than SCSI so i would assume so but i dont want to wreck my beautiful drive.
_________________ Gentoo 2005.1 2.6.13
Gentoo 2005.1 2.6.11
Ubuntu Hoary Hedgehog PPC
|
|
| Back to top |
|
jbilas Advanced Member

Joined: 14 Sep 2004 Posts: 924 Location: New York, USA
|
|
| Back to top |
|
Germ Keeper of the BIG STICK

Joined: 30 Apr 2003 Posts: 12329 Location: Planet Earth
|
Posted: Thu Sep 16, 2004 10:45 am Post subject: |
|
|
| jbilas wrote: | ....Anyhow, for SATA you can run
| Code: | | hdparm -X66 -d1 /dev/hda |
|
ATA 33 for a SATA drive?
_________________ Laptop: Mandriva 2010 PowerPack - kernel 2.6.32.7mib
Desktop: Mandriva 2010 Free - kernel 2.6.32.7mib
|
|
| Back to top |
|
jbilas Advanced Member

Joined: 14 Sep 2004 Posts: 924 Location: New York, USA
|
Posted: Thu Sep 16, 2004 5:40 pm Post subject: |
|
|
| Germ wrote: | | jbilas wrote: | ....Anyhow, for SATA you can run
| Code: | | hdparm -X66 -d1 /dev/hda |
|
ATA 33 for a SATA drive? |
OK, let me correct myself.
From hdparm man-page:
| Quote: |
For multiword DMA, the value used is the desired DMA mode number plus 32. for UltraDMA, the value is the desired UltraDMA mode number plus 64.
|
Therefore X66 isnt ATA33 but UDMA2.
The -X66 I use on 2.4 kernel which on 7200 rpm/8 MB SATA gives me about 1,3 MB/sec (got suggestion from Alan Cox, Im sure you know who it is).
Now, you can surely experiment with other settings (-X69, even -X70) and see if it works for you.
Cheers
_________________ Arch Linux 2.6.24-ARCH
|
|
| Back to top |
|
nukes Linux Guru

Joined: 29 Aug 2003 Posts: 4558
|
|
| Back to top |
|
Germ Keeper of the BIG STICK

Joined: 30 Apr 2003 Posts: 12329 Location: Planet Earth
|
|
| Back to top |
|
wrahmad New Member
Joined: 01 Nov 2004 Posts: 1
|
Posted: Mon Nov 01, 2004 7:18 pm Post subject: |
|
|
| hi, i have some problem with my harddisk. i'am using mandrake 8.2 with 2.4.18 kernel. when i try to activate dma parameter, i got message like HDIO_DMA failure : operation not permitted. so i can't use dma mode. when i check with hdparm -t /dev/hda, i got 7 MB/s. the funny thing is, when i use debian 3.0 with 2.2.20 kernel, i can activate dma mode and i got 33 MB/s using hdparm -t /dev/hda. is there something wrong with the kernel?. i am using Gigabyte mobo with via kt-600 chipset. thanx for the help....
|
|
| Back to top |
|
|