笔记本电脑退出挂起状态时 APM 级别被重置

笔记本电脑退出挂起状态时 APM 级别被重置

在调查为什么我的硬盘负载循环次数增加我观察到,每次我在运行 MATE 的 Debian Jessie 笔记本电脑上退出挂起状态时,我的 APM 级别都会被重置:

$ sudo smartctl --get=apm /dev/sda
...
APM feature is:   Disabled
$ sudo hdparm -I /dev/sda | grep level
    Advanced power management level: disabled
$ sudo hdparm -B /dev/sda

/dev/sda:
 APM_level  = off

将笔记本电脑置于挂起状态然后将其退出挂起状态后,出现以下情况:

$ sudo hdparm -I /dev/sda | grep level
    Advanced power management level: 128
$ sudo smartctl --get=apm /dev/sda
...
APM level is:     128 (minimum power consumption without standby)
$ sudo hdparm -B /dev/sda

/dev/sda:
 APM_level  = 128

我尝试启用 APM 选项/etc/hdparm.conf,但似乎没有帮助:

...
# -B apm setting
#apm = 255
apm = 255
# -B apm setting when on battery
#apm_battery = 127
apm_battery = 255
...

然后:

$ sudo /etc/init.d/hdparm restart

将硬盘置于挂起状态并重新开启后,我注意到 APM 级别已回到 128。

答案1

您使用 SSD 驱动器吗?就我而言,默认设置的 HDD 声级管理/etc/hdparm.conf是罪魁祸首。

这些设置最终对我起了作用:

# quiet # this should be commented out

/dev/disk/by-id/<YOUR_DISK_UUID> {
        acoustic = 128
        keep_features_over_reset = on
}

在此之后,我的 SSD 驱动器停止在挂起/恢复时改变 APM 级别,并且这修复了 SG_IO 错误,可能与同一个问题有关。

有关查找磁盘 UUID 和 hdparm 配置的更多信息,请参见此处: http://forum.havetheknowhow.com/viewtopic.php?t=479

希望有帮助!

答案2

我一直没有找到根本原因,但我能够通过在新/etc/systemd/system/tweak_hdparm_apm-resume.service文件中添加以下内容来解决这个问题:

[Unit]
Description=Sets APM value to 254
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
User=root
Type=oneshot
ExecStart=/path/to/tweak_hdparm_apm.sh

TimeoutSec=0
StandardOutput=syslog

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

然后tweak_hdparm_apm.sh在每次唤醒时运行以下命令:

#!/bin/sh
#
# Something on my Debian laptop keeps setting the APM level to 128 every
# time it comes out of sleep. This script sets the value to 254 for best
# performance and least aggressive APM to conserve the life of the hard
# drive.

# --- Running hdparm -B to get current value
oldvalue=$(/sbin/hdparm -B /dev/sda)

# --- Running hdparm to set new -B value to 254 (APM best/highest I/O performance and least aggressive APM)
/sbin/hdparm -B 254 /dev/sda

newvalue=$(/sbin/hdparm -B /dev/sda)

echo "$(date) Args: ${*} Oldvalue: ${oldvalue} Newvalue: ${newvalue}" >> tweak_hdparm_apm.log

exit ${?}

相关内容