Linux关于透明大页机制的介绍
透明大页介绍
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.
查看是否启用透明大页
1:命令cat /sys/kernel/mm/redhat_transparent_hugepage/enabled 该命令适用于red hat enterprise linux系统
2:命令cat /sys/kernel/mm/transparent_hugepage/enabled 该命令适用于其它linux系统
使用命令查看时,如果输出结果为[always]表示透明大页启用了。[never]表示透明大页禁用、[madvise]表示(只在madv_hugepage标志的vma中使用thp
3:如何hugepages_total返回0,也意味着标准大页禁用了(注意传统/标准大页和透明大页的区别)
透明大页(thp)管理和标准/传统大页(hp)管理都是操作系统为了减少页表转换消耗的资源而发布的新特性,虽然oracle建议利用大页机制来提高数据库的性能,但是oracle却同时建议关闭透明大页管理。这二者的区别在于大页的分配机制,标准大页管理是预分配的方式,而透明大页管理则是动态分配的方式。
4:cat /proc/sys/vm/nr_hugepages返回0也意味着传统大页禁用了(传统大页和透明大页)。
禁用、启用透明大页功能
方法1:设置/etc/grub.conf文件,在系统启动是禁用。
方法2:设置/etc/rc.local文件
使用上面的配置后必须重启操作系统才能生效,你也可以运行下面命令不用重启操作系统。
you must reboot your system for the setting to take effect, or run the following two echo lines to proceed with the install without rebooting:
小知识点:
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时也必须关闭透明大页功能。
到此这篇关于linux关于透明大页机制的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持。