分享

hdparm 优化硬盘的配置

 chenix 2006-12-22
hdparm 优化硬盘的配置

Reference: 2

1,Linux通用系统优化... 2

2,中文手册: 3

3,英文手册: 7

4, Speeding up Linux Using hdparm.. 15

 

 

    需要配置的原因是硬盘不断更新换代,linux系统为了兼容和稳定,默认没有采用较新的硬盘技术.

俺们的流媒体服务器配置:
/sbin/hdparm -c3 -u1 -d1 -m0 /dev/hda
/sbin/hdparm -c3 -u1 -d1 -m0 /dev/sda
/sbin/hdparm -c3 -u1 -d1 -m0 /dev/sdb
/sbin/hdparm -c3 -u1 -d1 -m0 /dev/hdc

分别为采用32位模式,响应其他中断,打开DMA模式,最后一个是扇区,估计是因为采用了自己的文件系统,内部有优化,所以关闭这个特性

-X因为大多数/全部现代 IDE 驱动器默认它们最快的 PIO 传输模式为打开. 所以摆弄它是没有必要的也是冒险的.

 

 

比较有用的参数如下:

Hdparm命令的一些常用的其他参数功能

 

-g 显示硬盘的磁轨,磁头,磁区等参数。

-i 显示硬盘的硬件规格信息,这些信息是在开机时由硬盘本身所提供。

-I 直接读取硬盘所提供的硬件规格信息。

-p 设定硬盘的PIO模式。

-Tt 评估硬盘的读取效率和硬盘快取的读取效率。

-u <01> 在硬盘存取时,允许其他中断要求同时执行。

-v 显示硬盘的相关设定。

 

尤其是

[root@ME_90_146 rss]# hdparm  -Tt /dev/hda

 

/dev/hda:

 Timing buffer-cache reads:   128 MB in  0.20 seconds =624.39 MB/sec

 Timing buffered disk reads:  64 MB in  1.39 seconds = 45.94 MB/sec

[root@ME_90_146 rss]#

 

[root@ME_90_146 rss]# hdparm /dev/hda

 

/dev/hda:

 multcount    =  0 (off)

 IO_support   =  3 (32-bit w/sync)

 unmaskirq    =  1 (on)

 using_dma    =  1 (on)

 keepsettings =  0 (off)

 readonly     =  0 (off)

 readahead    =  8 (on)

 geometry     = 30401/255/63, sectors = 488397168, start = 0

 

 



Reference:


1,Linux通用系统优化
http://blog./u/19412/showart_185301.html

使用hdparm改善Linux系统性能

 

如果你的Linux系统运行于IDE硬盘,可以使用hdparm工具来提高磁盘I/O的性能。不过使用hdparm要小心,因为可能破坏硬盘上的数据。所以在使用hdparm之前,仔细阅读你的硬盘手册。根据你具体的硬盘规格来使用相应的hdparm开关参数。对一块UltraATA/66

EIDE 硬盘,其控制芯片支持多 PIO 模式和DMA,我们使用以下命令来调谐磁盘性能:

 

# /sbin/hdparm -x66 -d1 -u1 -m16 -c3 /dev/hda

 

选项说明:

c3 :就是把硬盘的16位格式转换为32位模式(32-bit mode w/sync)。控制数据如何从pci总线传递到控制器。

m16 :改变硬盘的多路扇区的读功能,-m16可以使得硬盘在一次i/o中断中读入16个扇区的数据(据具体硬盘而定)。

d1:打开DMA模式。

x66 :在支持UDMA-capable的硬盘中,这个参数可以支持双DMA通道的数据传输模式。

u1 Linux在处理磁盘中断时,可以unmask其他的中断或者响应其他中断相关的任务。

查看以上的更改情况可以使用命令:

# /sbin/hdparm /dev/hda

测试磁盘I/O性能可以使用命令:

# /sbin/hdparm -tT /dev/hda

如果磁盘的性能有改进的话,可以使用以下命令来保存设置:

# /sbin/hdparm -k1 /dev/had

 

2,中文手册:

hdparm 文档

http://www./bbs/printthread.php?t=210179
 

hdparm - 获取/设置硬盘参数
总览
hdparm [ -a [
扇区数] ] [ -A [0|1] ] [ -c [芯片组模式] ] [ -C ] [ -d [0|1] ] [ -f ] [ -g ] [ -i ] [ -k [0|1] ] [ -K [0|1] ] [ -L [0|1] ] [ -m [扇区数] ] [ -p [0|1|2|3|4|5] ] [ -P [扇区数] ] [ -q ] [ -r [0|1] ] [ -S [超时] ] [ -T ] [ -t ] [ -u [0|1] ] [ -v ] [ -W [0|1] ] [ -X [传输模式] ] [ -y ] [ -Y ] [ -Z ] [设备] ..
描述
hdparm
提供一个实现各种硬盘控制动作的命令行接口,它由内建 Linux IDE/ST-506设备驱动程序支持.要实现这种功能需要Linux 核心版本为1.2.13或更高.在早期的核心下有一些选项可能不能正 常工作.另外,一些选项只是为包含了新的IDE设备驱动程序的核心 所支持,2.0.10版或者更高版本的核心.如果hdparm程序是在使用 旧的核心文件(在目录usr/include/linux)的机器上被编译的,这 些选项将无法获得.
选项
当未给出标记时, -acdgkmnru 被作为假设值 (除非一个给定的设备是SCSI设备或某种老式 XTMFM/RLL,在这种情况下 -gr -adgr 分别是默认值).
-a
为文件系统提前获得/设置扇区号,可以用来改善连续读取大文件时的系统性能,具体方式为提前读取额外的预期中正在运行的任务所需要的 数据块.在当前核心版本(2.0.10)中默认设置为8个扇区(4KB).对于 大多数用途,这个值看起来不错,但在一个大多数文件访问行为是随机 搜索的系统中,设置一个小一些的值可能效果会更好.当然,很多 IDE驱动器也有一个独立的内建的预读功能,这在很多情况下可以缓解 对文件系统预读功能的需求.
-A
关闭/打开IDE驱动器预读功能(通常默认为打开).
-c
查询/打开(E)IDE 32-bit I/O 支持.一个数字的参数可以被用来 打开/关闭32-bit I/O 支持.当前支持的值包括 0 关闭 32-bit I/O 支持, 1 打开 32-bit 数据传输, 3 以一个芯片组要求的特殊的 sync 流程打开 32-bit data 传输. 3 几乎对所有的32-bit IDE 芯片组起作用,但导致稍微多一些的系统开销. 注意,32-bit数据传输仅仅用于通过PCIVLB总线与接口卡的连接; 所有的IDE驱动器通过排线从接口卡获得的连接仅为16-bit.
-C
检查当前IDE能耗模式状态, 结果将是下面几种之一未知 (驱动器不支持此命令), 活动/闲置 (普通操作), 待机 (低能耗模式,驱动器待机), or 睡眠 (最低能耗模式, 驱动器被完全关闭). 选项 -S, -y, -Y, and -Z 用来操纵能耗模式.
-d
为驱动器关闭/打开 "using_dma" 标志. 此选项仅对一些支持 DMA并且对于IDE驱动程序来说是已知的驱动器-接口组合 (包括所有被支持的XT接口).特别的,Intel Triton 芯片组 能和很多驱动器一起实现总线控制 DMA 操作.(根据实验).使用 -X34 选项与 -d1 选项组合确保驱动器自身是为多字DMA模式2设计的. 使用DMA不一定对吞吐量或系统性能有改进,但很多人信赖它.
-E
设置光盘驱动器速度.对于一般性操作这不是必须的,因为驱动器将自动地自行选择自己的速度.如果你想要使用它,就在选项后提供一个数字,通常是24.
-f
当设备退出时同步并刷新指针高速缓存.此操作也作为选项 -t -T 定时的一部分被执行
-g
显示驱动器物理位置(柱面,磁头,扇区),设备的大小(以扇区为单位), 以及相对于驱动器起始的设备偏移量(以扇区为单位).
-h
显示简要使用信息(帮助).
-i
显示引导驱动器时获得的识别信息,如果有的话. 这是一种现代IDE驱动器特性,可能不被较老式的设备支持. 返回的数据可能是或不是当前的,这取决于自系统引导后的行为. 然而,当前的复合模式的扇区计数始终被给出. 要获得更多的关于识别信息的详细阐释,请查阅 AT Attachment Interface for Disk Drives (ANSI ASC X3T9.2 working draft, revision 4a, April 19/93).
-I
直接从驱动器获取识别信息, 并以原始的,未经过修改和更正的形式显示. 否则便与选项 -i 相同.
-k
获得/设置驱动器 keep_settings_over_reset 标志. 当此标志被设置,驱动程序将在一个软性的重置后保护选项 -dmu (如同在出错恢复流程中完成的那样) 此标志默认值为关 , 以防止可能由与 -dmu 组合设置导致的驱动器重置循环. 选项 -k 应该仅在你确信用一组选定的设置进行正确的系统操作之后被设置. 实际中,校验驱动器能够读/些并且在此过程中没有出错记录(核心消息, 大多数系统上/var/adm/messages),是测试一个配置(在用-k之前)必须的.
-K
设置驱动器的 keep_features_over_reset 标志. 此项设置使驱动器在软性重置后保留 -APSWXZ 标志的设置 (如同在出错恢复流程中完成的那样). 并非所有的驱动器都支持此项特性.
-L
设置驱动器的doorlock标志. 设置为 将锁住一些移动式硬驱动器( Syquest,ZIP,Jazz..)的 门锁机构.设置为 一般Linux根据驱动器用法自动维护门锁机构.(当安装一个文件 系统时锁住).但在系统关闭时,如果根分区在一个移动式磁盘上, 可能会有麻烦,因为在关闭后根分区仍在处在安装状态(只读). 所以,使用这个命令在根文件系统以只读的方式重新被安装 ,用户可以在关闭后从驱动器中移走磁盘.
-m
获得/设置驱动器多重扇区I/O的扇区数.设置为 0 关闭这项特性.多重扇区模式(aka IDE Block 模式),是大多数 现代硬盘驱动器的一项特性,它允许每次I/O中断传输多个扇区, 而不是通常的一次中断一个.当这项特性被打开时,操作系统 处理磁盘I/O的开销降低30-50%.在许多系统上,它也会在任何 地方增加5% - 50% 的数据流量大多数驱动器支持最小的设置 为2,4,8,16(扇区).较大的设置也可能存在,这取决于驱 动器.在许多系统上设置为1632看起来是最理想的. Western Digital在他们的许多驱动器上推荐设置为48. 归因于微小的(32kB)磁盘缓冲和非最优化的缓冲算法. 选项 -i 被用来查出一个已安装驱动器支持的最大设置 (在输出中查找 MaxMultSect ).一些驱动器声称支持多重扇区模式, 但在某些设置下丢失数据.在极少的情况下,这样的失败会导致 严重的文件系统损坏.
-p
尝试为指定的PIO模式对IDE接口芯片重编程,或者尝试为驱动器支持 的最佳的PIO模式进行自动调整.核心中仅针对于一些"知名"的芯片组支持这项特性,甚至这种支持不一定是最好的.一些IDE芯片组不能为 一个单一的驱动器改变PIO模式,在这种情况下此选项可能导致PIO 模式的设置影响到 两个 驱动器.许多IDE芯片组支持少于或多于标准的六个(05)PIO模式, 所以实际实现的精确速度设置将由芯片组和驱动器复杂的配合改变. 谨慎使用. 这项特性不包含任何针对不谨慎的保护措施,一个不成功的结果 可能导致 严重的文件系统损坏.
-P
为驱动器的内部预读机制设置最大扇区数. 不是所有的驱动器都支持这项特性.
-q
安静的操作下一个标志,压制正常输出. 当从/etc/rc.c/rc.local运行时,可用来减轻屏幕混乱程度. 不适用于 -i -v -t -T 标志.
-r
获得/设置驱动器的只读标志.当被设置时,设备上的写操作被禁止.
-R
登记一个IDE接口. 危险. 参见 -U 选项获取更多信息.
-S
设置驱动器待机(低速运转)超时值. 驱动器根据此值决定在关闭主轴电机以节约能耗之前等待多长 时间(没有磁盘操作).在这种状态下,驱动器可能需要来响应一 个接下来的磁盘访问,虽然大多数驱动器要快很多.超时值的编 码有些特别.0表示"".1240被指定为5秒的倍数, 也就是超时可以从5秒到20分钟.241251指定30分钟的111, 也就是超时可以从30分钟到5.5个小时.252表示超时21分钟, 253设置一个销售商定义的超时,255表示2115.
-T
用于以基准测试和比较为目的的缓存读取计时.要得到有意义的结果, 应该在内存不少于2M,系统没有其它活动(没有其它活动的程序) 的条件下,重复操作2-3.它显示了不存取磁盘直接从Linux缓存 读取数据的速度.这项测量实际上标示了被测系统的处理器,缓存 和内存的吞吐量. 如果标志 -t 也被指定,那么一个基于 -T 输出结果的修正量将被综合到 -t 操作报告的结果中.
-t
用于以基准测试和比较为目的的缓存读取计时.要得到有意义的结果, 应该在内存不少于2M,系统没有其它活动(没有其它活动的程序) 的条件下,重复操作2-3.它显示了不使用预先的数据缓冲从磁盘 这项测量标示了Linux下没有任何文件系统开销时磁盘可以支持多快的连续数据读取.为确保测量的精确,缓存在 -t 的过程中通过BLKFLSBUF控制被刷新. 如果标志 -T 也被指定,那么一个基于 -T 数促结果的修正量将被综合到 -t 操作报告的结果中.
-u
获得/设置驱动器"不屏蔽中断"标志.设置为 1 允许驱动器在磁盘中断处理过程中不屏蔽别的中断, 它极大改善了Linux的响应性能,并排除了"串行端口溢出"错误. 谨慎使用: 一些驱动器/控制器组合不能承受可能是潜在的 I/O 增长, 而导致 严重的文件系统损坏. 特别, CMD-640B RZ1000 (E)IDE 接口可能是 不可靠的 (由于某种硬件缺陷),当在早于 2.0.16 版本的核心下使用此选项时. 关闭这些接口的(通常通过设置BIOS/CMOS) IDE 预读 特性可以安全的解决这个问题.
-U
注销一个IDE接口. 危险. -R 的对应选项. 是为特别设计用来做热交换的硬件准备的(很罕见!). 使用时要有充分的知识和 非常的谨慎 ,因为它很容易终止或破坏你的系统. hdparm 的源代码包括一个 ‘contrib‘ 目录,里面有一些 用户捐赠的在一台 ThinkPad 600EUltraBay上作热交换的记录. 自己去冒险吧.
-v
显示所有的设置, 除了 -i ( -acdgkmnru 对于 IDE, -gr 对于 SCSI -adgr 对于 XT). 这也是未指定任何标志时的默认操作.
-W
关闭/打开 IDE 驱动器的写缓存特性 (通常默认为 OFF ).
-X
为较新的 (E)IDE/ATA2 驱动器设置 IDE 传输模式 . 特别是当在一个被支持的接口芯片组( Intel 430FX Triton) 上打开通向一个驱动器的DMA时与选项 -d1 组合使用,在这里用 -X34 来选择多字 DMA 模式2 传输. 对于支持 UltraDMA burst timings 的系统, -X66 来选择 UltraDMA mode2 传输 (你需要在这之前为 UltraDMA 准备好被支持的芯片组). 另外, 几乎没有必要 使用此标志,因为大多数/全部现代 IDE 驱动器默认它们最快的
PIO
传输模式为打开. 所以摆弄它是没有必要的也是冒险的. 在支持 alternate 传输模式的驱动器上, -X 可以被 仅 用来选择模式. 在改变传输模式之前, 应该为新模式的设置给 IDE 接口跳线或编程( -p 标志) 以防止数据的丢失或损坏. 请非常小心地使用它! 对于 Linux 使用的 PIO 传输模式,此值就是要求的 PIO 模式号加 8. 这样, 09 设置 PIO mode1, 10 设置 PIO mode2,
11
设置 PIO mode3. 设置为 00 还原驱动器的默认 PIO 模式, 01 关闭 IORDY. 对于多字 DMA, 使用的值时要求的 DMA 模式号加 32. 对于 UltraDMA ,相应的值是要求 UltraDMA 模式号加64.
-y
迫使一个 IDE 驱动器立即进入低能耗 待机 模式, 通常使它低速运转. 当前能耗模式状态可以用 -C 标志来检查.
-Y
迫使一个 IDE 驱动器立即进入最低能耗 睡眠 模式, 使它完全关闭. 一个来自硬件或软件的重置 可以重新唤醒驱动器. ( 如果需要,Linux IDE 驱动器将自动产生一个重置 ).
-Z
关闭某些 Seagate 驱动器(STxxx ?)的自动节能功能, 以防止它们在不适当的时候空转或低速运转.

BUGS
像上面提到的, -m 扇区数 和 -u 1 选项尤其要小心使用, 最好在一个只读文件系统上使用. 大多数驱动器和这些特性配合得很好,但有一些驱动器/控制器 组合不是100%兼容的.使用可能导致文件系统损坏. 请在实验之前给所有的数据作备份!

某些选项 (例如: -r 对于 SCSI) 可能在旧的核心下因为核心不 支持必要的 icctl() 而不能工作.

虽然这个命令只是为使用 (E)IDE 硬盘设备准备的,但有几个选项也能够(允许)用于带有 XT 接口的 SCSI 硬盘设备和 MFM/RLL 硬盘.
作者
hdparm
是由 Mark Lord <mlord@pobox.com>, Linux (E)IDE 驱动程序 的主要开发者和维护者编写的,并听取了很多网友的建议.

关闭 Seagate 自动节能的代码是征得
Tomi Leppikangas(tomilepp@paju.oulu.fi)
允许使用的.

 

3,英文手册:

http://wiki./index.php?title=Hdparm&variant=zh-cn

 

Linux命令:hdparm

功能说明:显示与设定硬盘的参数。
语  法:hdparm [-CfghiIqtTvyYZ][-a <快取分区>][-A <01>][-c ][-d <01>][-k <01>][-K <01>][-m <分区数>][-n <01>][-p ][-P <分区数>][-r <01>][-S <时间>][-u <01>][-W <01>][-X <传输模式>][设备]
补充说明:hdparm可检测,显示与设定IDESCSI硬盘的参数。
参  数:
-a<快取分区>   设定读取文件时,预先存入块区的分区数,若不加上<快取分区>选项,则显示目前的设定。
-A<01>   启动或关闭读取文件时的快取功能。
-c   设定IDE32I/O模式。
-C   检测IDE硬盘的电源管理模式。
-d<01>   设定磁盘的DMA模式。
-f   将内存缓冲区的数据写入硬盘,并清楚缓冲区。
-g   显示硬盘的磁轨,磁头,磁区等参数。
-h   显示帮助。
-i   显示硬盘的硬件规格信息,这些信息是在开机时由硬盘本身所提供。
-I   直接读取硬盘所提供的硬件规格信息。
-k<01>   重设硬盘时,保留-dmu参数的设定。
-K<01>   重设硬盘时,保留-APSWXZ参数的设定。
-m<磁区数>   设定硬盘多重分区存取的分区数。
-n<01>   忽略硬盘写入时所发生的错误。
-p   设定硬盘的PIO模式。
-P<磁区数>   设定硬盘内部快取的分区数。
-q   在执行後续的参数时,不在屏幕上显示任何信息。
-r<01>   设定硬盘的读写模式。
-S<时间>   设定硬盘进入省电模式前的等待时间。
-t   评估硬盘的读取效率。
-T   平谷硬盘快取的读取效率。
-u<01>   在硬盘存取时,允许其他中断要求同时执行。
-v   显示硬盘的相关设定。
-W<01>   设定硬盘的写入快取。
-X<传输模式>   设定硬盘的传输模式。
-y   使IDE硬盘进入省电模式。
-Y   使IDE硬盘进入睡眠模式。
-Z   关闭某些Seagate硬盘的自动省电功能。 


英文版本,欢迎翻译:

NAME hdparm - get/set hard disk parameters

SYNOPSIS hdparm [ -a [sectcount] ] [ -A [0|1] ] [ -c [chipset_mode] ] [ -C ] [ -d [0|1] ] [ -f ] [ -g ] [ -i ] [ -k [0|1] ] [ -K [0|1] ] [ -L [0|1] ] [ -m [sectcount] ] [ -p [0|1|2|3|4|5] ] [ -P [sectcount] ] [ -q ] [ -r [0|1] ] [ -S [timeout] ] [ -T ] [ -t ] [ -u [0|1] ] [ -v ] [ -W [0|1] ] [ -X [xfermode] ] [ -y ] [ -Y ] [ -Z ] [device] ..

DESCRIPTION hdparm provides a command line interface to various hard disk ioctls supported by the stock Linux IDE/ST-506 device driver. This utility requires Linux kernel version 1.2.13 or later. Some options may not work correctly with earlier kernels. In addition, several options are supported only for kernels which include the new (E)IDE device driver, such as version 2.0.10 or later. These options are unavail? able when hdparm is compiled on systems with older kernel files in /usr/include/linux.

OPTIONS When no flags are given, -acdgkmnru is assumed (except when a given device is SCSI or an old XT-type MFM/RLL, in which cases -gr and -adgr are the defaults, respectively).

-a Get/set sector count for filesystem read-ahead. This is used to improve performance in sequen? tial reads of large files, by prefetching additional blocks in anticipation of them being needed by the running task. In the current kernel version (2.0.10) this has a default setting of 8 sec? tors (4KB). This value seems good for most purposes, but in a system where most file accesses are random seeks, a smaller setting might provide better performance. Also, many IDE drives also have a separate built-in read-ahead function, which alleviates the need for a filesystem read- ahead in many situations.

-A Disable/enable the IDE drives read-lookahead feature (usually ON by default).

-c Query/enable (E)IDE 32-bit I/O support. A numeric parameter can be used to enable/disable 32-bit I/O support: Currently supported values include 0 to disable 32-bit I/O support, 1 to enable 32-bit data transfers, and 3 to enable 32-bit data transfers with a special sync sequence required by many chipsets. The value 3 works with nearly all 32-bit IDE chipsets, but incurs slightly more overhead. Note that "32-bit" refers to data transfers across a PCI or VLB bus to the interface card only; all (E)IDE drives still have only a 16-bit connection over the ribbon cable from the interface card.

-C Check the current IDE power mode status, which will always be one of unknown (drive does not sup? port this command), active/idle (normal operation), standby (low power mode, drive has spun down), or sleeping (lowest power mode, drive is completely shut down). The -S, -y, -Y, and -Z flags can be used to manipulate the IDE power modes.

-d Disable/enable the "using_dma" flag for this drive. This option only works with a few combina? tions of drives and interfaces which support DMA and which are known to the IDE driver (and with all supported XT interfaces). In particular, the Intel Triton chipset is supported for bus-mas? tered DMA operation with many drives (experimental). It is also a good idea to use the -X34 option in combination with -d1 to ensure that the drive itself is programmed for multiword DMA mode2. Using DMA does not necessarily provide any improvement in throughput or system perfor? mance, but many folks swear by it. Your mileage may vary.

-E Set cdrom speed. This is NOT necessary for regular operation, as the drive will automatically switch speeds on its own. But if you want to play with it, just supply a speed number after the option, usually a number like 2 or 4.

-f Sync and flush the buffer cache for the device on exit. This operation is also performed as part of the -t and -T timings.

-g Display the drive geometry (cylinders, heads, sectors), the size (in sectors) of the device, and the starting offset (in sectors) of the device from the beginning of the drive.

-h Display terse usage information (help).

-i Display the identification info that was obtained from the drive at boot time, if available. This is a feature of modern IDE drives, and may not be supported by older devices. The data returned may or may not be current, depending on activity since booting the system. However, the current multiple sector mode count is always shown. For a more detailed interpretation of the identification info, refer to AT Attachment Interface for Disk Drives (ANSI ASC X3T9.2 working draft, revision 4a, April 19/93).

-I Request identification info directly from the drive, which is displayed in its raw form with no endian changes or corrections. Otherwise similar to the -i option.

-k Get/set the keep_settings_over_reset flag for the drive. When this flag is set, the driver will preserve the -dmu options over a soft reset, (as done during the error recovery sequence). This flag defaults to off, to prevent drive reset loops which could be caused by combinations of -dmu settings. The -k flag should therefore only be set after one has achieved confidence in correct system operation with a chosen set of configuration settings. In practice, all that is typically necessary to test a configuration (prior to using -k) is to verify that the drive can be read/written, and that no error logs (kernel messages) are generated in the process (look in /var/adm/messages on most systems).

-K Set the drives keep_features_over_reset flag. Setting this enables the drive to retain the set? tings for -APSWXZ over a soft reset (as done during the error recovery sequence). Not all drives support this feature.

-L Set the drives doorlock flag. Setting this to will lock the door mechanism of some removeable hard drives (eg. Syquest, ZIP, Jazz..), and setting it to maintains the door locking mechanism automatically, depending on drive usage (locked whenever a filesystem is mounted). But on system shutdown, this can be a nuisance if the root partition is on a removeable disk, since the root partition is left mounted (read-only) after shutdown. So, by using this command to unlock the door -b after the root filesystem is remounted read-only, one can then remove the cartridge from the drive after shutdown.

-m Get/set sector count for multiple sector I/O on the drive. A setting of 0 disables this feature. Multiple sector mode (aka IDE Block Mode), is a feature of most modern IDE hard drives, permit? ting the transfer of multiple sectors per I/O interrupt, rather than the usual one sector per interrupt. When this feature is enabled, it typically reduces operating system overhead for disk I/O by 30-50%. On many systems, it also provides increased data throughput of anywhere from 5% to 50%. Some drives, however (most notably the WD Caviar series), seem to run slower with multi? ple mode enabled. Your mileage may vary. Most drives support the minimum settings of 2, 4, 8, or 16 (sectors). Larger settings may also be possible, depending on the drive. A setting of 16 or 32 seems optimal on many systems. Western Digital recommends lower settings of 4 to 8 on many of their drives, due tiny (32kB) drive buffers and non-optimized buffering algorithms. The -i flag can be used to find the maximum setting supported by an installed drive (look for MaxMult? Sect in the output). Some drives claim to support multiple mode, but lose data at some settings. Under rare circumstances, such failures can result in massive filesystem corruption.

-p Attempt to reprogram the IDE interface chipset for the specified PIO mode, or attempt to auto- tune for the "best" PIO mode supported by the drive. This feature is supported in the kernel for only a few "known" chipsets, and even then the support is iffy at best. Some IDE chipsets are unable to alter the PIO mode for a single drive, in which case this flag may cause the PIO mode for both drives to be set. Many IDE chipsets support either fewer or more than the standard six (0 to 5) PIO modes, so the exact speed setting that is actually implemented will vary by chipset/driver sophistication. Use with extreme caution! This feature includes zero protection for the unwary, and an unsuccessful outcome may result in severe filesystem corruption!

-P Set the maximum sector count for the drives internal prefetch mechanism. Not all drives support this feature.

-q Handle the next flag quietly, supressing normal output. This is useful for reducing screen clut? ter when running from /etc/rc.c/rc.local. Not applicable to the -i or -v or -t or -T flags.

-r Get/set read-only flag for device. When set, write operations are not permitted on the device.

-R Register an IDE interface. Dangerous. See the -U option for more information.

-S Set the standby (spindown) timeout for the drive. This value is used by the drive to determine how long to wait (with no disk activity) before turning off the spindle motor to save power. Under such circumstances, the drive may take as long as 30 seconds to respond to a subsequent disk access, though most drives are much quicker. The encoding of the timeout value is somewhat peculiar. A value of zero means "off". Values from 1 to 240 specify multiples of 5 seconds, for timeouts from 5 seconds to 20 minutes. Values from 241 to 251 specify from 1 to 11 units of 30 minutes, for timeouts from 30 minutes to 5.5 hours. A value of 252 signifies a timeout of 21 minutes, 253 sets a vendor-defined timeout, and 255 is interpreted as 21 minutes plus 15 seconds.

-T Perform timings of cache reads for benchmark and comparison purposes. For meaningful results, this operation should be repeated 2-3 times on an otherwise inactive system (no other active pro? cesses) with at least a couple of megabytes of free memory. This displays the speed of reading directly from the Linux buffer cache without disk access. This measurement is essentially an indication of the throughput of the processor, cache, and memory of the system under test. If the -t flag is also specified, then a correction factor based on the outcome of -T will be incor? porated into the result reported for the -t operation.

-t Perform timings of device reads for benchmark and comparison purposes. For meaningful results, this operation should be repeated 2-3 times on an otherwise inactive system (no other active pro? cesses) with at least a couple of megabytes of free memory. This displays the speed of reading through the buffer cache to the disk without any prior caching of data. This measurement is an indication of how fast the drive can sustain sequential data reads under Linux, without any filesystem overhead. To ensure accurate measurments, the buffer cache is flushed during the pro? cessing of -t using the BLKFLSBUF ioctl. If the -T flag is also specified, then a correction factor based on the outcome of -T will be incorporated into the result reported for the -t opera? tion.

-u Get/set interrupt-unmask flag for the drive. A setting of 1 permits the driver to unmask other interrupts during processing of a disk interrupt, which greatly improves Linuxs responsiveness and eliminates "serial port overrun" errors. Use this feature with caution: some drive/con? troller combinations do not tolerate the increased I/O latencies possible when this feature is enabled, resulting in massive filesystem corruption. In particular, CMD-640B and RZ1000 (E)IDE interfaces can be unreliable (due to a hardware flaw) when this option is used with kernel ver? sions earlier than 2.0.13. Disabling the IDE prefetch feature of these interfaces (usually a BIOS/CMOS setting) provides a safe fix for the problem for use with earlier kernels.

-U Un-register an IDE interface. Dangerous. The companion for the -R option. Intended for use with hardware made specifically for hot-swapping (very rare!). Use with knowledge and extreme caution as this can easily hang or damage your system. The hdparm source distribution includes a contrib directory with some user-donated scripts for hot-swapping on the UltraBay of a ThinkPad 600E. Use at your own risk.

-v Display all settings, except -i (same as -acdgkmnru for IDE, -gr for SCSI or -adgr for XT). This is also the default behaviour when no flags are specified.

-W Disable/enable the IDE drives write-caching feature (usually OFF by default).

-X Set the IDE transfer mode for newer (E)IDE/ATA2 drives. This is typically used in combination with -d1 when enabling DMA to/from a drive on a supported interface chipset (such as the Intel 430FX Triton), where -X34 is used to select multiword DMA mode2 transfers. With systems which support UltraDMA burst timings, -X66 is used to select UltraDMA mode2 transfers (youll need to prepare the chipset for UltraDMA beforehand). Apart from that, use of this flag is seldom neces? sary since most/all modern IDE drives default to their fastest PIO transfer mode at power-on. Fiddling with this can be both needless and risky. On drives which support alternate transfer modes, -X can be used to switch the mode of the drive only. Prior to changing the transfer mode, the IDE interface should be jumpered or programmed (see -p flag) for the new mode setting to pre? vent loss and/or corruption of data. Use this with extreme caution! For the PIO (Programmed Input/Output) transfer modes used by Linux, this value is simply the desired PIO mode number plus 8. Thus, a value of 09 sets PIO mode1, 10 enables PIO mode2, and 11 selects PIO mode3. Setting 00 restores the drives "default" PIO mode, and 01 disables IORDY. For multiword DMA, the value used is the desired DMA mode number plus 32. for UltraDMA, the value is the desired UltraDMA mode number plus 64.

-y Force an IDE drive to immediately enter the low power consumption standby mode, usually causing it to spin down. The current power mode status can be checked using the -C flag.

-Y Force an IDE drive to immediately enter the lowest power consumption sleep mode, causing it to shut down completely. A hard or soft reset is required before the drive can be accessed again (the Linux IDE driver will automatically handle issuing a reset if/when needed). The current power mode status can be checked using the -C flag.

-Z Disable the automatic power-saving function of certain Seagate drives (ST3xxx models?), to pre? vent them from idling/spinning-down at inconvenient times.

BUGS As noted above, the -m sectcount and -u 1 options should be used with caution at first, preferably on a read-only filesystem. Most drives work well with these features, but a few drive/controller combina? tions are not 100% compatible. Filesystem corruption may result. Backup everything before experiment? ing!

Some options (eg. -r for SCSI) may not work with old kernels as necessary ioctl()s were not supported.

Although this utility is intended primarily for use with (E)IDE hard disk devices, several of the options are also valid (and permitted) for use with SCSI hard disk devices and MFM/RLL hard disks with XT interfaces.

AUTHOR hdparm has been written by Mark Lord <mlord@pobox.com>, the primary developer and maintainer of the (E)IDE driver for Linux, with suggestions from many netfolk.

The disable Seagate auto-powersaving code is courtesy of Tomi Leppikangas(tomilepp@paju.oulu.fi).

SEE ALSO AT Attachment Interface for Disk Drives, ANSI ASC X3T9.2 working draft, revision 4a, April 19, 1993.

AT Attachment Interface with Extensions (ATA-2), ANSI ASC X3T9.2 working draft, revision 2f, July 26, 1994.

Western Digital Enhanced IDE Implementation Guide, by Western Digital Corporation, revision 5.0, Novem? ber 10, 1993.

Enhanced Disk Drive Specification, by Phoenix Technologies Ltd., version 1.0, January 25, 1994.

Version 3.9 February 2000 1

[Category:Linux]]

 

4, Speeding up Linux Using hdparm

http://www./article/server/00070002/0621409064857145.htm

Are you running an Intel Linux system with at least one (E)IDE hard drive?

 

 

Wouldn‘t it be neat if there were a magical command to instantly double the I/O performance of your disks? Or, in some cases, show 6 to 10 times your existing throughput?

 

Did you ever just wonder how to tell what kind of performance you‘re getting on your "tricked-out" Linux box?

 

Don‘t overlook hdparm(. If you‘ve never heard of it, don‘t worry. Most people I‘ve talked to haven‘t either. But if you‘re running an IDE/Linux system (as many folks are,) you‘ll wonder how you ever got this far without it. I know I did.

 

What‘s the big deal?

So, you‘ve got your brand-new UltraATA/66 EIDE drive with a screaming brand-new controller chipset that supports multiple PIO modes and DMA and the leather seat option and extra chrome... But is your system actually taking advantage of these snazzy features? The hdparm( command will not only tell you how your drives are performing, but will let you tweak them out to your heart‘s content.

 

Now before you get too excited, it is worth pointing out that under some circumstances, these commands CAN CAUSE UNEXPECTED DATA CORRUPTION! Use them at your own risk! At the very least, back up your box and bring it down to single-user mode before proceeding.

 

With the usual disclaimer out of the way, I‘d like to point out that if you are using current hardware (i.e. your drive AND controller AND motherboard were manufactured in the last two or three years), you are at considerably lower risk. I‘ve used these commands on several boxes with various hardware configurations, and the worst I‘ve seen happen is the occasional hang, with no data problems on reboot. And no matter how much you might whine at me and the world in general for your personal misfortune, we all know who is ultimately responsible for the well-being of YOUR box: YOU ARE. Caveat Fair Reader.

 

Now, then. If I haven‘t scared you away yet, try this (as root, preferably in single-user mode):

 

hdparm -Tt /dev/hda

You‘ll see something like:

 

/dev/hda:

 Timing buffer-cache reads:   128 MB in  1.34 seconds =95.52 MB/sec

 Timing buffered disk reads:  64 MB in 17.86 seconds = 3.58 MB/sec

What does this tell us? The -T means to test the cache system (i.e., the memory, CPU, and buffer cache). The -t means to report stats on the disk in question, reading data not in the cache. The two together, run a couple of times in a row in single-user mode, will give you an idea of the performance of your disk I/O system. (These are actual numbers from a PII/350 / 128M Ram / newish EIDE HD; your numbers will vary.)

 

But even with varying numbers, 3.58 MB/sec is PATHETIC for the above hardware. I thought the ad for the HD said something about 66MB per second!!?!? What gives?

 

Well, let‘s find out more about how Linux is addressing your drive:

 

hdparm /dev/hda

 

/dev/hda:

 multcount    =  0 (off)

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

 unmaskirq    =  0 (off)

 using_dma    =  0 (off)

 keepsettings =  0 (off)

 nowerr       =  0 (off)

 readonly     =  0 (off)

 readahead    =  8 (on)

 geometry     = 1870/255/63, sectors = 30043440, start = 0

These are the defaults. Nice, safe, but not necessarily optimal. What‘s all this about 16-bit mode? I thought that went out with the 386! And why are most of the other options turned off?

 

Well, it‘s generally considered a good idea for any self-respecting distribution to install itself in the kewlest, slickest, but SAFEST way it possibly can. The above settings are virtually guaranteed to work on any hardware you might throw at it. But since we know we‘re throwing something more than a dusty, 8-year-old, 16-bit multi-IO card at it, let‘s talk about the interesting options:

multcount: Short for multiple sector count. This controls how many sectors are fetched from the disk in a single I/O interrupt. Almost all modern IDE drives support this. The man page claims: 


When this feature is enabled, it typically reduces operating system overhead for disk I/O by 30 -50
. On many systems,  it also provides increased data throughput of anywhere from 5 to 50.
I/O support: This is a big one. This flag controls how data is passed from the PCI bus to the controller. Almost all modern controller chipsets support mode 3, or 32-bit mode w/sync. Some even support 32-bit async. Turning this on will almost certainly double your throughput (see below.) 


unmaskirq: Turning this on will allow Linux to unmask other interrupts while processing a disk interrupt. What does that mean? It lets Linux attend to other interrupt-related tasks (i.e., network traffic) while waiting for your disk to return with the data it asked for. It should improve overall system response time, but be warned: Not all hardware configurations will be able to handle it. See the manpage. 


using_dma: DMA can be a tricky business. If you can get your controller and drive using a DMA mode, do it. But I have seen more than one machine hang while playing with this option. Again, see the manpage (and the example on the next page)! 


Turbocharged
So, since we have our system in single-user mode like a good little admin, let‘s try out some turbo settings:

 

hdparm -c3 -m16 /dev/hda

/dev/hda:
 setting 32-bit I/O support flag to 3
 setting multcount to 16
 multcount    =  16 (on)
 I/O support  =  3 (32-bit w/sync)

Great! 32-bit sounds nice. And some multi-reads might work. Let‘s re-run the benchmark:

hdparm -tT /dev/hda


/dev/hda:
 Timing buffer-cache reads:   128 MB in  1.41 seconds =90.78 MB/sec
 Timing buffered disk reads:  64 MB in  9.84 seconds = 6.50 MB/sec
WOW! Almost double the disk throughput without really trying! Incredible.

But wait, there‘s more: We‘re still not unmasking interrupts, using DMA, or even a using decent PIO mode! Of course, enabling these gets riskier. (Why is it always a trade-off between freedom and security?) The man page mentions trying Multiword DMA mode2, so:

hdparm -X34 -d1 -u1 /dev/hda
...Unfortunately this seems to be unsupported on this particular box (it hung like an NT box running a Java app.) So, after rebooting it (again in single-user mode), I went with this:

hdparm -X66 -d1 -u1 -m16 -c3 /dev/hda

/dev/hda:
 setting 32-bit I/O support flag to 3
 setting multcount to 16
 setting unmaskirq to 1 (on)
 setting using_dma to 1 (on)
 setting xfermode to 66 (UltraDMA mode2)
 multcount    = 16 (on)
 I/O support  =  3 (32-bit w/sync)
 unmaskirq    =  1 (on)
 using_dma    =  1 (on)
And then checked:

hdparm -tT /dev/hda

/dev/hda:
 Timing buffer-cache reads:   128 MB in  1.43 seconds =89.51 MB/sec
 Timing buffered disk reads:  64 MB in  3.18 seconds =20.13 MB/sec

20.13 MB/sec. A far cry from the miniscule 3.58 we started with...

 

By the way, notice how we specified the -m16 and -c3 switch again? That‘s because it doesn‘t remember your hdparm settings between reboots. Be sure to add the above line to your /etc/rc.d/* scripts once you‘re sure the system is stable (and preferably after your fsck runs; having an extensive fs check run with your controller in a flaky mode may be a good way to generate vast quantities of entropy, but it‘s no way to administer a system. At least not with a straight face...)

 

Now, after running the benchmark a few more times, reboot in multi-user mode and fire up X. Load Netscape. And try not to fall out of your chair.

 

In conclusion

This is one of those interesting little tidbits that escapes many "seasoned" Linux veterans, especially since one never sees any indication that the system isn‘t using the most optimal settings. (Gee, all my kernel messages have looked fine....) And using hdparm isn‘t completely without risk, but is well worth investigating.

 

And it doesn‘t stop at performance: hdparm lets you adjust various power saving modes as well. See the hdparm( for the final word.

 

Many thanks to Mark Lord for putting together this nifty utility. If your particular distribution doesn‘t include hdparm (usually in /sbin or /usr/sbin), get it from the source at http://metalab./pub/Linux/system/hardware/

 

Happy hacking! 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多