http://lymanrb.spaces.live.com/blog/cns!A8ABB185AA013BB7!241.entry http://www.linuxsir.org/bbs/thread332608.html
标题: [zz] 笔记本硬盘到底能 unload 多少次?

Ubuntu也许将成为你的笔记本硬盘杀手 http://linux.solidot.org/article.pl?sid=07/11/01/0451253 matrix 发表于 2007年11月01日 12时50分 星期四    Printer-friendly    Email story
来自一年坏一次部门 Bug Ubuntu 数据存储 LinuxUbuntu系统的ACPI电源管理默认设置 存在问题,当用户切换到电池供电模式时,/etc/acpi/power.sh向所有块设备发出一个hdparm -B 1命令,这会导致出现频繁的负荷循环(load cycles)。发现 Bug #59695的 用户称仅在100小时内就出现了7000次负荷循环。大多数笔记本硬盘只能承受至多60万次此类循环,这意味着它会大幅度减少笔记本硬盘的寿命。SATA 硬盘用户可以输入“smartctl -d ata -a /dev/sda”命令来查看负荷循环次数,但需要先安装Smartmontools软件包(apt-get下)。

小心Ubuntu谋杀你的笔记本硬盘 http://bbs.zdnet.com.cn/thread-131929-1-1.html

现已确认,Ubuntu系统的ACPI电源管理机制存在缺陷,会大幅减少笔记本硬盘的寿命。

如果安装了Ubuntu的笔记本用户转入电池供电模式,则“/etc/acpi/power.sh”中的默认配置会导致极其频繁的载入循环,报告称100 小时即可达到7000多次,而资料显示大多数笔记本硬盘最多只能承受60万次这种循环。换算下来,这相当于一块全新的笔记本硬盘只能连续实用不到1年。

SATA硬盘用户可以安装硬盘检测工具Smartmontools检查一下自己的笔记本,输入“smartctl -d ata -a /dev/sda”命令即可查看载入循环次数。

在IBM ThinkPad Z60m/T43、HP Compaq nw9440等笔记本上都已确认了这一bug

警惕 laptop-mode-tools 的 HD_IDLE_TIMEOUT 参数

之前讨论影响硬盘寿命的 load/unload 的问题(见旧文一旧文二),都是集中于对 haprm -B 参数的调整。而这次要提醒大家注意的,是 hdparm -S 参数。

这里是 man hdparm 的 -S 部分的说明。


Set the standby (spindown) timeout for the drive. This value is used by the drive to deter‐mine 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 "timeouts are disabled": the device will not automatically enter standby mode. Values from 1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes. Values from 241 to 251 specify from 1 to 11 units of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours. A value of 252 signifies a timeout of 21 minutes. A value of 253 sets a vendor-defined timeout period between 8 and 12 hours, and the value 254 is reserved. 255 is interpreted as 21 minutes plus 15 seconds. Note that some older drives may have very different interpretations of these values.


看了之后冷汗直冒,实在是一个杀伤力很强的参数。如果有幸使用了 laptop-mode-tools,那么可以看一下 /etc/laptop-mode/laptop-mode.conf 里面,关于 -S 参数定义的部分。

#
# Should laptop mode tools control the hard drive idle timeout settings?
#
CONTROL_HD_IDLE_TIMEOUT=1

#
# Idle timeout values. (hdparm -S)
# Default is 2 hours on AC (NOLM_HD_IDLE_TIMEOUT_SECONDS=7200) and 20 seconds
# for battery and for AC with laptop mode on.
#
LM_AC_HD_IDLE_TIMEOUT_SECONDS=20
LM_BATT_HD_IDLE_TIMEOUT_SECONDS=20
NOLM_HD_IDLE_TIMEOUT_SECONDS=7200


我的 archlinux 上,laptop-mode-tools 使用的默认值仅仅是 20 秒!赶紧检查了一下 Load Cycle Count 的值(可能需要 root 权限,请自行 sudo),

$ smartctl -a /dev/sda | grep 193
193 Load_Cycle_Count 0x0032 100 100 000 Old_age Always - 18556

如此高的数值,1 月份买的新机器,华丽地中招了 :(

预 防办法很简单,将上述各 IDLE 值相应调大即可。不知道为什么 laptop-mode-tools 的默认设置会如此“有进取心的”(这里还真没想到用什么词比较贴切,英文可以用 aggressive)。或许对于这个问题,laptop-mode 的开发方并没有给予太多关注。

Spinning down too many times may kill hard drives

Desktop hard drives are usually rated for only 40,000-50,000 spinups, and one spinup every 10 minutes will kill your 40,000-spinup HD in 277 days. So this is NOT recommended for server use, unless you increase the spinup interval dramatically, to say once every hour or two. Laptop hard drives are usually rated for around 300,000 spinups, so those will last about 2083 days or 6 years if you have them powered on 24-7.



还是那个硬盘 load/unload 的 bug

新买了笔记本,所以对这个问题也有了新的认识(查老本的 load 次数都 11w 多了……)。

结论

这个问题确实存在。起因是硬盘频繁 load/unload 的声音引起了我的注意。查了一下,在卸掉 vista 装上 ubuntu 总共开机 18小时的时间里,这个指标达到了 3xx,平均 3 分钟 1 次,这个指标太吓人了。

解决办法

安装 laptop-mode,手动编辑 /etc/laptop-mode/laptop-mode.conf,大概 216 行左右,按如下修改:


#
# Should laptop mode tools control the hard drive power management settings?
#
CONTROL_HD_POWERMGMT=1


#
# Power management for HD (hdparm -B values)
#
BATT_HD_POWERMGMT=192
LM_AC_HD_POWERMGMT=254
NOLM_AC_HD_POWERMGMT=254


第 一项是为了让对硬盘参数的设置纳入 laptop-mode 管理(默认不开)。后面三个就是指定各种模式下的硬盘参数了。默认情况下是 1/255/255。1 这个值太激进(估计 3 分钟 1 次就是它干的),我改成了 192(电池模式下毕竟还是要省电的,虽然这个值在不同品牌的硬盘可能表现差异很大,但是根据我搜索的结果,设置成 192 的时候硬盘已经很难有机会自行 unload 了)。后两个默认值 255 是可以不改的,但是 255 是直接关闭 APM(高级电源管理),据说某些硬盘可能会忽略 255 这个极端值,所以改成 254(我的出发点其实还是不想舍弃 APM)。

然后是修改 /etc/default/acpi-support 这个文件。文件末尾两个参数,按如下设置:

# Switch to laptop-mode on battery power - off by default as it causes odd
# hangs on some machines
ENABLE_LAPTOP_MODE=true

# Spindown time on battery
SPINDOWN_TIME=60


第一项是开启 laptop-mode,第二项似乎是控制用来控制硬盘空闲多长时间自动断电的,可根据自己喜好修改(默认值是 12)。

经几天观察,基本上这个 Load Cycle Count 只在关机的时候才会增加了。

附:监测 Load Cycle Count 的方法

sudo smartctl -a /dev/sda


设备可能是 /dev/hda(IDE 硬盘)或 /dev/sdb(第二块硬盘)等等。如果觉得输出太多,可以加上 grep 193。


sudo smartctl -a /dev/sda | grep 193



archlinux 下的 load/unload 问题

大概两周前把笔记本上的 linux 从 ubuntu 迁移到了 archlinux。现在感觉一切良好。archlinux 的各种配置确实比 ubuntu 感觉要更清晰而有条理,所以折腾起来是一件令人愉快的事。

作为笔记本用户,第一关心的当然是据称涉及所有 linux 发行版的硬盘 killer 问题,之前也写过一篇文章,主要涉及 laptop-mode 的设置,对于这一块来说,archlinux 的设置并没有什么不同。

但是如果启动的时候插着电源,laptop-mode 是默认不开启的。于是有必要增加一点“保险措施”。即在 /etc/rc.local(这个文件是专门留给用户编辑的)里加上


#


p.s. 如果不加任何设置,我的笔记本自带的硬盘 FUJITSU MHY2120BH 的 apm level 默认是 128。

p.s. 其实强制 laptop-mode 启用,在 rc.conf 的 DAEMON 里面直接加上 laptop-mode 是更省事的办法。