Files
nexus/wiki/concepts/系统睡眠管理.md

83 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "系统睡眠管理"
type: concept
tags: [操作系统, 电源管理, 服务器运维]
---
# 系统睡眠管理
> 系统睡眠管理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 配置:
```bash
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 |
进阶禁用:
```bash
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
```
## 服务器场景的特殊性
1. **零物理交互**:无显示器/键盘,无法手动唤醒
2. **网络可用性要求**:持续可远程访问
3. **功耗容忍度**:始终接电,不依赖电池
4. **远程唤醒需求**:关机状态也需要 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 系统睡眠管理的典型应用场景