2.9 KiB
2.9 KiB
title, type, tags
| title | type | tags | |||
|---|---|---|---|---|---|
| 系统睡眠管理 | concept |
|
系统睡眠管理
系统睡眠管理(Sytem Sleep Management)是操作系统在用户空闲时降低功耗的机制,包含多个层级的电源状态。服务器场景下通常需要禁用这些行为以确保持续可用性。
睡眠层级对比
| 层级 | macOS (pmset) | Linux (systemd-logind) | Windows |
|---|---|---|---|
| 显示器睡眠 | displaysleep | — | 显示器睡眠 |
| 系统空闲睡眠 | sleep | suspend | 睡眠 (S3) |
| 待机(延迟睡眠) | standby | suspend + timer | 睡眠 |
| 休眠(断电保存) | hibernatemode | hibernate | 休眠 (S4) |
| 混合睡眠 | — | hybrid-sleep | 混合睡眠 |
| 深度休眠 | — | suspend-then-hibernate | 快速启动 |
macOS 睡眠管理
工具:pmset
| 参数 | 说明 |
|---|---|
sleep |
系统空闲时进入睡眠(S3) |
displaysleep |
显示器进入低功耗 |
standby |
进入完全睡眠前的定时器(默认1小时) |
hibernatemode |
内存内容写入磁盘后断电(S4) |
Home Server 配置:
sudo pmset -a sleep 0 displaysleep 0 standby 0 hibernatemode 0
Linux 睡眠管理
工具:systemd-logind + /etc/systemd/logind.conf
| 参数 | 说明 |
|---|---|
HandleLidSwitch |
合盖时动作(ignore/suspend/hibernate/lock) |
AllowSuspend |
是否允许 suspend |
AllowHibernate |
是否允许 hibernate |
进阶禁用:
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
服务器场景的特殊性
- 零物理交互:无显示器/键盘,无法手动唤醒
- 网络可用性要求:持续可远程访问
- 功耗容忍度:始终接电,不依赖电池
- 远程唤醒需求:关机状态也需要 WoL 支持
跨平台对比
| 维度 | macOS | Ubuntu/Linux | 对应关系 |
|---|---|---|---|
| 基础禁用命令 | pmset -a sleep 0 |
HandleLidSwitch=ignore |
sleep=HandleLidSwitch |
| 显示器睡眠 | pmset -a displaysleep 0 |
N/A(无显示器概念) | 无直接对应 |
| 待机定时器 | pmset -a standby 0 |
systemd-inhibit | 后台锁定机制 |
| 休眠模式 | pmset -a hibernatemode 0 |
systemctl mask hibernate.target |
S4=hibernate |
| 网络唤醒 | pmset -a womp 1 |
ethtool wol g | 硬件+软件配合 |
相关概念
- pmset — macOS 睡眠管理工具
- caffeinate — macOS 临时防止睡眠
- Wake-on-LAN — 配合睡眠管理的远程唤醒
- systemd-logind — Linux 电源管理核心
- HandleLidSwitch — Linux 合盖动作配置
- 休眠目标 — Linux systemd 睡眠目标管理
相关实体
- Mac Mini M4 — macOS 系统睡眠管理的典型应用场景
- Ubuntu Server — Linux 系统睡眠管理的典型应用场景