1 Transparent Huge Pages 说明

官网上有2篇文章对THP 做了说明:

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

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/s-memory-transhuge.html

Starting with RedHat6, RedHat7, OL6, OL7 SLES11 and UEK2 kernels, Transparent HugePages are implemented and enabled (default) in an attempt to improve the memory management.  Transparent HugePages are similar to the HugePages that have been available in previous Linux releases.  The main difference is that the Transparent HugePages are set up dynamically at run time by the khugepaged thread in kernel while the regular HugePages had to be preallocated at the boot up time.

从RedHat 6, OEL 6, SLES 11 and UEK2 kernels 开始,系统缺省会启用 Transparent HugePages,用来提高内存管理的性能透明大页(Transparent HugePages ), THP 与Hugepages 类似,主要的区别是:Transparent HugePages 可以实时配置,不需要重启才能生效配置。

关于HugePages 参考如下链接:

Linux HugePages 配置与 Oracle 性能关系说明

http://www.cndba.cn/dave/article/310

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.

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.

2 查看与关闭THP

当以下文件里的值为always表示已经启用THP:

[root@www.cndba.cn ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
[always] madvise never
[root@www.cndba.cn ~]#
[root@www.cndba.cn ~]# grep AnonHugePages /proc/meminfo 
AnonHugePages:    348160 kB
只要这里的值大于0,即表示启用了THP。

在linux 6.2 之后可以通过如下命令来监控THP:

[root@www.cndba.cn ~]# egrep 'trans|thp' /proc/vmstat
nr_anon_transparent_hugepages 170
thp_fault_alloc 18566
thp_fault_fallback 110
thp_collapse_alloc 185
thp_collapse_alloc_failed 32
thp_split 221
[root@www.cndba.cn ~]#

查看哪些进程在使用THP:

[root@www.cndba.cn ~]# grep -e AnonHugePages  /proc/*/smaps | awk  '{ if($2>4) print $0} ' |  awk -F "/"  '{print $0; system("ps -fp " $3)} '
/proc/2645/smaps:AnonHugePages:      2048 kB
UID        PID  PPID  C STIME TTY          TIME CMD
grid      2645  2644  0 Oct25 ?        00:00:09 /u01/gridsoft/12.1.0/opmn/bin/ons -d
/proc/2780/smaps:AnonHugePages:     14336 kB
UID        PID  PPID  C STIME TTY          TIME CMD
root      2780     1  0 Oct25 ?        00:01:53 /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/java -Djava.util.logging.config.file=/www/t
/proc/2780/smaps:AnonHugePages:     14336 kB
UID        PID  PPID  C STIME TTY          TIME CMD
root      2780     1  0 Oct25 ?        00:01:53 /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/java -Djava.util.logging.config.file=/www/t
/proc/2780/smaps:AnonHugePages:     38912 kB
UID        PID  PPID  C STIME TTY          TIME CMD
root      2780     1  0 Oct25 ?        00:01:53 /usr/lib/jvm/java-1.7.0-openjdk.x86_64/bin/java -Djava.util.logging.config.file=/www/t
/proc/2780/smaps:AnonHugePages:      6144 kB
UID        PID  PPID  C STIME TTY          TIME CMD

在OS启动时禁用THP:

在grub.conf 文件中添加:transparent_hugepage=never。 这种方法在修改后需要重启OS才能生效。

[root@www.cndba.cn ~]# cat  /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,1)
#          kernel /vmlinuz-version ro root=/dev/sda4
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda1
device (hd0) HD(1,800,3e8000,ad383463-7239-443a-83c6-7b8c6539a458)
default=0
timeout=5
splashimage=(hd0,1)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-573.el6.x86_64)
root (hd0,1)
kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=UUID=65b6fe1a-6897-4a16-9cf6-e8dfcc89b7ce rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet transparent_hugepage=never
initrd /initramfs-2.6.32-573.el6.x86_64.img

在运行时禁用:

直接执行如下命令禁用THP,不需要重启OS。

[root@www.cndba.cn ~]# echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
[root@www.cndba.cn ~]# echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag
[root@www.cndba.cn ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
always madvise [never]

但这种方法在OS重启之后就会失效。

3 Oracle 与 THP 关系

根据MOS ID 1557478.1的说明。

Transparent HugePages are known to cause unexpected node reboots and performance problems with RAC, Oracle strongly advises to disable the use of Transparent HugePages. In addition, Transparent Hugepages may cause problems even in a single-instance database environment with unexpected performance problems or delays. As such, Oracle recommends disabling Transparent HugePages on all Database servers running Oracle.

The ocssd.log may show some of the threads are blocked (but this does not show all the time):

2013-05-01 14:30:45.255: [    CSSD][224204544]clssscMonitorThreads clssnmvKillBlockThread not scheduled for 7500 msecs

2013-05-01 14:30:46.945: [    CSSD][224204544]clssscMonitorThreads clssnmvWorkerThread not scheduled for 8030 msecs

因为THP 会导致节点重启,所以Oracle 强烈建议关闭THP。 具体关闭操作参考上节。

Linux Transparent Huge Pages 对 Oracle 的影响的更多相关文章

  1. Linux传统Huge Pages与Transparent Huge Pages再次学习总结

      Linux下的大页分为两种类型:标准大页(Huge Pages)和透明大页(Transparent Huge Pages).Huge Pages有时候也翻译成大页/标准大页/传统大页,它们都是Hu ...

  2. Examining Huge Pages or Transparent Huge Pages performance

    Posted by William Cohen on March 10, 2014 All modern processors use page-based mechanisms to transla ...

  3. redis启动后出现"WARNING you have Transparent Huge Pages (THP) support enabled in your kernel"问题

    问题描述:启动redis后出现:WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This w ...

  4. Linux中禁用THP(Transparent Huge Pages)

    一.简介 Centos6开始引入THP,Centos7时默认启用,用来提升内存性能. 二.说明 争对一些数据库,如Oracle.MariaDB.MongoDB.VoltDB在使用时,要求关闭此功能. ...

  5. Transparent Huge Pages

    在RHEL6中,透明大页功能是默认开启的. 开启该选项后,内核会尽可能地尝试分配大页,如果mmap区域是2mb,那么每个linux进程都会分配到2mb大小的页.如果大页不够用了(比如物理内存不够了), ...

  6. WARNING you have Transparen Huge Pages..

    redis启动警告: WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will c ...

  7. 为 Python Server Pages 和 Oracle 构建快速 Web 开发环境。

    为 Python Server Pages 和 Oracle 构建快速 Web 开发环境. - 在水一方 - 博客频道 - CSDN.NET 为 Python Server Pages 和 Oracl ...

  8. 在 Oracle Linux 6.5 上安装 Oracle 11g 单实例数据库

    Checking the Hardware Requirements 系统必须满足下面最小的硬件要求 Memory Requirements Minimum: 1 GB of RAMRecommend ...

  9. Linux服务器磁盘扩展和oracle表空间文件迁移操作记录

    1.环境介绍 服务器硬件:Dell R710 服务器OS:红帽子Linux   RHEL4.8 数据库:Oracle 10g 2.出现的问题 因为数据表每天有上百万的数据写入表,加上建立索引,导致表空 ...

随机推荐

  1. html学习笔记(一)

    认识网页 网页组成 由文字.图片.输入框.视频.音频.超链接等组成. web标准 W3C组织(万维网联盟) Html (结构标准 ),相当人的身体. Css 样式(表现)标准 , 相当与给人化妆 变的 ...

  2. docker 使用compose安装zookeeper集群

    此基础镜像使用的为zookeeper的官方镜像 docker pull zookeeper 新建文件 docker-compose.yml version: ' services: zookeeper ...

  3. Java的commons包的简介

    Jakarta Commons是Jakarta的一个子项目,目的是创建和维护独立于其他框架和产品的程序包(packages).Jakarta Commons项目源于重用,其中的程序包必须确保能够重用. ...

  4. 远程桌面控制项目开发(Spring+Netty+Swing)

    [目录] 1.前言 2.初现端倪 3.款款深入 4.责任细分 5.功能层级图 6.项目结构 7.关键类设计 8.一些设计想法 9.待优化 10.一点心得 11.效果演示 12.讨论 13.GitHub ...

  5. 【转】SQL SERVER 日期格式化

    0   或   100   (*)     默认值   mon   dd   yyyy   hh:miAM(或   PM)       1   101   美国   mm/dd/yyyy       ...

  6. C#中深拷贝和浅拷贝

    一:概念 内存:用来存储程序信息的介质. 指针:指向一块内存区域,通过它可以访问该内存区域中储存的程序信息.(C#也是有指针的) 值类型:struct(整形.浮点型.decimal的内部实现都是str ...

  7. 通向全栈之路——(5)git通三端

    一.在私有git服务中新建一个项目(码云):将电脑上id_rsa.pub(git公钥)拷贝至ssh下面中保存二.本地代码关联git:1.git全局设置:git config --global user ...

  8. Unity3d嵌入web网页

    应用场景 程序中的界面风格 UI内容等相关内容需要很容易方便的跟新替换,不使用unity传统的热加载方式,也不想使用和H5等做混合APP的时候, 就用嵌入web来实现. 假如我想替换某个背景图,一般来 ...

  9. 彻底弄懂HTTP缓存机制及原理(转载)

    https://www.cnblogs.com/chenqf/p/6386163.html 前言 Http 缓存机制作为 web 性能优化的重要手段,对于从事 Web 开发的同学们来说,应该是知识体系 ...

  10. JS实现继承的几种方式以及优缺点(转载)

    前言 JS作为面向对象的弱类型语言,继承也是其非常强大的特性之一.那么如何在JS中实现继承呢?让我们拭目以待. JS继承的实现方式 既然要实现继承,那么首先我们得有一个父类,代码如下: // 定义一个 ...