执子之手

与子偕老


  • 首页

  • 分类

  • 归档

  • 标签

  • 关于

  • 搜索
close

Mac休眠模式调整

时间: 2020-08-11   |   分类: 技巧     |   阅读: 1661 字 ~4分钟   |   访问: 0

手头的Mac已经用了三年了,之前合盖睡眠的时候感觉掉电还不明显,最近几次系统升级后感觉掉电的情况明显了,一个晚上会掉5%左右,虽然不多,但是还是不爽。 经过搜索,发现可以通过修改休眠模式,来解决这个问题,特此记录一下。

1. pmset及参数介绍

pmset是Mac的一个系统命令,可以用来修改和电源管理相关的参数。看man中的帮助:

pmset can modify the values of any of the power management settings defined below. You may specify one or more setting & value pairs on the command-line invocation of pmset. The -a, -b, -c, -u flags determine whether the settings apply to battery ( -b ), charger (wall power) ( -c ), UPS ( -u ) or all ( -a ).

简单来说就是可以通过pmset -b或pmset -c,pmset -a等命令修改电源配置参数。当然也可以通过pmset -g命令查询当前的配置参数或日志等。例如以下命令可以查看当前系统的电源相关配置:

 1> pmset -g custom
 2Battery Power:
 3 lidwake              1
 4 autopoweroff         1
 5 standbydelayhigh     1800
 6 autopoweroffdelay    28800
 7 standbydelaylow      600
 8 standby              1
 9 proximitywake        0
10 ttyskeepawake        1
11 hibernatemode        3
12 powernap             0
13 gpuswitch            2
14 hibernatefile        /var/vm/sleepimage
15 highstandbythreshold 95
16 displaysleep         2
17 sleep                1
18 acwake               0
19 halfdim              1
20 tcpkeepalive         1
21 lessbright           1
22 disksleep            10
23AC Power:
24 lidwake              1
25 autopoweroff         1
26 standbydelayhigh     86400
27 autopoweroffdelay    28800
28 standbydelaylow      10800
29 standby              1
30 proximitywake        1
31 ttyskeepawake        1
32 hibernatemode        3
33 powernap             1
34 gpuswitch            2
35 hibernatefile        /var/vm/sleepimage
36 highstandbythreshold 50
37 displaysleep         10
38 womp                 1
39 networkoversleep     0
40 sleep                10
41 tcpkeepalive         1
42 halfdim              1
43 acwake               0
44 disksleep            10

要修改Mac的休眠相关配置,需要用到pmset命令,其中与休眠相关的几个关键参数有:hibernatemode,standby,highstandbythreshold,standbydelayhigh,standbydelaylow。有关这几个参数的具体含义与用途,首先看一下man帮助中的描述。

1.1 SAFE SLEEP ARGUMENTS

hibernatemode supports values of 0, 3, or 25. Whether or not a hibernation image gets written is also dependent on the values of standby and autopoweroff

For example, on desktops that support standby a hibernation image will be written after the specified standbydelay time. To disable hibernation images completely, ensure hibernatemode standby and autopoweroff are all set to 0.

hibernatemode = 0 by default on desktops. The system will not back memory up to persistent storage. The system must wake from the contents of memory; the system will lose context on power loss. This is, historically, plain old sleep.

hibernatemode = 3 by default on portables. The system will store a copy of memory to persistent storage (the disk), and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from hibernate image.

hibernatemode = 25 is only settable via pmset. The system will store a copy of memory to persistent storage (the disk), and will remove power to memory. The system will restore from disk image. If you want “hibernation” - slower sleeps, slower wakes, and better battery life, you should use this setting.

Please note that hibernatefile may only point to a file located on the root volume.

1.2 STANDBY ARGUMENTS

standby causes kernel power management to automatically hibernate a machine after it has slept for a specified time period. This saves power while asleep. This setting defaults to ON for supported hardware. The setting standby will be visible in pmset -g if the feature is supported on this machine.

standbydelayhigh and standbydelaylow specify the delay, in seconds, before writing the hibernation image to disk and powering off memory for Standby. standbydelayhigh is used when the remaining battery capacity is above highstandbythreshold , and standbydelaylow is used when the remaining battery capacity is below highstandbythreshold.

highstandbythreshold has a default value of 50 percent.

autopoweroff is enabled by default on supported platforms as an implementation of Lot 6 to the European Energy- related Products Directive. After sleeping for seconds, the system will write a hibernation image and go into a lower power chipset sleep. Wakeups from this state will take longer than wakeups from regular sleep.

autopoweroffdelay specifies the delay, in seconds, before entering autopoweroff mode.

2. 解释

根据官方文档,我们可以总结一下:

macOS 默认的睡眠,会关闭屏幕,但会维持对内存(RAM)的供电。这样一来,一旦打开盖子,macOS 就能立即恢复。若是电池电量低于某个预设阈值,则会将内存中的数据转储到硬盘,而后彻底断电。

对应的,macOS 的睡眠有两种状态:

  • 不断电,数据存储在内存中,可以快速恢复。我们称这种状态为睡眠(Sleep);
  • 断电,数据存储在硬盘中,恢复得较慢。我们称这种状态为休眠(Hibernate/Stand-by)。

睡眠和休眠可以组合出三种模式,由 hibernatemode 控制

  • hibernatemode = 0,这是桌面设备的默认值。系统只睡眠,不休眠,不将数据存储在硬盘中;
  • hibernatemode = 3,这是移动设备的默认值。系统默认睡眠,在一定时间后或电量低于阈值将数据存储在硬盘中,而后休眠。这是所谓的安全睡眠(Safe-Sleep);
  • hibernatemode = 25。只休眠,不睡眠。这种模式只能通过pmset进行设置。

无论是安全睡眠模式还是休眠模式,从磁盘上恢复时,都会需要一定的时间屏幕才会被点亮。

对于安全睡眠模式,又有几个参数可以来进行微调:

  • 当剩余电量大于 highstandbythreshold(默认 50%)时,在 standbydelayhigh 秒(默认 86,400,即一整天)后进入休眠。
  • 当剩余电量小于 highstandbythreshold 时,在 standbydelaylow 秒(默认 10,800,即三小时)后进入休眠。

3. 修改一下

我们来实际操作一下:

 1# 使用-b限定只修改电池供电的情况下的配置,因为晚上睡眠的时候不插电源
 2# hibernatemode设置为安全睡眠模式
 3pmset -b hibernatemode 3
 4# 电量阈值设置为95%
 5pmset -b highstandbythreshold 95
 6# 电量超过95%的时候休眠前等待30分钟
 7pmset -b standbydelayhigh 1800
 8# 电量低于95%的时候休眠前等待10分钟
 9pmset -b standbydelaylow  600
10# 自动断电时间限定为30分钟
11pmset -b autopoweroffdelay 1800
#Mac#
使用Python写一个Alfred Workflow
使用KeepAlived配置Nginx高可用
  • 文章目录
  • 站点概览
Orchidflower

Orchidflower

Do one thing at a time, and do well.

77 日志
6 分类
84 标签
GitHub 知乎 OSC 豆瓣
  • 1. pmset及参数介绍
    • 1.1 SAFE SLEEP ARGUMENTS
    • 1.2 STANDBY ARGUMENTS
  • 2. 解释
  • 3. 修改一下
© 2009 - 2024 执子之手
Powered by - Hugo v0.113.0
Theme by - NexT
ICP - 鲁ICP备17006463号-1
0%