验证是否启用了 THP
CentOS/RHEL 7 上的“tuned.service”默认将 transparent_hugepage 设置为 always。
即使在 grub 内核命令行中禁用它,调整后的服务也会在启动期间将其设置为“始终”。
下面的命令输出确认系统上已启用 THP。
# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never
注意:无法在正在运行的机器上启用/禁用透明大页面,需要重新启动。
查看更多教程 https://on itroad.com
禁用 THP 的步骤
- 在grub2配置文件中添加“transparent_hugepage=never”内核参数选项。
在 /etc/default/grub 文件中的 GRUB_CMDLINE_LINUX 选项上添加或者更改“transparent_hugepage=never”内核参数。
# vi /etc/default/grub GRUB_TIMEOUT=5 GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="nomodeset crashkernel=auto rd.lvm.lv=vg_os/lv_root rd.lvm.lv=vg_os/lv_swap rhgb quiet transparent_hugepage=never" GRUB_DISABLE_RECOVERY="true"
- 通过运行 grub2-mkconfig -o 命令重建 /boot/grub2/grub.cfg 文件。
在重建 GRUB2 配置文件之前,请确保备份现有的 /boot/grub2/grub.cfg。
在基于 BIOS 的机器上
# grub2-mkconfig -o /boot/grub2/grub.cfg
在基于 UEFI 的机器上
# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
- 重新启动系统并验证选项是否有效。
# shutdown -r now
- 验证参数设置是否正确
# cat /proc/cmdline BOOT_IMAGE=/vmlinuz-3.10.0-514.10.2.el7.x86_64 root=/dev/mapper/vg_os-lv_root ro nomodeset crashkernel=auto rd.lvm.lv=vg_os/lv_root rd.lvm.lv=vg_os/lv_swap rhgb quiet transparent_hugepage=never LANG=en_US.UTF-8
故障排除
如果透明大页面 (THP) 仍未禁用,请继续并使用以下选项之一。
禁用tuned服务
如果使用以下任一命令重新启用 THP,请禁用调tuned服务。
# systemctl stop tuned # systemctl disable tuned
或者
# tuned-adm off
创建一个禁用 THP 的自定义调整配置文件
- 另一种推荐的方法是在禁用 THP 的情况下创建自定义的调整配置文件。
找出哪个配置文件处于活动状态,创建一个副本。
在以下示例中,我们目前使用吞吐量性能配置文件:
# tuned-adm active Current active profile: throughput-performance
- 要创建自定义配置文件,请在 /etc/tuned 目录中创建一个具有所需配置文件名称的新目录。
# mkdir /etc/tuned/nothp_profile
- 然后为 nothp_profile 创建一个新的tuned.conf 文件,并插入新的调优信息:
# cat /etc/tuned/nothp_profile/tuned.conf [main] include= throughput-performance [vm] transparent_hugepages=never
- 使脚本可执行。
# chmod +x /etc/tuned/nothp_profile/tuned.conf
- 使用tuned-adm 命令启用nothp_profile。
# tuned-adm profile nothp_profile
- 此更改将立即生效并持续重启。
验证
要验证 THP 是否已禁用,请运行以下命令:
# cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never]
显式大页面(Explicit Huge Pages) VS 透明大页面(Transparent Huge Pages)
系统中可以有两种类型的 HugePages:通过 vm.nr_hugepages sysctl 参数显式分配的显式巨型页面和由内核自动分配的透明巨型页面。
日期:2020-09-17 00:12:03 来源:oir作者:oir