Linux系统挂起-恢复后解决缓慢问题
偶尔,当我将Linux笔记本电脑(睡眠模式)挂起后,稍后再恢复工作,机器会变得缓慢。每次我切换应用程序时,都会出现可感知的延迟,滚动会中断,文本编辑会延迟。像htop和iotop这样的监控工具没有显示出系统资源处于重负载状态。我关闭了所有应用程序,但缓慢的问题仍然存在。
显然这是一个CPU频率被锁定在非常低水平的错误。Linux使用CPU频率调整来节省电力;当机器恢复时,它应该开始增加CPU频率以满足系统的需求,但它并不总是这样做。重启可以解决这个问题,但谁有时间这样做呢?好消息是,使用cpupower
工具可以轻松解决这个问题。
获取cpupower工具
您可能已经安装了cpupower
,如果没有,可以通过包管理器轻松获取。在Ubuntu上,cpupower是linux-tools-common
包的一部分。您可以在终端中使用以下命令安装它
$ sudo apt-get install linux-tools-common
在基于RHEL的发行版(如Fedora和CentOS)上,cpupower
包含在kernel-tools
包中。在CentOS和较老的Fedoras上,您可以使用以下命令安装它
$ sudo yum install kernel-tools
在较新的Fedoras上,您可以使用dnf
来安装它
$ sudo dnf install kernel-tools
切换回性能模式
现代Intel CPU的CPU频率调整由intel_pstate驱动程序提供。它支持两种操作模式(称为“governors”):性能和省电。性能模式不一定是“火力全开”的性能。同样,省电模式也不会损害您的系统。两者都是智能governors,通过调整CPU频率响应系统负载。我发现切换governors可以立即解决我的系统缓慢问题。
要确认哪些governors可用,我使用cpupower
$ cpupower frequency-info --governors
analyzing CPU 0:
performance powersave
在这里,您可以看到我的系统打印出预期的“性能”和“省电”。要切换到性能governor,我可以使用以下命令
$ sudo cpupower frequency-set --governor performance
Setting cpu: 0
Setting cpu: 1
Setting cpu: 2
Setting cpu: 3
frequency-info
子命令将显示哪个governor是活动的
$ cpupower frequency-info
analyzing CPU 0:
driver: intel_pstate
CPUs which run at the same hardware frequency: 0
CPUs which need to have their frequency coordinated by software: 0
maximum transition latency: 0.97 ms.
hardware limits: 500 MHz - 2.70 GHz
available cpufreq governors: performance, powersave
current policy: frequency should be within 500 MHz and 2.70 GHz.
The governor "performance" may decide which speed to use
within this range.
current CPU frequency is 2.28 GHz.
boost state support:
Supported: yes
Active: yes
“当前策略”部分描述了活动的governor,在我的情况下显示性能governor是活动的。
cpupower资源
Redhat Linux文档包括一个关于CPU频率设置的指南,其中包含有关加载附加驱动程序的说明。Arch Linux CPU频率调整文档包含大量有用信息,包括哪些文件控制频率设置。
cpupower
手册页相当简略。一旦安装了cpupower
,尝试运行help
命令以开始
$ cpupower help
Usage: cpupower [-d|--debug] [-c|--cpu cpulist ] <command> [<args>]
Supported commands are:
frequency-info
frequency-set
idle-info
idle-set
set
info
monitor
help
Not all commands can make use of the -c cpulist option.
Use 'cpupower help <command>' for getting help for above commands.
本文最初发布在PerlTricks.com。
标签
反馈
这篇文章有什么问题吗?通过在GitHub上打开一个问题或拉取请求来帮助我们。