Red Hat Enterprise Linux 6 7关闭透明大页面及透明大页面基础概念

发布时间:2020-08-04 19:02:20 作者:你好我是李白
来源:ITPUB博客 阅读:349

https://access.redhat.com/solutions/46111

环境

问题

决议

Note:
Transparent Huge Pages are  not available on the 32-bit version of RHEL 6.
For RHEL 7 see  How to disable transparent hugepages (THP) on Red Hat Enterprise Linux 7
For RHEL 8 see  How to disable transparent hugepages (THP) on Red Hat Enterprise Linux 8

Transparent Huge Pages (THP) are enabled by default in RHEL 6 for  all applications. The kernel attempts to allocate hugepages whenever possible and any Linux process will receive 2MB pages if the mmap region is 2MB naturally aligned. The main kernel address space itself is mapped with hugepages, reducing TLB pressure from kernel code. For general information on Hugepages, see:  What are Huge Pages and what are the advantages of using them?

The kernel will always attempt to satisfy a memory allocation using hugepages. If no hugepages are available (due to non availability of physically continuous memory for example) the kernel will fall back to the regular 4KB pages. THP are also swappable (unlike hugetlbfs). This is achieved by breaking the huge page to smaller 4KB pages, which are then swapped out normally.

But to use hugepages effectively, the kernel must find physically continuous areas of memory big enough to satisfy the request, and also properly aligned. For this, a  khugepaged kernel thread has been added. This thread will occasionally attempt to substitute smaller pages being used currently with a hugepage allocation, thus maximizing THP usage.

In userland, no modifications to the applications are necessary (hence transparent). But there are ways to optimize its use. For applications that want to use hugepages, use of  posix_memalign() can also help ensure that large allocations are aligned to huge page (2MB) boundaries.

Also, THP is only enabled for anonymous memory regions. There are plans to add support for tmpfs and page cache. THP tunables are found in the  /sys tree under  /sys/kernel/mm/redhat_transparent_hugepage.

The values for  /sys/kernel/mm/redhat_transparent_hugepage/enabled can be one of the following:

Raw
always   -  always use THP
never    -  disable THP

khugepaged will be automatically started when  transparent_hugepage/enabled is set to "always" or "madvise, and it'll be automatically shutdown if it's set to "never". The  redhat_transparent_hugepage/defrag parameter takes the same values and it controls whether the kernel should make aggressive use of memory compaction to make more hugepages available.

Check system-wide THP usage

Run the following command to check system-wide THP usage:

Raw
# grep AnonHugePages /proc/meminfo 
AnonHugePages:    632832 kB

Note: Red Hat Enterprise Linux 6.2 or later publishes additional THP monitoring via  /proc/vmstat:

Raw
# egrep 'trans|thp' /proc/vmstat
nr_anon_transparent_hugepages 2018
thp_fault_alloc 7302
thp_fault_fallback 0
thp_collapse_alloc 401
thp_collapse_alloc_failed 0
thp_split 21

Check THP usage per process

Run the following command to monitor which processes are using THP:

Raw
    # grep -e AnonHugePages  /proc/*/smaps | awk  '{ if($2>4) print $0} ' |  awk -F "/"  '{print $0; system("ps -fp " $3)} '
/proc/7519/smaps:AnonHugePages:    305152 kB
UID        PID  PPID  C STIME TTY          TIME CMD
qemu      7519     1  1 08:53 ?        00:00:48 /usr/bin/qemu-system-x86_64 -machine accel=kvm -name rhel7 -S -machine pc-i440fx-1.6,accel=kvm,usb=of
/proc/7610/smaps:AnonHugePages:    491520 kB
UID        PID  PPID  C STIME TTY          TIME CMD
qemu      7610     1  2 08:53 ?        00:01:30 /usr/bin/qemu-system-x86_64 -machine accel=kvm -name util6vm -S -machine pc-i440fx-1.6,accel=kvm,usb=
/proc/7788/smaps:AnonHugePages:    389120 kB
UID        PID  PPID  C STIME TTY          TIME CMD
qemu      7788     1  1 08:54 ?        00:00:55 /usr/bin/qemu-system-x86_64 -machine accel=kvm -name rhel64eus -S -machine pc-i440fx-1.6,accel=kvm,us

To disable THP at boot time

Append the following to the kernel command line in  grub.conf:

Raw
transparent_hugepage=never

Note: Certain ktune and/or tuned profiles specify to enable THP when they are applied. If the  transparent_hugepage=never parameter is set at boot time, but THP does not appear to be disabled after the system is fully booted. Refer to the following article:

Disabling transparent hugepages (THP) on Red Hat Enterprise Linux 6 is not taking effect

To disable THP at run time

Run the following commands to disable THP on-the-fly:

Raw
# echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
# echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag

How to tell if Explicit HugePages is enabled or disabled

There can be two types of HugePages in the system: Explicit Huge Pages which are allocated explicitly by  vm.nr_hugepages sysctl parameter and Transparent Huge Pages which are allocated automatically by the kernel. See below on how to tell if Explicit HugePages is enabled or disabled.

Comments
推荐阅读:
  1. Red Hat 7 vncserver如何配置
  2. aws中Red Hat Enterprise Linux 7.3安装图形界面以及mac下的VNC连接

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

enterprise hat linux

上一篇:PHP数组处理函数举例

下一篇:阿里P8架构师谈:淘宝技术架构从1.0到4.0的架构变迁!附架构资料

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》