LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1898|回复: 19

[zz]警惕 laptop-mode-tools 的 HD_IDLE_TIMEOUT 参数

[复制链接]
发表于 2008-4-28 16:06:52 | 显示全部楼层 |阅读模式
原文载于本人 blog。
http://lymanrb.blogspot.com/2008 ... -hdidletimeout.html

之前讨论影响硬盘寿命的 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.



--
由 lyman 于 4/28/2008 04:15:00 下午 在 苦水潭 上发表
发表于 2008-4-28 17:07:57 | 显示全部楼层
看得一头雾水,继续关注此帖
回复 支持 反对

使用道具 举报

发表于 2008-4-28 17:18:51 | 显示全部楼层
真是个大陷阱。待会儿回家,就看看我的本本。
回复 支持 反对

使用道具 举报

发表于 2008-4-28 18:23:37 | 显示全部楼层
我没有使用laptop-mode-tools,一切默认设置,应该不会有什么问题吧。
回复 支持 反对

使用道具 举报

发表于 2008-4-28 19:46:17 | 显示全部楼层
这个好像有过讨论,只有在笔记本长期使用AC电源时并同时打开laptop-mode,可能有影响。aggressive可以翻成激进。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-4-28 22:10:45 | 显示全部楼层
Post by qiang_liu8183;1843517
看得一头雾水,继续关注此帖


好吧,特此把旧文也贴上来,这个之前由 ubuntu 而起,有过很长时间的讨论。

原文地址
http://lymanrb.blogspot.com/2008/01/loadunload-bug.html

还是那个硬盘 load/unload 的 bug

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

结论

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

解决办法

安装 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 这个值太激进(估计 1 分钟 3 次就是它干的),我改成了 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



--
由 lyman 于 1/21/2008 12:38:00 下午 在 苦水潭 上发表
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-4-28 22:12:27 | 显示全部楼层
Post by ganloo;1843588
这个好像有过讨论,只有在笔记本长期使用AC电源时并同时打开laptop-mode,可能有影响。aggressive可以翻成激进。


呵呵,“激进”也不够雅。或许用“愤青”、“左”之类的词更传神。
回复 支持 反对

使用道具 举报

发表于 2008-4-28 22:42:14 | 显示全部楼层
本机没有acpi-support,估计不用改了。
回复 支持 反对

使用道具 举报

发表于 2008-4-29 10:52:19 | 显示全部楼层
我的是本本, 没有安装这个,但是有时候本本处于闲置状态的时候,就听到磁头在条,好像是磁头归位的声音。。。。应该怎么弄呀,怪吓人的。。
回复 支持 反对

使用道具 举报

发表于 2008-4-29 14:46:27 | 显示全部楼层
ubuntu论坛早有讨论,说是ubuntu的bug,造成硬盘寿命减少,就是这个笔记本上专用的laptop工具造成的,我使用后发现硬盘一会就停转,但是你不能叫我不用硬盘把,我一开软件硬盘又开始转。循环。。我想对硬盘肯定不好。。后来不用了,只是给cpu,显卡降频就够了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表