欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

hdparm 命令使用;关闭硬盘 HDD cache; 硬盘读写性能测试;

程序员文章站 2022-04-13 09:06:44
最新需要使用硬盘做一些测试,需要使用到hdparm工具,并进行了解,并进行简要记录; hdparm、dd、fio、都是很好的硬盘测试软件;通常使用其对硬盘信息做基本了解; 关闭硬盘写Cache用例: hdparm -W /dev/sdh # 查看写缓存状态; hdparm -W 0 /dev/sdh ......

最新需要使用硬盘做一些测试,需要使用到hdparm工具,并进行了解,并进行简要记录;

hdparm、dd、fio、都是很好的硬盘测试软件;通常使用其对硬盘信息做基本了解;

关闭硬盘写cache用例:

hdparm -w  /dev/sdh # 查看写缓存状态;
hdparm -w  0 /dev/sdh # 关闭cache,保证数据强一致性;放置断电时数据未落盘;
hdparm -w  1 /dev/sdh # 打开

测试磁盘和磁盘缓存读取速度:

查看磁盘信息:
fdisk -l  /dev/sdh
hdparm /dev/sdh
评估磁盘读取速度:
hdparm -t /dev/sdh
评估磁盘缓存读取速度:
hdparm -t /dev/sdh
直接测试硬盘的读性能(绕过内核页缓存):
hdparm -tt --direct /dev/sdh
顺序写测试:
time -p  bash -c "dd if=/dev/urandom of=./dd.log bs=1m count=50000"
随机写测试:

命令使用方法说明:

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)

保持更新,更多内容请关注cnblogs.com/xuyaowen;