在Intel处理器上,修改mitigations参数使Linux系统运行得更快

您可能听说过影响了许多现代处理器,包括英特尔,AMD,System Z,Power和ARM的某些处理器。幸运的是,内核开发人员已经发布了安全补丁来解决Meltdown/Spectre问题,在最新的内核版本中,默认情况下应用补丁。尽管安全补丁有助于缓解漏洞,但是它们也会影响系统的性能,如果您的系统受到了很好的保护,并且希望获得所有的性能,那么本指南非常适合您。本简要指南介绍了如何通过关闭Spectre和Meltdown缓解措施使Linux系统在Intel CPU上更快地运行。

警告 :
在实施以下解决方案之前,我必须警告你 - 这是高度不安全的,不建议这样做。这将禁用Intel CPU上的所有Spectre和Meltdown缓解措施,并使Linux系统对风险敞开大门。除非清楚地知道你在做什么,不要这样做。

如果您根本不关心安全性,请继续按照以下说明禁用缓解措施。

使Linux系统在Intel CPU上运行更快

使用你喜欢的文本编辑器编辑GRUB文件。

在Debian上,Ubuntu:


$ sudo nano /etc/default/grub

如果你使用的是Linux内核版本5.1.13及更新版本,请添加/编辑以下内核参数,如下所示:

GRUB_CMDLINE_LINUX="mitigations=off"

这将禁用所有可选的CPU缓解措施。

如果你使用的内核版本早于5.1.13,请添加/编辑以下内容:

GRUB_CMDLINE_LINUX="noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off tsx=on tsx_async_abort=off mitigations=off"

这些是内核参数,可用于禁用所有降低Linux系统速度的Spectre/Meltdown缓解措施。

有关每个标志的更多详细信息,请快速搜索google。

添加内核parameter之后,使用命令更新GRUB配置:

$ sudo update-grub

最后,重新启动系统:

$ sudo reboot

在CentOS和RHEL这样的RPM-based系统上,编辑/etc/sysconfig/grub文件:

$ sudo /etc/sysconfig/grub

在GRUB_CMDLINE_LINUX中添加上面的参数,然后使用命令更新GRUB配置:

$ sudo grub2-mkconfig

最后重新启动:

$ sudo reboot

在一些Linux系统中,需要在"GRUB_CMDLINE_LINUX_DEFAULT ="中添加这些内核参数。

我们现在已禁用所有"Spectre"和"Meltdown"缓解措施。这会稍微提高系统的性能,但也可能使用户面临多个CPU漏洞。

检查Spectre/Meltdown mitigations是否被禁用
我们可以使用"spectre-meltdown-checker"工具来帮助你识别Linux中的specre和missdown漏洞,在一些Linux发行版的官方存储库中可以找到它。

在Debian上,Ubuntu:

$ sudo apt install spectre-meltdown-checker

在CentOS上,RHEL:

$ sudo yum install epel-release
$ sudo yum install spectre-meltdown-checker

在Fedora上:

$ sudo dnf install $ sudo apt install spectre-meltdown-checker

安装spectre-meltdown-checker后,以root用户身份或以sudo权限运行它,以检查是否关闭了Spectre和Meltdown:

你应该看到如下所示的消息。

[...]
> STATUS: VULNERABLE (Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers)
[...]
> STATUS: VULNERABLE (IBRS+IBPB or retpoline+IBPB is needed to mitigate the vulnerability)
[...]
> STATUS: VULNERABLE (PTI is needed to mitigate the vulnerability)

或者,你可以检查Spectre/Meltdown漏洞,如下所示。

$ ls /sys/devices/system/cpu/vulnerabilities/

示例输出:

itlb_multihit l1tf mds meltdown spec_store_bypass spectre_v1 spectre_v2 tsx_async_abort

还有

$ grep . /sys/devices/system/cpu/vulnerabilities/*

示例输出:

/sys/devices/system/cpu/vulnerabilities/itlb_multihit:KVM: Vulnerable
/sys/devices/system/cpu/vulnerabilities/l1tf:Mitigation: PTE Inversion
/sys/devices/system/cpu/vulnerabilities/mds:Vulnerable; SMT Host state unknown
/sys/devices/system/cpu/vulnerabilities/meltdown:Vulnerable
/sys/devices/system/cpu/vulnerabilities/spec_store_bypass:Vulnerable
/sys/devices/system/cpu/vulnerabilities/spectre_v1:Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers
/sys/devices/system/cpu/vulnerabilities/spectre_v2:Vulnerable, STIBP: disabled
/sys/devices/system/cpu/vulnerabilities/tsx_async_abort:Not affected

运行一些基准测试,并检查你将获得的性能,然后决定是否有必要禁用所有功能。

我已经警告过:对于家庭或单用户计算机,此技巧是一个有用且明智的选择。但不建议用于生产系统。

参考:
在Intel CPU上,如何使Linux系统运行得更快
导致Linux 4.20性能下降的STIBP已被Kernel 4.19系列内核移除

### Linux Kernel 5.4.34 Information The Linux kernel version 5.4.34 is a stable release that includes numerous improvements, bug fixes, and security patches over previous versions within the 5.x series[^1]. This particular iteration focuses on enhancing stability while addressing critical issues identified since the initial rollout of this long-term support (LTS) branch. #### Release Notes Highlights Key updates introduced in Linux kernel 5.4.34 encompass: - Enhanced driver compatibility for various hardware components. - Performance optimizations across multiple subsystems including networking stack enhancements. - Security vulnerability mitigations ensuring safer operations against potential threats. - Miscellaneous bug corrections impacting overall reliability and user experience positively. For detailed technical changes, one can refer to the official changelog provided by maintainers which documents each modification meticulously from commit messages submitted during development cycles leading up to final compilation into an officially supported build. #### Download Instructions To obtain the source code package associated with Linux kernel 5.4.34 directly from canonical repositories or mirrors maintained globally, users may follow these instructions tailored specifically towards acquiring verified archives suitable for compiling custom kernels as well as applying necessary configurations according to individual requirements: ```bash wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.4.34.tar.xz tar -xf linux-5.4.34.tar.xz cd linux-5.4.34/ make menuconfig # Customize configuration options here if needed before proceeding further ``` After preparing desired settings through `menuconfig`, continue building process using preferred methods documented extensively elsewhere regarding best practices when dealing with low-level operating system constructs like those found inside modern Unix-like environments such as GNU/Linux distributions today.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值