Adeptus-Mechanicus

Main
Codex
Librarium Whitehat
Advisories
Blog Pics
"Inveniam viam aut faciam" : I will either find a way, or I shall make one


HDPARM - REV YOUR DISK

One of the many wonderful things about linux is the fact that you can tune just about anything. You can fiddle to scrape the last bit of performance out of your machine. Of course you may also screw it up, but hey, you would'nt be fiddling if you did'nt know what you doing ... right?

Well to help you fiddle I'm going to introduce the hdparm command.I will be going through some of the uses, remember that there are many more to check out. And as always, fiddle carefully and at your own risk.

What is it?
hdparm allows you to tune the ATA driver settings. You can query and modify settings. It will also allow you to test your configuration. If you do change settings and your machine does not fall over then just add those settings to your system startup. Remember that hdparm must be run as root.

Testing 1,2,3...
The first thing to do is test your drives to see how they are functioning. Lets first lay a little groundwork regarding ATA specifications;

UDMA Mode Common Name Max. Transfer
0
n/a
16.7 MB/s
1
n/a
25 MB/s
2
Ultra-ATA/33
33 MB/s
3
n/a
44.4 MB/s
4
Ultra-ATA/66
66.7 MB/s
5
Ultra-ATA/100
100 MB/s
6
ULtra-ATA/133
133 MB/s

You should also know what speed's your hardware supports. Then we'll start with testing your drive. Let's start with the -t flag. This measurement is an indication device reads and of how fast the drive can sustain sequential data reads under Linux, without any filesystem over-head.So..
hdparm -t /dev/hda (This will test the the primary device on the first channel)
You should get a result looking something like this (of course results will vary),
Timing buffered disk reads: 80 MB in 3.00 seconds = 26.67 MB/sec
Next, try the -T flag. This does timings of cache reads. This measurement is essentially an indication of the throughput of the processor, cache, and memory of the system under test. So...
hdparm -T /dev/hda
You should get a result looking something like this,
Timing buffer-cache reads: 528 MB in 2.01 seconds = 262.69 MB/sec

Show Me the Specs
hdparm can also show a wealth of information regarding your drive, it's configuration and features. Take a look, try... hdparm -I /dev/hda I'm not going to give the full listing for my drive, it's just too much. But here is a snippet of the type of information you will get,
Capabilities:

LBA, IORDY(can be disabled)

bytes avail on r/w long: 40 Queue depth: 1

Standby timer values: spec'd by Standard, with device specific minimum

R/W multiple sector transfer: Max = 16 Current = 16

Recommended acoustic management value: 128, current value: 254

DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 *udma5

Cycle time: min=120ns recommended=120ns

PIO: pio0 pio1 pio2 pio3 pio4

Cycle time: no flow control=120ns IORDY flow control=120ns
To get a brief listing of the current settings you could also try a plain, hdparm /dev/hda (no flags). You should get something like,
/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 = 8 (on)
geometry = 1216/255/63, sectors = 19541088, start = 0

Vroom, vroom
Now the number of tweaks you can use hdparm for are many, so I'm just going to go through some of the safer more common ones. Take a look at...
hdparm -c1 -m16 -d1 -u1 /dev/hda
In this command the -c flag enables 32-bit transfers to the ATA controller (You could also try using a 3 setting for this flag). The -m flag sets the maximum number of sectors to transfer in a single request. The -d flag will enable DMA. The -u flag permits the unmasking of other interrupts during processing of a disk interrupt, which greatly improves responsiveness. Re-test the drive after this to see if there has been an increase in speed. If there has and the system remains stable, consider adding the command to your machine's startup sequence.

Power to the People
hdparm will also allow you to set power management options for your drive, if your drive allows it. Check with hdparm -I /dev/hda. If under the Commands/features section, under the Enabled Supported heading you see * Power Management feature set, then you will be able to tell it to power down after a sepecified period of inactivity. You could use,
hdparm -S10 /dev/hda
The -S switch will set the spin-down time in multiple of 5, so 10 would mean that the drive should spin down after 50 seconds of inactivity.

That's it for a quick run through hdparm, I hope it's been helpful. Remember it can do a lot more, so look at the rest of the options, and happy fiddling.


-The homepage for hdparm - http://freshmeat.net/projects/hdparm/