文档章节

Tune Your Hard Disk with hdparm

CasparLi
 CasparLi
发布于 2017/08/17 11:23
字数 2773
阅读 19
收藏 0
点赞 0
评论 0

By 

Tim Schürmann

Hdparm is the tool to use when it comes to tuning your hard disk or DVD drive, but it can also measure read speed, deliver valuable information about the device, change important drive settings, and even erase SSDs securely.

In 2005, Canadian Mark Lord developed the small hdparm utility to test Linux drivers for IDE hard drives. Since then, the program has developed into a valuable tool for diagnosis and tuning of hard drives. For example, it tests the speed of hard drives and solid state disks, puts devices to sleep, and turns the energy-saving mode on or off. With modern devices, it can activate the acoustic mode and clean up SSDs. Before your first experiments with hdparm, you should read about safety concerns in the “Warning!” box.

Need for Communication

All reasonably new distributions already include hdparm in the basic installation. You only need to open a terminal and call up

hdparm -I /dev/sda | more

as administrator (Figure 1).

Figure 1: Hdparm lists the hardware properties of a six-year-old hard disk with a 320GB capacity.

The tool will deliver all available data about the chosen drive – in this case, the first hard disk sda. The | more option makes sure the large amount of information does not simply rush unread through the terminal.

Hdparm accepts any device as mass storage that is connected to an (E)IDE, SATA, or SAS interface, including, therefore, DVD drives and SSDs. USB-to-IDE adapters often cause problems because they do not transmit the (complete) ATA or ATAPI commands to the drive. The information that hdparm delivers is dependent on the device. The designation and firmware version number are always listed at the top under Model Number and Firmware Revision. Owners of an SSD especially can find out quickly whether they are running the current firmware version.

On newer hard disks, you should check whether Native Command Queuing (NCQ) is to be found under Commands/features. This technology makes it possible for the hard disk to sort queries from the system in such a way that the heads take the shortest possible path. SSDs, on the other hand, distribute write accesses more efficiently across storage blocks. Ideally, this leads to an increase in speed. If NCQ is deactivated, check the BIOS to find out whether the drive is running in AHCI mode, which is also necessary for other functions such as energy management.

Speedometer

To determine how fast a drive delivers data, use the

hdparm -t /dev/sda

command. After a few seconds, the data transfer rate appears (in megabytes per second, MBps). The small program reads directly from the drive for a while regardless of the filesystem. The speed measured is therefore somewhat faster than in actual practice. To receive an untainted result, no other programs should be running during the measurement, and enough main memory should be free. Repeat the measurement at least three times and then calculate the average value. For a current model, the result should reach at least 80 MBps (Figure 2).

Figure 2: This SATA hard drive achieved an average read speed of 80.48 MBps.

The Linux kernel deposits the data retrieved from the hard drive into a buffer. To determine the speed of the unadorned drive, you can use the

hdparm -t --direct /dev/sda

command. Hdparm then reads the data directly from the disk. The values thus measured will be somewhat slower than without --direct, but at least you can see the pure transmission rate of the disk (Figure 3).

Figure 3: Without the buffer, transmission rate drops dramatically. At the middle of the 320GB hard drive, more speed losses are seen.

Hdparm always reads the data from the beginning of the storage device. Hard disks, however, tend to deliver data somewhat more slowly from the outer areas of magnetic disks; therefore, hdparm lets you set an offset (from software version 9.29 on):

hdparm -t --direct --offset 500 /dev/sda

The 500 stands for the number of gigabytes to skip. On a 1TB hard disk, the command above would therefore deliver data from the middle of the disk. As Figure 3 shows, reading speed drops quite markedly in the outer areas of a hard disk.

All the speed tests introduced here only give a first impression of possible problems and bottlenecks. For a complete benchmark, however, you would also need to determine the write speed, for example.

Faster, Faster

Some drive properties can be changed while the device is in operation; for example, most drives allow you to turn power management on and off. Just which functions hdparm can change and activate on a hard drive can be called up with

hdparm -I /dev/sda

and are found under Commands/features (Figure 1). All functions found there and marked with an asterisk are currently active, and hdparm can use the rest or at least activate them.

To speed up data transmission, a hard disk usually reads several sectors at the same time. How many it can deliver at the same time is revealed by

hdparm -I /dev/sda

and is listed after R/W multiple sector transfer: Max =. This value should also be found in the same line after Current =. If that is not the case, you can increase the value with:

hdparm -m16 /dev/sda

This instructs the hard drive always to deliver 16 sectors at once.

Curiously, some hard drives run slower with higher values: The hdparm man page mentions primarily older Caviar drives from Western Digital. In such cases, you should reduce the number of sectors again or even turn the function off completely, which is done with:

hdparm -m0 /dev/sda

Beyond this, modern drives can even retrieve a few sectors in advance (“read ahead”). To define how many, use the -a switch (Figure 4, top) – for example:

hdparm -a256 /dev/sda

Figure 4: Here, the read-ahead is set to 256, and acoustic management is currently deactivated.

Here, the drive will read the 256 sectors in advance that are most likely the next to be requested. Higher values speed up above all the reading of large files – at the cost, however, that reading smaller ones takes longer. The current setting is shown with

hdparm -a /dev/sda

Beyond that, many drives also possess a built-in, additional read-ahead function. As a rule, therefore, you can leave the setting at the default value.

How fast queries from the operating system reach the hard drive controller can be called up with

hdparm -c /dev/sda

The value should be 32-bit; you can force this value with the -c3 switch.

Full Speed Ahead

Many modern hard drives allow you to slow down the head movement. Although doing so will increase access times, it will also reduce the noise level. To find out whether your own hard drive offers this “acoustic mode,” you can use this command:

hdparm -M /dev/sda

If a number follows the equal sign, as shown in Figure 4 (bottom), the drive can be put into a quiet mode with:

hdparm -M 128 /dev/sda

To reach the highest speed, use the maximum value:

hdparm -M 254 /dev/sda

Values between 128 and 254 are allowed, resulting in a trade-off between noise level and speed. Incidentally, your Linux kernel must also support acoustic management, which should be the case for all current major distributions.

Some CD and DVD drives turn out to be more like turbines: Their high-speed rotation can hinder audio/video enjoyment. The

hdparm -E 4 /dev/sr0

command will provide relief. The parameter 4 determines speed, and /dev/sr0 specifies the DVD drive. This example slows drive reading speed ninefold.

Write-Back Caching

With write-back caching, the hard drive first stores the data to be written in a buffer. In this way, it can accept data much faster, which in the end leads to a faster write speed. The

hdparm -W /dev/sda

command shows whether write-back caching is active with a 1 after the equals sign; otherwise, you can activate the function with the -W1 switch.

If hdparm will not allow this change, you need to make sure that write-back caching has been activated in the BIOS. However, this function is not recommended for all situations: In the case of a power outage, the data in the buffer would be lost permanently.

If a program sensitive to data loss – such as a database – is running on the system, you should turn off the write-back cache with the -W0 switch. Documentation for the PostgreSQL database even explicitly recommends that this be done.

Live Wire

If a hard disk or SSD doesn’t have anything to do for a certain period of time, it automatically enters sleep mode. This power-saving feature can be influenced with the -B parameter. Thus, using:

hdparm -B255 /dev/sda

would deactivate energy management; however, not all drives allow this.

Instead of 255, values between 1 and 254 are allowed. A higher value means more power is used but also promises higher performance or speed. Values between 1 and 128 allow the drive to shut down, whereas values from 129 to 254 forbid that from happening.

The most power can be saved with a value of 1; the highest rate of data transmission (I/O performance) is achieved with 254. You can call up the current value with:

hdparm -B /dev/sda

The specific effect the different values will have depends on the drive itself. However, you should keep in mind that too many shutdowns are not good for desktop hard drives: Each time it shuts off, the drive must park the heads, which increases wear and tear. Consequently, you shouldn’t wake your hard drive up every two seconds – which always takes more than two seconds to do.

You can set how many seconds of idleness the hard drive should wait before it goes to sleep with the

hdparm -S 128 /dev/sda

switch; however, this value here is not in seconds but a number between 1 and 253. The hard drive multiplies this value by another. The value chosen in the example, 128, lies between 1 and 240, for which the drive uses a factor of five. Consequently, it would shut down after 640 seconds of idleness.

From 241 and up, the multiplication factor increases steadily. At 251, the waiting period has increased to 5.5 hours. At 253, the value is preset by the manufacturer, usually between eight and 12 hours. The value 254 is left out; at 255, the drive will wait 21 minutes and 15 seconds. A value of 0 will deactivate sleep mode completely. To send the hard drive to sleep immediately, enter:

hdparm -y /dev/sda

With a capital Y, the drive will go into an even deeper state of sleep. Depending on the drive, the drive might only wake up from a deep sleep after a reset of the whole system.

Cleanup

SSDs track the location of the data deposited on them independently of the operating system. This can lead to the curious situation that a file has been deleted but the SSD still has its former location marked as occupied. To remedy such conflicts, newer versions of hdparm include the wiper.shscript. Entering

wiper.sh /dev/sda

determines which blocks are being used and which are not and reports this to the SSD. However, this script must be used with caution: The documentation warns explicitly that data could be lost and advises against its use with the Btrfs filesystem. Drives with ext2/3/4, Reiser3, and XFS should be mounted as read-only before using the wiper command. It would be best to unmount the drive completely or start wiper.sh from a Live system. In any case, you should definitely make a backup of the SSD beforehand and use the script only in an emergency. Incidentally, because wiper is so dangerous, some distributions do not even include it.

Secure Deletion

To achieve higher transfer rates and spread use equally over the storage chips, SSDs also reserve some storage areas (wear leveling), so that simply formatting an SSD will seldom delete the whole drive. Most SSDs therefore offer a function called secure erase, which causes the drive to empty all its storage cells. This is especially useful should you decide to give up your used SSD.

Secure erase has two pitfalls: hdparm can only initiate a secure erase when the BIOS also allows it. Beyond that, the method is considered to be experimental. The documentation warns explicitly about using the procedure because, in the worst case, secure erase could make the whole SSD unusable. If you want to use this delete function anyway, first call up the identification information with:

hdparm -I /dev/sdb

Under Security, the line supported: enhanced erase should show up somewhere; otherwise, the SSD won’t support secure erase. Next, turn on the security function of the drive by (temporarily) setting a password like 123456:

hdparm --user-master u --security-set-pass 123456 /dev/sdb

When you call up the identification information again, you will now find enabled under Security. To erase the SSD now, enter:

hdparm --user-master u --security-erase 123456 /dev/sdb

In the process, hdparm also removes the password. The whole process takes a few minutes, depending on the size of the SSD, during which no feedback is given.

Afterward, when you call up the identification information, the area under Security should again look like it did before setting the password.

Relics

In the case of older hard drives with an IDE connector (also called PATA), you should take a look at the using_dma line in the identification output. With the help of DMA (Direct Memory Access) technology, the hard drive itself deposits data directly into main memory. If the respective flag is 0 (off), it will slow down the data transfer. Over the years, ever faster DMA standards have been introduced; the fastest possible can be activated with the command:

hdparm -d1 /dev/hda

On some very old systems, however, the DMA mode can cause problems. After activating it, you should therefore copy a few larger test files to the drive. If problems arise or the drive crashes, deactivate the DMA mode again with:

hdparm -d0 /dev/hda

Incidentally, modern SATA drives always use DMA.

While the hard drive is transferring the requested data, the rest of the system can go about completing other tasks – but only if an on appears after unmaskirq in the identification info output. You can force this mode with the -u1 switch.

Lasting Values

After restarting the system, all changes made with hdparm are lost. To activate them permanently, the respective hdparm commands must be entered in the start scripts. How this is done depends on the distribution you are running, but usually the entry must be made in /etc/rc.local.

Debian-based systems, on the other hand, read the /etc/hdparm.conf configuration file on system startup. In it is a section for each hard drive with the following format:

/dev/sda {
  ...
}

Modern Linux systems randomly allocate device names (sdasdb). To assign the hdparm settings to a specific drive permanently, use its specific UUID:

/dev/disk/by-id/ata-SAMSUNG_HD103SJ_S246J1RZB00034 {...}

The settings belong between the curly braces. Each parameter has its own name. Acoustic management is set, for example, to the value of 128 with:

acoustic_management = 128

Which name belongs to which hdparm parameter is revealed by the comments at the top of the file.

Conclusions

Hdparm also includes many other parameters that can be quite dangerous. For example, many SSDs can be protected with a password, which can lead to data loss in some situations. It’s not a coincidence that the man page (man hdparm) warns about the dangers.

Incidentally, hdparm is only one useful tool among many; for example, the smartmontools can determine the health status of a hard drive.

Related content

  • hdparm Drive Utility

    Hdparm is the tool to use when it comes to tuning your hard disk or DVD drive, but it can also measure read speed, deliver valuable information about the device, change important drive settings, and even erase SSDs securely.

    more »

  • hdparm and DMA

    A simple command helps you switch on the afterburner for your hard disks and drives. hdparm improves the performance of your storage devices.

    more »

  • Ask Klaus!

    Klaus Knopper answers your Linux questions.

    more »

  • Hdparm Goes 8.1

    Moving from version 7.7 to 8.1 gives users of the hard disk tool new options and new information displays.

    more »

  • TKperf

    TKperf combines several SSD tools under one roof. You can use TKperf to investigate SSDs before deployment and even to measure performance.

    more »

本文转载自:http://www.linux-magazine.com/Online/Features/Tune-Your-Hard-Disk-with-hdparm

共有 人打赏支持
CasparLi
粉丝 13
博文 129
码字总数 26212
作品 0
成都
程序员
[转载] 磁盘硬件问题(坏块)检测

标签 PostgreSQL , Linux , Windows , SSD , smartctl , smartmontools , badblocks , hdparm , HD Tune 背景 Linux下面可以使用smartctl , badblocks检查是否有坏块。 Win下面可以使用HD Tu......

德哥
04/18
0
0
硬盘测试——hdparm

hdparm(hard disk parameters) 语法:hdparm [-CfghiIqtTvyYZ][-a ][-A <0或1>][-c ][-d <0或1>][-k <0或1>][-K <0或1>][-m ][-n <0或1>][-p ][-P ][-r <0或1>][-S ][-u <0或1>][-W <0或1>]......

jesse-lin
2016/10/29
8
0
在Linux操作系统下如何开启硬盘DMA (2)

Linux下的32位I/O和DMA默认是关闭的。如果用的是16位I/O的话,就无法充分发挥电脑的性能。 如果要打开32位I/O和DMA,就需要以root身份进行设置。为了降低因出错而重启系统对文件系统的损害,...

zt371
2009/05/07
413
0
RedHat 下的硬盘读写速度测试工具

执行一下以下命令看看你服务器的磁盘性能如何。 hdparm -Tt /dev/sda 以下是 2块 希捷 ES2 SATA 500G 做 Raid0 的速度 [root@admin ~]# hdparm -Tt /dev/sda /dev/sda: Timing cached reads:...

范堡
2009/02/25
766
0
Linux 下的硬盘读写速度测试工具

Linux 下的硬盘读写速度测试工具 执行一下以下命令看看你服务器的磁盘性能如何。 hdparm -Tt /dev/sda 以下是 2块 希捷 ES2 SATA 500G 做 Raid0 的速度 [root@admin ~]# hdparm -Tt /dev/sd...

范堡
2009/04/17
4.5K
6
Linux系统下测试磁盘读写IO性能(物理机和虚拟机的测试)

1、写速度测试 用dd命令进行测试,以每次写入8k的数据,执行300000次,time命令显示执行过程的时间,执行完成后生成/test.disk文件,大小为2.3G,下面是两台物理服务器和一台虚拟机的写入速度...

HMLinux
2016/08/24
0
0
Linux 硬盘分区、格式化、自动挂载配置

转载:http://aofengblog.blog.163.com/blog/static/6317021201101502540117/ Ubuntu系统的硬盘空间不够用了,需要增加新的硬盘扩容。将硬盘分区、格式化、自动挂载配置的整个过程记下来,备...

careluck
2017/09/28
0
0
OPTIMIZING NGINX FOR HIGH TRAFFIC LOADS

I have previously talked about some of the most common nginx questions; not surprisingly, one such question is how to optimize nginx for high performance. This is not really ove......

煮酒品茶
2014/03/25
0
0
Oracle在Linux操作系统下的安装小结

如果是为了在一台仅有256M内存的普通PC机上试用Oracle9i,在分配了1GB左右的交换空间的情况下,也可以正常运行Oracle数据库。 要检查内存空间,登录进入Linux,在命令行方式(bash环境)下执行...

JavaGG
2009/05/07
239
0
菜鸟学Linux 第111篇笔记 Memory

菜鸟学Linux 第111篇笔记 Memory 建议查看原文(因为复制版的格式可能有问题) 原文出自 Winthcloud 链接: 内容总览 内存子系统组件 Memory提升 Viewing system calls Strategies for usin...

Winthcloud
2017/05/31
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

Spring配置xml启动报错 Connot find 'beans'

1.我们先看一下spring的原始配置 <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSc......

江湖鱼大虾
9分钟前
0
0
与女儿谈商业模式 (4):戴尔的成功秘诀

分类:与女儿谈商业模式 | 标签: 戴尔 经济学 陈志武 2007-05-15 10:26阅读(7434)评论(36)   2007年5月《创富志》与“女儿谈商业模式”专栏 (之四)   戴尔的成功秘诀   陈志武   ...

祖冲之
19分钟前
0
0
www.w3.org被qiang导致logback报错:Connect reset

web项目部署到tomcat后,web项目中的logback不能运行,报错信息如下: Reported exception: ch.qos.logback.core.joran.spi.JoranException: I/O error occurred while parsing xml file......

浮躁的码农
33分钟前
0
0
JDeveloper中文乱码解决

全局设置字体; 全局设置环境编码; 项目设置编译器环境编码。

wffger
今天
2
0
MySQL主从介绍 , 准备工作,配置主,配置从, 测试主从同步

MySQL主从介绍 MySQL主从又叫做Replication、AB复制。简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步的 MySQL主从是基于binlog的,主上须开启bin...

TaoXu
今天
2
0
线性代数学习总结

亭子happy
今天
1
0
Java8:Lambda表达式增强版Comparator和排序

1、概述 在这篇教程里,我们将要去了解下即将到来的JDK 8(译注,现在JDK 8已经发布了)中的Lambda表达式——特别是怎样使用它来编写Comparator和对集合(Collection)进行排序。 这篇文章是...

孟飞阳
今天
0
0
从架构到组件,深挖istio如何连接、管理和保护微服务2.0?

近几年我一直从事于微服务系统的设计以及实现方面的工作,属于微服务架构一线实践者。之前做过一些单体系统的微服务改造,在微服务拆分、治理等方面都有一定的经验。 本人比较特殊一点的经历...

xiaomin0322
今天
1
0
基于vue的h5文件切片上传(获取文件md5,实现秒传、进度条实现)

template <button @click="file"></button><label ref="upload" style="position: relative;"> <input type="file" @change="selectFile" style="position: abs......

hkaikai
今天
2
0
Spring Boot 2.0 项目实现自同步AD域账号

在通过Spring Boot的自动化装配功能及JDK自带的LDAP模块,可通过如下几个简单步骤实现业务系统自动同步AD域账号功能。 1. Java自带ldap搜索域账号信息核心代码: try { LdapContext ctx...

B超
今天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部