Use_hdparm_to_improve_IDE_device_performance

http://gentoo-wiki.com/HOWTO_Use_hdparm_to_improve_IDE_device_performance

Introduction
Hdparm is a tool that allows you to set IDE device settings. This includes things such as DMA modes, transfer settings and various other settings that can help improve the speed of your hard disks and CDROMs. These settings are not enabled by default, so you will probably want to enable them. This guide is also intended to provide more up-to-date information on hdparm settings and inform the user how to check what settings are supported so that the optimum settings for the drive can be used. Many hdparm guides simply tell people to enable specific modes such as '-X33' or '-c1', and as most of these guides are now out-of-date many people end up using those older settings when better, newer options may now be used. By speeding up your hard drives you should get a faster system. It should also help solve stuttering DVD playback or extremely slow burning.

[edit]Installing hdparm
Firstly check if hdparm is already installed on your system by typing the following as root:

emerge -n hdparm
[edit]Getting information about your different drives
Different drives have different capabilities, so in order to configure them you must know what they are capable of doing. # hdparm -i /dev/hdX should give you the information you need (replace hdX with your drive)

Udev systems also allow for drives to be accessed with a slightly more understandable filename.

For hard drives (replace X with the disc number): hdparm -i /dev/discs/disc#/disc, and for CDROMs: hdparm -i /dev/cdroms/cdrom#/cdrom

You should get something similar to the following

Code: hdparm -i /dev/hdd

Model=WDC WD80EB-28CGH2, FwRev=24.84G24, SerialNo=WD-WMA9N7936819
Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq }
RawCHS=15509/16/63, TrkSize=57600, SectSize=600, ECCbytes=40
BuffType=DualPortCache, BuffSize=768kB, MaxMultSect=16, MultSect=16
CurCHS=15509/16/63, CurSects=15633072, LBA=yes, LBAsects=15633072
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

You will want to repeat this process for each IDE HDD/CDROM you have. Pay attention to the MaxMultSec and maximum mode available from the PIO/DMA/UDMA modes.

[edit]Benchmarking devices
hdparm includes a handy benchmark mode, which should allow you to see how much of a speed improvement each of the different settings gives you. When running a benchmark it is recommended that you close all programs that could interfere with the results. Ideally do it from the console, rather than in a xterm with xorg running. To perform a benchmark, issue a command like the following - once again replacing X with your drive letter:

# hdparm -tT /dev/hdX
You should then get some speed results like the following:

Code: hdparm -tT /dev/hdX
/dev/hdd:
Timing cached reads: 496 MB in 2.00 seconds = 247.42 MB/sec
Timing buffered disk reads: 60 MB in 3.03 seconds = 19.81 MB/sec

It is recommended that you benchmark all your drives and save the results before you start tweaking them, so that you can tell how much of an improvement you are getting.

For example, the following test was run on a hard drive supporting UDMA6:

Code: hdparm -tT /dev/hdX
/dev/hda:
Timing cached reads: 1104 MB in 2.00 seconds = 551.53 MB/sec
Timing buffered disk reads: 170 MB in 3.00 seconds = 56.58 MB/sec

Here's a hard drive set to low, slow settings:

Code: # hdparm -cuda /dev/hda
/dev/hda:
IO_support = 0 (default 16-bit)
unmaskirq = 0 (off)
using_dma = 0 (off)
readahead = 256 (on)

And here is its performance information:

Code: # hdparm -tT /dev/hda
/dev/hda:
Timing cached reads: 344 MB in 2.08 seconds = 165.37 MB/sec
Timing buffered disk reads: 10 MB in 3.48 seconds = 2.87 MB/sec

This is the same hard drive, after rebuilding the kernel with the Cotroller's drivers and DMA enabled (see below: "I get "Operation not permitted" errors on setting DMA (-d1)"):

Code: # hdparm -cuda /dev/hda
/dev/hda:
IO_support = 1 (32-bit)
unmaskirq = 1 (on)
using_dma = 1 (on)
readahead = 256 (on)

And this is the performance statistics for those settings:

Code: # hdparm -tT /dev/hda
/dev/hda:
Timing cached reads: 464 MB in 2.01 seconds = 231.06 MB/sec
Timing buffered disk reads: 54 MB in 3.06 seconds = 17.65 MB/sec
Note: The IDE Controller in this system doesn't support higher udma levels than udma4, so with a newer controller and udma6 you will probably get better improvements.
[edit]Changing device settings
Warning: Changing settings could possibly damage your hardware or make your system unstable. Most newer drives should cope fine but do so at your own risk!

Note: These setting will be removed upon a system reboot. After you have found the optimal settings for your hard drive, you must follow the instructions below to make them load at bootup.
[edit]Checking current settings
Some settings can be checked by omitting the number used to set it. For instance to check the current DMA mode setting:

# hdparm -d /dev/hda
Some setting however will not work, such as the xfer mode (-X) will set the xfer mode to 0 rather than giving you the current setting or like write-caching (-W) will ask you to give the setting. You can generally find out all the setting on a current drive with a simple

# hdparm /dev/hda
This should give you something similar to the following:

Code: hdparm /dev/hda
/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 = 256 (on)
geometry = 15509/16/63, sectors = 8004132864, start = 0

Or use a hdparm -i as described above for more advanced settings such as transfer mode.

[edit]DMA mode -d
Changing DMA modes can sometimes cause some older systems to lockup, you have been warned!

The first mode you will probably want to enable is DMA. DMA is important to enable, you will want to enable DMA on DVD drives if you want to watch or burn DVD's, without turning on DMA your DVD playback is likely to stutter and burning can take over an hour rather than a few minutes and has a much higher chance of failing. Enabling DMA on normal cdroms or hard drives is also highly recommended, it should improve speeds a great deal and reduce cpu load. You must also have the DMA option for your chipset compiled in your kernel, it should appear under "Device Drivers>ATA/ATAPI/MFM/RRL support", then select the specific option for your chipset. You can use the following command to check what your IDE chipset is:

# lspci |grep -i ide
To enable DMA on a device type the following:

# hdparm -d1 /dev/hda
Now run a benchmark and see how much of an improvement you have received.

[edit]Xfer mode (PIO/SDMA/MDMA/UDMA) -X
DMA actually has several different possible xfer modes. These are PIO 1-4 (Programmed IO), SDMA 0-2 (Single-word DMA), MDMA 0-2 (Multi-word DMA) and UDMA 0-5 (Ultra-DMA). These modes are set with the following command, replace ## with the desired mode and hda with your drive:

# hdparm -X## /dev/hda
Generally the higher the mode, the better. Here is a list of different xfer modes and their corresponding number:

0 1 2 3 4 5 6
PIO 08 09 10 11 12
SDMA 16 17 18
MDMA 32 33 34
UDMA 64 65 66 67 68 69 70

E.g. To set UDMA6:

# hdparm -X70 /dev/hda
You can also select the desired mode by specifing the name of the mode:

# hdparm -X udma6 /dev/hda
For most modern hard drives you will probaly want to use a UDMA mode. After enabling a xfer mode run a hdparm -i to ensure that the mode has actually been set. Once you have set the desired mode try another benchmark.

Note: hdparm man-page claims that the best mode is set by the drive itself on startup. My own tests have the same result. I only got worse performance by fiddling around with this parameter.
[edit]32-bit IO_SUPPORT -c
You can set 32-bit IO support with the -c# flag. There are 4 different levels of IO_Support

0 default 16-bit
1 32-bit
2 16-bit
3 32-bit w/sync

If possible you will probably want option 1. However, some chipsets do support 32 bit I/O, but have compatibility problems. These chipsets need the sync option, which slows things down a tiny bit. They should use option 3. Only if you experience problems with both options 1 and 3, use option 0 or 2. Most (but not all) newer chipsets work fine with option 1. Here is how you can enable 32 bit I/O on your chipset.

# hdparm -c1 /dev/hda
This setting changes how the data is moved from the PCI bus to the controller. It can double your throughput.

[edit]MultSect -m
When you did hdparm -i on your drive you should have a section MaxMultSect. You can set you MultSect to this with the -m flag shown in the following command, replace # with your MaxMultSect:

# hdparm -m# /dev/hda
This controls how many sectors are fetched from the disk in a single I/O interrupt. Most newer drives should be able to handle a MultSect of 16, or 8 for older ones. Changing this setting should reduce system resources from disk access and also increase disk bandwidth. Note that this is only relevant for PIO modes, and not for DMA modes, where high numbers of sectors are always used, up to 256 on older drives, and up to 65535 on newer drives. The vast majority of drives in use today will be set by the kernel to use a (U)DMA mode by default, making this option irrelevant.

[edit]unmaskirq -u
You can enable unmaskirq with the following:

# hdparm -u1 /dev/hda
Enabling unmasking lets Linux unmask other interrupts while handling a disk interrupt, allowing your system to do other similar tasks at the same time and should improve overall system response time.

[edit]Spindown -S
This Option controls the Spindown of your drive.

# hdparm -Sx /dev/hda
The Time (in seconds) after which the Drive spins down is the value of your x multiplied with 5 From the manpage:

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.
A value of 255 is interpreted as 21 minutes plus 15 seconds.
The value 254 is reserved.
Note that some older drives may have very different interpretations of these values.
Example:

hdparm -S12 /dev/hda
Now the drive spins down after 1 minute. (12x5=60s) To turn it off choose x=0.

[edit]Acoustic Management -M
# hdparm -Mx /dev/hda
128 is the quiet-modus. If you set x to 254 you will get the maximum of speed, but you can also choose a number between.

[edit]Power Management -B
This Option controls the Power Management of your drive.

# hdparm -Bx /dev/hda
Set x to 1 to get the maximum powersave or set x to 255 to turn off the Power Management.You can also choose a number between.

[edit]Write-Caching -W
Write-caching can be enabled with the following:

# hdparm -W1 /dev/hda
Write-Caching has been reported to have problems with journaling filesystems (For instance ext3 and Reiser), and it is recommended that you don't enable it on such systems.

[edit]Read-lookahead -A
Read-lookahead can be enabled with the following:

# hdparm -A1 /dev/hda
[edit]Readahead -a
The readahead fs setting can be changed with:

# hdparm -a# /dev/hda
My hard drives have 256 already automatically set.

[edit]Making the hdparm options permanent
Now that you have worked out your ideal hdparm option, you need to edit the /etc/conf.d/hdparm file to ensure that the setting are reloaded next time your system is rebooted.

You should be presented the following file:

File: /etc/conf.d/hdparm (default)
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-apps/hdparm/files/hdparm-conf.d.3,v 1.2 2004/09/06 02:17:08 swegener Exp $

# You can either set hdparm arguments for each drive using hdX_args,
# discX_args, cdromX_args and genericX_args, e.g.
#
# hda_args="-d1"
# disc1_args="-d1"
# cdrom0_args="-d1"

# or, you can set hdparm options for ALL drives using all_args, e.g.
#
# all_args="-d1"

If most of your drives will be using the same setting, modify the all_args line to reflect your desired hdparm settings. Here is an example file, hda and hdb are standard hard drives that support UDMA-5, hdc only supports UDMA-2 and hdd is a cdrom with readahead of 8 and only supporting UDMA-0, as its a basic cdrom no write caching is needed.

File: /etc/conf.d/hdparm (Sample)
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-apps/hdparm/files/hdparm-conf.d.3,v 1.2 2004/09/06 02:17:08 swegener Exp $

# You can either set hdparm arguments for each drive using hdX_args,
# discX_args, cdromX_args and genericX_args, e.g.
#
# hda_args="-d1"
# disc1_args="-d1"
# cdrom0_args="-d1"

# or, you can set hdparm options for ALL drives using all_args, e.g.
#
#all_args="-d1"
hda_args="-A1 -d1 -u1 -c3 -X69 -W1 -m16"
hdb_args="$hda_args"
hdc_args="-A1 -d1 -u1 -c3 -X66 -W1 -m16"
hdd_args="-A1 -d1 -u1 -c3 -X64 -m16 -a8"

Lastly, add hdparm to be run at boot:

# rc-update add hdparm boot
[edit]Troubleshooting
[edit]hdparm -i shows a UDMA mode however nothing happens when i try and set that mode
This is most likely because your mother board doesn't support the higher ATA modes required to run this mode. If you are sure that your mother board supports the mode make sure that the device is attached to the correct IDE plug on the mother board. Different ATA specifications have different coloured sockets on the motherboard.

Here is a list of the different UDMA modes and the ATA requirement:

UDMA ATA
0 ATA 16
1 ATA 24
2 ATA 33
3 ATA 44
4 ATA 66
5 ATA 100
6 ATA 133
[edit]I get "Operation not supported" errors on even basic commands such as 'hdparm -i'
You are probaly attempting to use hdparm on a SATA or some other bizarre drive. hdparm currently has very limited support for SATA drives however these drives are generally setup automatically to use most of the more decent settings. You should be able to get the basic information (without the -i) and benchmarking to work. Try benchmarking the drive to check if you are getting good speeds (generally above 1000MB for cached reads and above 50MB for buffered reads).

blktool is an alternatative to hdparm with some support for SATA and SCSI drives.

[edit]I get "Operation not permitted" errors on setting DMA (-d1)
Your kernel is not supporting these IDE instructions. After compiling the kernel with all settings right, the same error returns, and this is a bug / sloppy hardware problem (my experience). You might want to try to compile your IDE chipset extension into the kernel, NOT AS A MODULE. That way this code loads before IDE_GENERIC and the problem is gone.

If the latter is not helpful, check your BIOS settings. For example, using ASUS's "enhanced IDE" mode which is labeled as native to Win2K/XP will cause your system to come to a crawl. There may be several other BIOS settings for your drive that will cause performance problems. If you have BIOS options available for your drive, make sure they look right to you before you endeavor to refine your Kernel.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值