Linux 测试硬盘性能

Linux 测试硬盘性能

一、hdparm测试

(1)安装

[root@oracledb ~]# yum -y install hdparm
已加载插件:fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                     | 3.6 kB     00:00     
extras                                                   | 2.9 kB     00:00     
updates                                                  | 2.9 kB     00:00     
(1/2): extras/7/x86_64/primary_db                          | 243 kB   00:01     
(2/2): updates/7/x86_64/primary_db                         |  12 MB   00:22     
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 hdparm.x86_64.0.9.43-5.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package          架构             版本                    源              大小
================================================================================
正在安装:
 hdparm           x86_64           9.43-5.el7              base            83 k

事务概要
================================================================================
安装  1 软件包

总下载量:83 k
安装大小:152 k
Downloading packages:
hdparm-9.43-5.el7.x86_64.rpm                               |  83 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : hdparm-9.43-5.el7.x86_64                                    1/1 
  验证中      : hdparm-9.43-5.el7.x86_64                                    1/1 

已安装:
  hdparm.x86_64 0:9.43-5.el7                                                    

完毕!

(2)参数

通过帮助信息,查看参数:

[root@oracledb ~]# hdparm -h

hdparm - get/set hard disk parameters - version v9.43, by Mark Lord.

Usage:  hdparm  [options] [device ...]

Options:
 -a   Get/set fs readahead
 -A   Get/set the drive look-ahead 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 drive power mode status
 -d   Get/set using_dma flag
 -D   Enable/disable drive defect management
 -E   Set cd/dvd drive speed
 -f   Flush buffer cache for device on exit
 -F   Flush drive write cache
 -g   Display drive geometry
 -h   Display terse usage information
 -H   Read temperature from drive (Hitachi only)
 -i   Display drive identification
 -I   Detailed/current information directly from drive
 -J   Get/set Western DIgital "Idle3" timeout for a WDC "Green" drive (DANGEROUS)
 -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 multiple sector count
 -M   Get/set acoustic management (0-254, 128: quiet, 254: fast)
 -n   Get/set ignore-write-errors flag (0/1)
 -N   Get/set max visible number of sectors (HPA) (VERY DANGEROUS)
 -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 queue_depth (if supported)
 -r   Get/set device readonly flag (DANGEROUS to set)
 -R   Get/set device write-read-verify flag
 -s   Set power-up in standby flag (0/1) (DANGEROUS)
 -S   Set standby (spindown) timeout
 -t   Perform device read timings
 -T   Perform cache read timings
 -u   Get/set unmaskirq flag (0/1)
 -U   Obsolete
 -v   Use defaults; same as -acdgkmur for IDE drives
 -V   Display program version and exit immediately
 -w   Perform device reset (DANGEROUS)
 -W   Get/set drive write-caching flag (0/1)
 -x   Obsolete
 -X   Set IDE xfer mode (DANGEROUS)
 -y   Put drive in standby mode
 -Y   Put drive to sleep
 -z   Re-read partition table
 -Z   Disable Seagate auto-powersaving mode
 --dco-freeze      Freeze/lock current device configuration until next power cycle
 --dco-identify    Read/dump device configuration identify data
 --dco-restore     Reset device configuration back to factory defaults
 --direct          Use O_DIRECT to bypass page cache for timings
 --drq-hsm-error   Crash system with a "stuck DRQ" error (VERY DANGEROUS)
 --fallocate       Create a file without writing data to disk
 --fibmap          Show device extents (and fragmentation) for a file
 --fwdownload            Download firmware file to drive (EXTREMELY DANGEROUS)
 --fwdownload-mode3      Download firmware using min-size segments (EXTREMELY DANGEROUS)
 --fwdownload-mode3-max  Download firmware using max-size segments (EXTREMELY DANGEROUS)
 --fwdownload-mode7      Download firmware using a single segment (EXTREMELY DANGEROUS)
 --idle-immediate  Idle drive immediately
 --idle-unload     Idle immediately and unload heads
 --Istdin          Read identify data from stdin as ASCII hex
 --Istdout         Write identify data to stdout as ASCII hex
 --make-bad-sector Deliberately corrupt a sector directly on the media (VERY DANGEROUS)
 --offset          use with -t, to begin timings at given offset (in GiB) from start of drive
 --prefer-ata12    Use 12-byte (instead of 16-byte) SAT commands when possible
 --read-sector     Read and dump (in hex) a sector directly from the media
 --repair-sector   Alias for the --write-sector option (VERY DANGEROUS)
 --security-help   Display help for ATA security commands
 --trim-sector-ranges        Tell SSD firmware to discard unneeded data sectors: lba:count ..
 --trim-sector-ranges-stdin  Same as above, but reads lba:count pairs from stdin
 --verbose         Display extra diagnostics from some commands
 --write-sector    Repair/overwrite a (possibly bad) sector directly on the media (VERY DANGEROUS)

主要参数:
-a<快取分区> 设定读取文件时,预先存入块区的分区数,若不加上<快取分区>选项,则显示目前的设定。

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

(3)硬盘基本信息

检查硬盘的基本信息
hdparm /dev/sda


[root@oracledb ~]#  hdparm /dev/sda   

/dev/sda:
 multcount     =  0 (off)
 IO_support    =  1 (32-bit)
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 243201/255/63, sectors = 3907029168, start = 0

对比fdisk看硬盘信息:

[root@oracledb ~]# fdisk -l

磁盘 /dev/sda:2000.4 GB, 2000398934016 字节,3907029168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:dos
磁盘标识符:0x000be460

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048  3907028991  1953001472   8e  Linux LVM

磁盘 /dev/mapper/centos-root:1660.1 GB, 1660071968768 字节,3242328064 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节


磁盘 /dev/mapper/centos-swap:16.8 GB, 16844324864 字节,32899072 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节


磁盘 /dev/mapper/centos-home:322.9 GB, 322948825088 字节,630759424 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节

(4)磁盘读性能

hdparm -t /dev/sda :硬盘读
hdparm -T /dev/sda:硬盘缓存读
hdparm -tT --direct /dev/sda:硬盘读性能
hdparm -cdt /dev/sda:硬盘直接读

[root@oracledb ~]# hdparm -t /dev/sda

/dev/sda:
 Timing buffered disk reads: 718 MB in  3.01 seconds = 238.87 MB/sec
[root@oracledb ~]# hdparm -T /dev/sda

/dev/sda:
 Timing cached reads:   34628 MB in  2.00 seconds = 17342.99 MB/sec
[root@oracledb ~]# hdparm -tT --direct /dev/sda

/dev/sda:
 Timing O_DIRECT cached reads:   490 MB in  2.00 seconds = 244.46 MB/sec
 Timing O_DIRECT disk reads: 572 MB in  3.01 seconds = 190.07 MB/sec

[root@oracledb ~]# hdparm -cdt /dev/sda

/dev/sda:
 IO_support    =  1 (32-bit)
 HDIO_GET_DMA failed: Inappropriate ioctl for device
 Timing buffered disk reads: 534 MB in  3.01 seconds = 177.59 MB/sec
[root@oracledb ~]# 

二、time和dd测试

用8K,16K,32K,64K块文件测试:
块越大,速度越高 ,稳定在388M/s

[root@oracledb ~]#  time dd if=/dev/sda of=/dev/null bs=8k count=100000 
记录了100000+0 的读入
记录了100000+0 的写出
819200000字节(819 MB)已复制,4.11789 秒,199 MB/秒

real    0m4.120s
user    0m0.046s
sys     0m1.145s
[root@oracledb ~]#  time dd if=/dev/sda of=/dev/null bs=16k count=100000  
记录了100000+0 的读入
记录了100000+0 的写出
1638400000字节(1.6 GB)已复制,4.34149 秒,377 MB/秒

real    0m4.344s
user    0m0.029s
sys     0m0.655s
[root@oracledb ~]#  time dd if=/dev/sda of=/dev/null bs=32k count=100000   
记录了100000+0 的读入
记录了100000+0 的写出
3276800000字节(3.3 GB)已复制,8.44203 秒,388 MB/秒

real    0m8.443s
user    0m0.047s
sys     0m1.122s
[root@oracledb ~]#  time dd if=/dev/sda of=/dev/null bs=64k count=100000   
记录了100000+0 的读入
记录了100000+0 的写出
6553600000字节(6.6 GB)已复制,17.0282 秒,385 MB/秒

real    0m17.029s
user    0m0.047s
sys     0m2.024s
[root@oracledb ~]# 

你可能感兴趣的:(Linux,优化,linux,运维,服务器)