How to use, monitor, and disable transparent hugepages in Red Hat Enterprise Linux 6
Resolution
Note: Transparent Huge Pages are not available on the 32-bit version of RHEL 6.
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:
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:
# grep AnonHugePages /proc/meminfo
AnonHugePages: 632832 kB
Note: Red Hat Enterprise Linux 6.2 or later publishes additional THP monitoring via /proc/vmstat
:
# 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:
# 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
:
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:
# echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
# echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag
- NOTE: Running the above commands will stop only creation and usage of the new THP. The THP which were created and used at the moment the above commands were run would not be disassembled into the regular memory pages. To get rid of THP completely the system should be rebooted with THP disabled at boot time.
- NOTE: Some third party application install scripts check value of above files and complain even if THP is disabled at boot time using
transparent_hugepage=never
, this is due to the fact when THP is disabled at boot time, the value of/sys/kernel/mm/redhat_transparent_hugepage/defrag
will not be changed, however this is expected and system will never go in THP defragmentation code path when it is disabled at boot and THP defrag need not to be disabled separately.
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 Tranparent Huge Pages which are allocated automatically by the kernel. See below on how to tell if Explicit HugePages is enabled or disabled.
Explicit HugePages DISABLED:
If the value of
HugePages_Total
is "0" it means HugePages is disabled on the system.# grep -i HugePages_Total /proc/meminfo
HugePages_Total: 0
Similarly, if the value in
/proc/sys/vm/nr_hugepages
file orvm.nr_hugepages
sysctl parameter is "0" it means HugePages is disabled on the system:# cat /proc/sys/vm/nr_hugepages
0
# sysctl vm.nr_hugepages
vm.nr_hugepages = 0
Explicit HugePages ENABLED:
If the value of
HugePages_Total
is greater than "0", it means HugePages is enabled on the system:# grep -i HugePages_Total /proc/meminfo
HugePages_Total: 1024
Similarly if the value in
/proc/sys/vm/nr_hugepages
file orvm.nr_hugepages
sysctl parameter is greater than "0", it means HugePages is enabled on the system:# cat /proc/sys/vm/nr_hugepages
1024
# sysctl vm.nr_hugepages
vm.nr_hugepages = 1024
Comments
- RHEL 6 disables THP on systems with < 1G of ram. Refer to Red Hat Bug 618444 - disable transparent hugepages by default on small systemsfor more information.
- Disadvantages of using the explicit hugepages (libhugetlbfs): Using hugetlbfs requires significant work from both application developers and system administrators; explicit hugepages must be set aside at boot time, and applications must map them explicitly. The process is fiddly enough that use of hugetlbfs is restricted to those who really care and who have the time to mess with it. Hugetlbfs is often seen as a feature for large, proprietary database management systems and little else.
References:
- Transparent huge pages in 2.6.38
- Documentation/vm/transhuge.txt
- Andrea Arcangeli's presentation "Transparent Hugepage Support" : KVM Forum 2010 - Presentations
How to use, monitor, and disable transparent hugepages in Red Hat Enterprise Linux 6的更多相关文章
- How to disable transparent hugepages (THP) on Red Hat Enterprise Linux 7
How to disable transparent hugepages (THP) on Red Hat Enterprise Linux 7 $ Solution 已验证 - 已更新2017年六月 ...
- Disable or enable the IPv6 protocol in Red Hat Enterprise Linux
Resolution Red Hat Enterprise Linux 4, 5 and 6 enable Internet Protocol Version 6 (IPv6) by default. ...
- Linux 关于Transparent Hugepages的介绍
透明大页介绍 Transparent Huge Pages的一些官方介绍资料: Transparent Huge Pages (THP) are enabled by default in RHEL ...
- THP Transparent HugePages 相关知识与关闭
近期遇到个LINUX系统内存比較大.未开 HugePages,业务有变化导致ORACLE连接数剧增至上千个,PageTables达到上百G.导致内存不足系统HANG住的案例. 因此须要开启 HugeP ...
- Linux 关于Transparent Hugepages的介绍【转】
透明大页介绍 Transparent Huge Pages的一些官方介绍资料: Transparent Huge Pages (THP) are enabled by default in RHEL ...
- THP Transparent HugePages 相关知识与关闭【转】
最近遇到个LINUX系统内存比较大,未开 HugePages,业务有变化导致ORACLE连接数剧增至上千个,PageTables达到上百G,导致内存不足系统HANG住的案例. 因此需要开启 HugeP ...
- Transparent HugePages(透明大页)
Transparent HugePages(透明大页) 1. 介绍 从RedHat6, RedHat7, OL6, OL7 SLES11 and UEK2 kernels开始,透明大页默认是被开启的以 ...
- THP Transparent HugePages关闭
ambari 安装Hortonworks HDP 时在检测host异常 The following hosts have Transparent Huge Pages (THP) enabled.TH ...
- HugePages概述--翻译自19C文档
翻译自: https://docs.oracle.com/en/database/oracle/oracle-database/19/unxar/administering-oracle-databa ...
随机推荐
- PHP 7中利用OpenSSL代替Mcrypt加解密的方法详解
php7.1发布后新特性吸引了不少PHPer,大家都在讨论新特性带来的好处与便利.但是从php7.0 升级到 php7.1 废弃(过时)了一个在过去普遍应用的扩展(mcrypt扩展).官方提供了相应的 ...
- centos6安装ElasticSearch5.6.5错误记录
在centos6安装ES的时候遇到不少问题.这里记录日志.以后安装一定要升级centos7,别说啥稳定问题了,该升级就升级. [1]: max file descriptors [4096] for ...
- 【R】函数-统计函数
- Grid 拾遗
*.GridSplitter属性是Grid面板的一个特性.(1)预留一行或一列,专门用于放置 GridSplitter对象,如果是行的话,把其Height 设置为 Auto,如果是列的话,把其 Wid ...
- OpenNebula学习第四节之磁盘镜像的制作
一.准备工作 需要准备一个Ubuntu16.04的ISO文件上传至服务器,如下图所示 二.操作步骤 2.1:创建操作目录 创建一个/var/tmp/cloud_image目录,把Ubuntu16.04 ...
- Linux上传和下载之Xshell
一.安装与授权 安装时候需要注意的是,选择 Free For Home/School选项进行安装,如下图所示安装成功后 二.上传 上传需要使用rz命令,如下图所示,第一次可能会提示你命令无效或者提示你 ...
- Discuz! X3安装第三方主题出现:对不起,您安装的不是正版应用..的解决方法
discuz 社区在更新到3.0以上后,增加了对插件的版本检测,在安装时,可能会出现:“对不起,您安装的不是正版应用,安装程序无法继续执行”的提示,要解决这个其实挺容易的,找到以下文件: /sourc ...
- struts笔记
Struts视频笔记: Struts是一个开源的web框架,框架提高了程序的规范的同时也约束了程序员的自由 为什么会有struts: 因为我们队mvc理解的不同,可能造成不同公司写程序的时候,规范不统 ...
- SDE注册版本失败,仅支持一个空间列
如果直接编辑SDE要素类与要素可以不需要版本,使用默认版本,如果要让用户通过界面编辑,即使用开启编辑.保存编辑和停止编辑,就需要注册为版本,而在注册版本弹出如下错误: 正如错误所说,一个要素类或shp ...
- ASP.NET匿名对象与集合的使用
一.关于匿名类型的特性 1.匿名类型 定义:匿名对象 var vobj = new { id = "编号", title = "标题", content = & ...