Linux下的32位I/O和DMA默認是關閉的。如果用的是16位I/O的話,就無法充分發揮電腦的性能。
如果要打開32位I/O和DMA,就需要以root身份進行設置。為了降低因出錯而重啟系統對文件系統的損害,最好以單用戶模式進行。
首先,使用下面的命令檢查硬盤驅動器的當前I/O情況:
[root@anima lwg]# /sbin/hdparm -t /dev/hda
/dev/hda:
Timing buffered disk reads: 8 MB in 3.31 seconds = 2.42 MB/sec
[root@anima lwg]#
如果要顯示當前I/O、DMA設置,可以分別使用下面的命令:
[root@anima lwg]# /sbin/hdparm -c /dev/hda (顯示當前I/O設置)
/dev/hda:
IO_support = 0 (default 16-bit)
[root@anima lwg]# /sbin/hdparm -d /dev/hda (顯示當前DMA設置)
/dev/hda:
using_dma = 0 (off)
[root@anima lwg]#
通過上面的命令,已經知道現在32位I/O和DMA是關閉的,可以分別用下面的命令將其打開:
[root@anima lwg]# /sbin/hdparm -c 1 /dev/hda (打開32位I/O)
/dev/hda:
setting 32-bit IO_support flag to 1
IO_support = 1 (32-bit)
[root@anima lwg]# /sbin/hdparm -d 1 /dev/hda (打開DMA)
/dev/hda:
setting using_dma to 1 (on)
using_dma = 1 (on)
[root@anima lwg]#
然後使用下面的命令使設置生效:
[root@anima lwg]# /sbin/hdparm -k 1 /dev/hda
/dev/hda:
setting keep_settings to 1 (on)
keepsettings = 1 (on)
[root@anima lwg]#
好啦!現在再查看一下驅動器的I/O情況:
[root@anima lwg]# /sbin/hdparm -t /dev/hda
/dev/hda:
Timing buffered disk reads: 116 MB in 3.03 seconds = 38.34 MB/sec
[root@anima lwg]#
可以看到,現在系統的I/O性能提高了很多。
但是,上面的設置只是對當前的系統有效,當再次重啟系統時,又得重新設置了。
如果要使每次系統啟動時都打開DMA,可以在/etc/rc.d/rc.local文件中添加上面的命令來實現:
[root@anima lwg]# echo "/sbin/hdparm -c 1 -d 1 -k 1 /dev/hda" >> /etc/rc.d/rc.local
[root@anima lwg]# hdparm命令幫助:
[root@anima lwg]# /sbin/hdparm --help
hdparm - get/set hard disk parameters - version v5.7
Usage: hdparm [options] [device] ..
Options:
-a get/set fs readahead
-A set drive read-lookahead flag (0/1)
-b get/set bus state (0 == off, 1 == on, 2 == tristate)
-B set Advanced Power Management setting (1-255)
-c get/set IDE 32-bit IO setting
-C check IDE power mode status
-d get/set using_dma flag
--direct use O_DIRECT to bypass page cache for timings
-D enable/disable drive defect management
-E set cd-rom drive speed
-f flush buffer cache for device on exit
-g display drive geometry
-h display terse usage information
-i display drive identification
-I detailed/current information directly from drive
--Istdin reads identify data from stdin as ASCII hex
--Istdout writes identify data to stdout as ASCII hex
-k get/set keep_settings_over_reset flag (0/1)
-K set drive keep_features_over_reset flag (0/1)
-L set drive doorlock (0/1) (removable harddisks only)
-M get/set acoustic management (0-254, 128: quiet, 254: fast) (EXPERIMENTAL)
-m get/set multiple sector count
-n get/set ignore-write-errors flag (0/1)
-p set PIO mode on IDE interface chipset (0,1,2,3,4,...)
-P set drive prefetch count
-q change next setting quietly
-Q get/set DMA tagged-queuing depth (if supported)
-r get/set device readonly flag (DANGEROUS to set)
-R register an IDE interface (DANGEROUS)
-S set standby (spindown) timeout
-t perform device read timings
-T perform cache read timings
-u get/set unmaskirq flag (0/1)
-U un-register an IDE interface (DANGEROUS)
-v defaults; same as -mcudkrag for IDE drives
-V display program version and exit immediately
-w perform device reset (DANGEROUS)
-W set drive write-caching flag (0/1) (DANGEROUS)
-x tristate device for hotswap (0/1) (DANGEROUS)
-X set IDE xfer mode (DANGEROUS)
-y put IDE drive in standby mode
-Y put IDE drive to sleep
-Z disable Seagate auto-powersaving mode
-z re-read partition table
[root@anima lwg]#
關於硬盤DMA:
硬盤的DMA模式大家應該都知道吧,硬盤的PATA模式有DMA33、DMA66、DMA100和DMA133,較新的有SATA-150、SATA-300。一般來說現在大多數人用的還是PATA模式的硬盤,硬盤使用DMA模式相比以前的PIO模式傳輸的速度要快2~8倍。DMA模式的啟用對系統的性能起到了實質性的作用。
DMA傳輸模式:
“Ultra DMA Mode *(*為數字,DMA33為2, DMA66為4,DMA100為5、DMA133為6)”。