良玉的博客 点点滴滴,积水成河_良玉的博客_页游、手游linux运维工程师之路

Transparent Hugepages 透明大页

Transparent Huge Pages的一些官方介绍资料:

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.


在linux2.6.38之前,处理大容量内存工作集的高性能关键计算应用是运行在libhugetlbfs之上,必须依赖于
hugetlbfs,。透明Hugepage支持是一种替代手段,它使用大内存页,并且虚拟内存页的大小可以动态变化,没有hugetlbfs的缺点。
目前只适用于匿名内存映射,但未来可以扩展到tmpfs的papecache层。
大内存页的优点:
巨大的页面可以通过减少缺页提升性能(一次缺页分配大块的内存),还可以通过减少虚拟地址到物理地址的转换成本(减少转化次数),甚至可以避免地址转换。如果处理器必须转换一个虚拟地址,它必须通过多达四层页表。处理器保持一个“翻译后备缓冲器(TLB)的缓存的转换结果。TLB的容量很小,一般是128条指令转换、32条数据转换。非常容易被填满,从而必须进行大量的地址转换。例如:2m的页大小只需要一个tlb项,而4k的页大小就需要512个tlb项。通过内核地址使用大内存页,可以减少tlb的压力。
基于以上原因,使用大内存页的程序会运行的很快。
hugetlbfs 缺点:
(1)巨页必须在内核启动时刻进行设置,并且需要应用程序显示映射。
(2)更倾向于大的专有数据库管理系统


# cat /sys/kernel/mm/transparent_hugepage/enabled 

[always] madvise never


查看透明大页的状态

输出结果为[always]表示透明大页启用了。[never]表示透明大页禁用


# grep -i HugePages_Total /proc/meminfo

HugePages_Total: 0

返回0,也意味着透明大页禁用了


cat /proc/sys/vm/nr_hugepages返回0也意味着透明大页禁用了。


通常禁用使用echo来完成:

# echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
[root@getlnx06 ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
always madvise [never]




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

 

2:Transparent Huge Pages在32位的RHEL 6中是不支持的。

Transparent Huge Pages are not available on the 32-bit version of RHEL 6.

 

3: ORACLE官方不建议我们使用RedHat 6, OEL 6, SLES 11 and UEK2 kernels 时的开启透明大页(Transparent HugePages ), 因为透明大页(Transparent HugePages ) 存在一些问题:

        1.在RAC环境下 透明大页(Transparent HugePages )会导致异常节点重启,和性能问题;

        2.在单机环境中,透明大页(Transparent HugePages ) 也会导致一些异常的性能问题;

Transparent HugePages memory is enabled by default with Red Hat Enterprise Linux 6, SUSE Linux Enterprise Server 11, and Oracle Linux 6 with earlier releases of Oracle Linux Unbreakable Enterprise Kernel 2 (UEK2) kernels. Transparent HugePages memory is disabled in later releases of Oracle Linux UEK2 kernels.Transparent HugePages can cause memory allocation delays during runtime. To avoid performance issues, Oracle recommends that you disable Transparent HugePages on all Oracle Database servers. Oracle recommends that you instead use standard HugePages for enhanced performance.Transparent HugePages memory differs from standard HugePages memory because the kernel khugepaged thread allocates memory dynamically during runtime. Standard HugePages memory is pre-allocated at startup, and does not change during runtime.

Starting with RedHat 6, OEL 6, SLES 11 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. Because 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.

 

4:安装Vertica Analytic Database时也必须关闭透明大页功能。


留言列表
发表评论
来宾的头像