CLI Magic: Hdparm and the Zen of data transfer

86

Author: Joe Barr

There is a place for the GUI and its cocoon-like protective services, grasshopper. But at times it stands between you and enlightenment like a pit of sticky silly putty on the path to grokking your hardware. Take your hard drive, for example. If you ever want to go mano a mano with your IDE drive, especially an older model, you need to shed that GUI like a snake molting its skin and meet me at the CLI, where we can talk about the magic of hdparm.This handy utility provides a wealth of information about the settings of your IDE drives. Better still, it allows you to tweak them if necessary to improve performance. Please note: it’s possible that using hdparm to tweak your settings can damage your drive or its contents. Be smart and backup any data on a drive prior to twiddling with its setting bits. Of course, if you weren’t the adventuresome type, you wouldn’t be studying life on the CLI, now would you.

Let’s see what hdparm has to say about my 15GB Western Digital drive, aka in these parts as /dev/hda. Your /dev hard drive permissions are probably set for root and group access only, with no permissions at all for the world at large. If they’re not, they should be. In any case, su to root before entering the hdparm commands.

Here’s what hdparm has to say about /dev/hda on my system with no options specified other than the drive itself:

# hdparm /dev/hda

/dev/hda: multcount = 16 (on) IO_support = 1 (32-bit) unmaskirq = 1 (on) using_dma = 1 (on) keepsettings = 0 (off) readonly = 0 (off) readahead = 256 (on) geometry = 29104/16/63, sectors = 15020457984, start = 0

If you add an “-i” to the hdparm command above, it will report on the identification of the drive, like this:

# hdparm -i /dev/hda

/dev/hda: Model=WDC WD150EB-00BHF0, FwRev=15.15M15, SerialNo=WD-WMA6K2947273 Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq } RawCHS=16383/16/63, TrkSize=57600, SectSize=600, ECCbytes=40 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=16 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=29336832 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 AdvancedPM=no WriteCache=enabled Drive conforms to: device does not report version: * signifies the current active mode

Hdparm will also give you some idea of the speed of throughput from the drive to the CPU. If you don’t shut down to single-user mode and curtail all other processing, the results won’t be too meaningful. To get the measurements hdparm can provide for my 15GB Western Digital, I entered hdparm -Tt /dev/hda. I took mine under a normal system load which includes an Internet security application — Zoneminder — which means Apache and MySQL were running as well, so the results varied wildly based on what was happening at the time. Here is a sample of how hdparm responded:

/dev/hda:
 Timing cached reads:   548 MB in  2.10 seconds = 260.99 MB/sec
 Timing buffered disk reads:   22 MB in  3.32 seconds =   6.63 MB/sec

Let’s compare the settings on my drive with the tweaking tip mentioned on the hdparm project page on Freshmeat, which claims “Most drives can benefit from improved performance using a command similar to “hdparm -qm8 -qu1 -qc1 -qd1 /dev/hda”.

Ignore the q in each option, it simply tells hdparm to execute silently. The options cited above break down as follows:

  • -qm8 Set multiple sector count to 8
  • -qu1 Set unmaskirq flag on
  • -qc1 Set 32-bit IO on
  • -qd1 Set DMA on

While those are all good tips, my drive was already configured at least that well. And that’s the rub with hdparm: events have conspired the past few years which make it less valuable today than it has been in the past.

Hard drive performance has outrun processor performance to the point that waiting on data to keep the CPU busy is no longer a bottleneck in most applications. Drives today are simply spinning much faster: 7,500, 10,000 or even 15,000 RPM drives are available off the shelf. Older drives, of course, can still benefit from such .

But don’t write hdparm off completely for even the latest drives, it still has utility beyond teaching you more about the zen of your system hardware. It’s possible that your system is underutilizing even newer drives, specifically in the choice of data transfer modes. You might add a new drive that is capable of UDMA transfers at faster speed than it is configured for. If your mainboard and chipset are also capable of the higher transfer rate, you can use hdparm to tweak the drive to use the faster setting.

I exchanged email with Hdparm’s author, Mark Lord, and he was kind enough to take the time to teach me a little bit more about the origins and utility of the program. I asked if he had written it originally as an aid for writing device drivers, and he replied, “Yes. Specifically, I wrote it to help me with development of the original Linux IDE driver that I worked on and maintained for many years.”

Commenting on its usefullness with new drives, Lord said, “So long as DMA is already ‘on’, most hdparm features won’t make much of a difference with performance. But the “-W” (write-cache) is one thing that makes a substantial improvement in performance on nearly all systems.”

I ended by asking Lord who the major users of Hdparm are today. He told me:

Just about every major distro invokes hdparm as part of system startup.
Aside from that, individuals also use it to do “-W1” (write cache on),
to control the drive’s acoustic management settings, to control auto
spin-down for laptops on battery power, etc…

Even users of SATA drives make frequent use of hdparm.

As always, see the man about hdparm, and pay particular attention to its various warnings as you explore the true nature of your system.