justlinux.com
Sun, 27-May-2012 11:35:39 GMT

Forum: Registered Users: 76222, Online: 301
nhfs Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home Home

Help File Library: Hard Drive Speed Tweak for Linux


Written By: Fancy Piper
fancypiper's note: Check out O'reilly's article on Speeding up Linux Using hdparm

Enabling 32-bit I/O and DMA for the hard drives

See man hdparm for complete details and cautions.

Some Linux distributions aren't optimized for your specific system, so tweaks are necessary. I run RedHat 6.1, and here is how I sped up my disk speed by enabling 32-bit I/O and DMA on my system.

The turning on/off of the 32-bit I/O and DMA has to be done by root with all root privileges. I su - and query my current settings and time the harddrive current performance:

[phil@fancypiper phil]$ su -
Password:

[root@fancypiper /root]# hdparm -c /dev/hda

/dev/hda:
I/O support = 0 (default 16-bit)


[root@fancypiper /root]# hdparm -c /dev/hdb

/dev/hdb:
I/O support = 0 (default 16-bit)

[root@fancypiper /root]# hdparm -t /dev/hda

/dev/hda:
Timing buffered disk reads: 64 MB in 17.58 seconds = 3.64 MB/sec


[root@fancypiper /root]# hdparm -t /dev/hdb

/dev/hdb:
Timing buffered disk reads: 64 MB in 17.44 seconds = 3.67 MB/sec

Both my drives are set to 16 bit and no DMA. Now, I turn on the 32 bit I/O and DMA and check the timing with the new settings.

[root@fancypiper /root]# hdparm -c 1 -d 1 /dev/hda

/dev/hda:
setting 32-bit I/O support flag to 1
setting using_dma to 1 (on)
I/O support = 1 (32-bit)
using_dma = 1 (on)
[root@fancypiper /root]# hdparm -c 1 -d 1 /dev/hdb

/dev/hdb:
setting 32-bit I/O support flag to 1
setting using_dma to 1 (on)
I/O support = 1 (32-bit)
using_dma = 1 (on)

[root@fancypiper /root]# hdparm -t /dev/hda

/dev/hda:
Timing buffered disk reads: 64 MB in 11.77 seconds = 5.44 MB/sec


[root@fancypiper /root]# hdparm -t /dev/hdb

/dev/hdb:
Timing buffered disk reads: 64 MB in 5.24 seconds =12.21 MB/sec


[root@fancypiper /root]#

Quite an improvement, especially the second drive!

You can commit these settings by commanding:

[root@fancypiper /root]# hdparm -k 1 /dev/hda

/dev/hda:
setting keep_settings to 1 (on)
keepsettings =  1 (on)
[root@fancypiper /root]# hdparm -k 1 /dev/hdb

/dev/hdb:
setting keep_settings to 1 (on)
keepsettings =  1 (on)

To apply these settings on re-boot, they must be placed in some startup file. Since I use the RedHat 6.1 distro of Linux, I add this to the bottom of my /etc/rc.d/rc.local file.

Here is my /etc/rc.d/rc.local file for an example:


#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

if [ -f /etc/redhat-release ]; then R=$(cat /etc/redhat-release)

arch=$(uname -m) a="a" case "_$arch" in
_a*) a="an";;
_i*) a="an";; esac

NUMPROC=`egrep -c "^cpu[0-9]+" /proc/stat` if [ "$NUMPROC" -gt "1" ]; then SMP="$NUMPROC-processor " if [ "$NUMPROC" = "8" -o "$NUMPROC" = "11" ]; then a="an" else a="a" fi fi

# This will overwrite /etc/issue at every boot. So, make any changes you # want to make to /etc/issue here or you will lose them when you reboot. echo "" > /etc/issue echo "$R" >> /etc/issue echo "Kernel $(uname -r) on $a $SMP$(uname -m)" >> /etc/issue

cp -f /etc/issue /etc/issue.net echo >> /etc/issue fi

# Added by phil # This sets 32 bit I/O and DMA for hard drives hdparm -c 1 -d 1 -k 1 /dev/hda

hdparm -c 1 -d 1 -k 1 /dev/hdb

Now enjoy your zippier Linux.

fancypiper@crosswinds.net

Note Added by Jeff

Don't try this at home, kids! On my machine (Pentium MMX 233), the test hdparm -c 1 -d 1 /dev/hdb, hdparm -t /dev/hdb resulted in a small but significant improvement in throughput.

However, when I added the line hdparm -c 1 -d 1 -k 1 /dev/hdb to /etc/rc.d/rc.local, Linux would no longer boot! Got all kinds of disk errors. Be wary.