Hack 99. Boost Hard-Drive Performance


IDE hardware.To be on the safe side, your new Linux installation starts up with
the least common denominator of disk drive performance
capabilitiestypically DMA-33robbing you of 50-150% of
your potential performance. Once Linux is installed, you are free and
encouraged to start tweaking the configuration of your disk drive and
its interface to squeeze the most of them.
|
available from your package manager). It can be adjusted manually and
then put into a startup script to make your chosen settings effective
every time the system starts up.HDPARM is a command-line utility that provides powerful control over
your hard drive parameters (HD PARaMeters). It can also tell you a
lot about your disk drive. Everything you do with HDPARM, until you
make a script for it, will be done at the command line.
|
drive. (This is the default for the first IDE drive; a SATA drive may
appear as /dev/hde if your motherboard also has
IDE interfaces.) Run the following command:
hdparm -i /dev/hdaYou should get some info like the following:
/dev/hda:This tremendous amount of data provided tells you:MaxMultSect
Model=QUANTUM FIREBALLlct, FwRev=APL.1234, SerialNo=1234567
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
RawCHS=16383/16/63, TrkSize=32256, SectSize=21298, ECCbytes=4
BuffType=DualPortCache, BuffSize=418kB, MaxMultSect=8, MultSect=off
CurCHS=16383/16/63, CurSects=-66060037, LBA=yes, LBAsects=39876478
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 udma0 udma1 udma2 udma3 udma4 *udma5
AdvancedPM=no
Drive Supports : ATA/ATAPI-5 T13 1321D revision 1 : ATA-1 ATA-2
ATA-3 ATA-4 ATA-5
The maximum number of sectors your hard disk can read at a time.
MultSect
The current number of sectors being read at a time.
PIO modes and DMA modes
The modes supported by your hard drive. The one marked with an
asterisk (*) is the one currently set.
AdvancedPM
Indicates whether or not your hard drive supports Advanced Power
Management.
Another command:
hdparm /dev/hdareveals the following information:
/dev/hda:The items of interest are:multcount
multcount = 0 (on)
I/O support = 0 (16-bit)
unmaskirq = 0 (off)
using_dma = 0 (off)
keepsettings = 0 (off)
nowerr = 0 (off)
readonly = 0 (off)
readahead = 8 (on)
geometry = 2482/255/63, sectors = 39876480, start = 0
The number of sectors being read at a time.
I/O support
The operating mode of your hard disk (16/32/32sync).
using_dma
Whether or not the drive is using the DMA feature. This may be on by
default if your version of Linux properly detects and supports your
chipset and drive's DMA capabilities.
keepsettings
Whether the settings are kept after the drive resets (usually caused
by errors).
readonly
Whether the drive is read-only. Normally set to 1
only for CD-ROMs.
readahead
How many sectors ahead will be read when you access the hard drive.
The HDPARM program provides two performance-testing features that are
crucial to letting you know whether you're making
improvements as you tweak along. The command:
hdparm -Tt /dev/hda1will show results such as the following before enhancing the
performance:
/dev/hda1:and then results like these after enhancing the performance:
Timing buffer-cache reads: 128 MB in 5.97 seconds = 21.43 MB/sec
Timing buffered disk reads: 64 MB in 17.97 seconds = 3.56 MB/sec
Timing buffer-cache reads: 128 MB in 0.91 seconds =140.66 MB/secThe goal of this hack is to see the time in seconds decrease and the
Timing buffered disk reads: 64 MB in 3.78 seconds = 16.93 MB/sec
MB/sec to increase. You can do that by using a variety of parameters,
invoked one at a time, then rerunning the performance tests to see if
things are improving.Mistakes during the setup process may damage your filesystem and all
of its data, so it's best to do this after a fresh
install of Linux or right after you've done a full
backup.Begin by setting the operating mode of the interface between the
system and the disk drive using one of the following parameters:
hdparm -c0 /dev/hda #sets operating mode to 16-bitsMode 1 (-c1) is used most often for best
hdparm -c1 /dev/hda #sets operating mode to 32-bits
hdparm -c3 /dev/hda #sets operating mode to 32-bits synchronized
performance. Mode 3 (-c3) only is needed for some
chipsets.Next set the data transfer parameters, which you can determine from
the output of the "-I" command
shown earlier (in that case 8 is the maximum supported):
hdparm -m8 /dev/hdaNext try activating DMA mode for your system interface:
hdparm -d1Then set the drive mode (a value of X32 is most common; UDMA-5 is
X69):
hdparm -X32 /dev/hdaor:
hdparm -X69 /dev/hdaFinally, try setting the read-ahead value, which is typically set to
the same value as multcount from earlier, or 8:
hdparm -a8 /dev/hdaIf any or all of these settings make incremental improvements in
performance, remember them and create a script that sets them all
sequentially or includes them all in one line. I prefer sequential
lines to ensure the drive accepts each command separately and I do
not lose a setting if another fails to take. From all of this, you
might typically be using the following parameters:
hdparm -c1Another single-command example that may work best for your system is:
hdparm -m8 /dev/hda
hdparm -d1
hdparm -X34 /dev/hda
hdparm -a8 /dev/hda
hdparm -X66 -d1 -u1 -m16 -c3 /dev/hdaSave to a file and make the file a script to place in the directory
for the runlevel at which you normally use Linux. For example:
- Using a text editor, create then save the script as
/etc/init.d/hdparm.local.Configure it to start in runlevel 5 with the following command:
ln -s /etc/init.d/hdparm.local /etc/rc5.d/S20hdparm.localThe rc5.d part of the parameter string indicates
runlevel 5, which is the normal operating mode for most Linux
systems. To find out your default runlevel, examine
/etc/inittab for the inittdefault
entry, as in:
id:5:initdefault:The next step is to keep an eye on dmesg and/or
/var/log/syslog. In some cases, an error will
cause the settings to be reset. So that's where the
-k (keep) flag comes in. If
you're 100% positive that these settings
won't corrupt your data, you can add
-k to the script.Jim Aspinwall