您的位置:首页 > 教程 > linux > Linux关于透明大页机制的介绍

Linux关于透明大页机制的介绍

2022-06-20 14:44:44 来源:易采站长站 作者:

Linux关于透明大页机制的介绍

透明大页介绍TransparentHugePages的一些官方介绍资料:TransparentHugePages(THP)areenabledbydefaultinRHEL6...EfG站长之家-易采站长站-Easck.Com

透明大页介绍

Transparent Huge Pages的一些官方介绍资料:EfG站长之家-易采站长站-Easck.Com

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?EfG站长之家-易采站长站-Easck.Com

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.EfG站长之家-易采站长站-Easck.Com

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.EfG站长之家-易采站长站-Easck.Com

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.EfG站长之家-易采站长站-Easck.Com

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.EfG站长之家-易采站长站-Easck.Com

查看是否启用透明大页

1:命令cat /sys/kernel/mm/redhat_transparent_hugepage/enabled 该命令适用于Red Hat Enterprise Linux系统EfG站长之家-易采站长站-Easck.Com

[root@getlnx06 ~]# more /etc/issue
 
Red Hat Enterprise Linux Server release 6.6 (Santiago)
 
Kernel \r on an \m
 
[root@getlnx06 ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
 
[always] madvise never

2:命令cat /sys/kernel/mm/transparent_hugepage/enabled 该命令适用于其它Linux系统EfG站长之家-易采站长站-Easck.Com

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

使用命令查看时,如果输出结果为[always]表示透明大页启用了。[never]表示透明大页禁用、[madvise]表示(只在MADV_HUGEPAGE标志的VMA中使用THPEfG站长之家-易采站长站-Easck.Com

3:如何HugePages_Total返回0,也意味着标准大页禁用了(注意传统/标准大页和透明大页的区别)EfG站长之家-易采站长站-Easck.Com

透明大页(THP)管理和标准/传统大页(HP)管理都是操作系统为了减少页表转换消耗的资源而发布的新特性,虽然ORACLE建议利用大页机制来提高数据库的性能,但是ORACLE却同时建议关闭透明大页管理。这二者的区别在于大页的分配机制,标准大页管理是预分配的方式,而透明大页管理则是动态分配的方式。EfG站长之家-易采站长站-Easck.Com

[root@getlnx06 ~]# grep -i HugePages_Total /proc/meminfo 
 
HugePages_Total: 0

4:cat /proc/sys/vm/nr_hugepages返回0也意味着传统大页禁用了(传统大页和透明大页)。EfG站长之家-易采站长站-Easck.Com

[root@getlnx06 ~]# cat /proc/sys/vm/nr_hugepages 
 
0

禁用、启用透明大页功能

方法1:设置/etc/grub.conf文件,在系统启动是禁用。EfG站长之家-易采站长站-Easck.Com

[root@getlnx06 ~]# vi /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,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/VolGroup--LogVol0-LogVol01
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5

Linux关于透明大页机制的介绍EfG站长之家-易采站长站-Easck.Com

方法2:设置/etc/rc.local文件EfG站长之家-易采站长站-Easck.Com

[root@getlnx06 ~]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
 
touch /var/lock/subsys/local
 
if test -f /sys/kernel/mm/redhat_transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
fi

Linux关于透明大页机制的介绍EfG站长之家-易采站长站-Easck.Com

使用上面的配置后必须重启操作系统才能生效,你也可以运行下面命令不用重启操作系统。EfG站长之家-易采站长站-Easck.Com

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:EfG站长之家-易采站长站-Easck.Com

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

小知识点:

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

2:Transparent Huge Pages在32位的RHEL 6中是不支持的。EfG站长之家-易采站长站-Easck.Com

Transparent Huge Pages are not available on the 32-bit version of RHEL 6.EfG站长之家-易采站长站-Easck.Com

3: ORACLE官方不建议我们使用RedHat 6, OEL 6, SLES 11 and UEK2 kernels 时的开启透明大页(Transparent HugePages ), 因为透明大页(Transparent HugePages ) 存在一些问题:EfG站长之家-易采站长站-Easck.Com

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.EfG站长之家-易采站长站-Easck.Com

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.EfG站长之家-易采站长站-Easck.Com

4:安装Vertica Analytic Database时也必须关闭透明大页功能。EfG站长之家-易采站长站-Easck.Com

到此这篇关于Linux关于透明大页机制的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持我们。EfG站长之家-易采站长站-Easck.Com

EfG站长之家-易采站长站-Easck.Com

如有侵权,请联系QQ:279390809 电话:15144810328

相关文章

  • Linux下用GHOST来做系统备份

    Linux下用GHOST来做系统备份

    在Windows系统下备份我们可以用GHOST工具软件完成,Linux系统不能完全依赖于GHOST工具,一则是GHOST本身是有版权的软件,二是GHOST只支持ext2、ext3文件系统的Linux分区,不支持reiserfs、xfs等
    2019-10-25
  • 给 FreeBSD 12.1 安装 GNOME3 图形界面

    给 FreeBSD 12.1 安装 GNOME3 图形界面

    FreeBSD是一个完全开放的、安全的系统,可以Do it yourself的系统。但是个人还是不喜欢呆板的命令行界面,所有就给 FreeBSD 12.1 安装 GNOME3 图形界面。 开始操作,启动FreeBSD 12.1,以root身份
    2019-10-27
  • Ubuntu Studio一个不错的操作系统

    Ubuntu Studio一个不错的操作系统

    Ubuntu Studio 是一个基于 Ubuntu 而面向音频、视频及图形爱好者的操作系统。本次推出的 Ubuntu Studio 为 7.04 版,目前仅支持 Intel i386 兼容的处理器。 Ubuntu Studio 从大量的开源多媒体创作程序
    2019-10-25
  • 最受欢迎的10款Linux免费游戏

    最受欢迎的10款Linux免费游戏

    图为在Linux下运行的免费游戏America's Army 如果你认为 Linux下没有什么好游戏的话,那就错了!我们来看看Linux下最受欢迎的10款游戏吧,而且这些游戏都是完全免费的! # skyreal update(06-12
    2019-10-25
  • compiz fusion特效使用心得(附3D桌面图)

    compiz fusion特效使用心得(附3D桌面图)

    3D桌面图 LINUX发行版就是好,当大多数人还在沉迷于那些什么风格图标鸟玻璃效果甚至孜孜不倦津津乐道的时候,Linux的高手们已经悄悄为我们开启了一个桌面系统3D的时代。 当我第一次
    2019-10-25
  • Ubuntu 下aMule 的安装配置

    Ubuntu 下aMule 的安装配置

    aMule 是一个类似于 eMule 的多平台 P2P 客户端程序。以下将简略叙述 aMule 在 Ubuntu 中的安装及配置 [High ID] 与 [KAD] 的过程。 安装: sudo apt-get install amule sudo apt-get install amule-utils 如果需要
    2019-10-25
  • JMeter jp@gc - stepping thread group插件

    JMeter jp@gc - stepping thread group插件

    这是一个出单接口压力测试的小例子,了解一下压力测试最最基础的基础。出单接口是用来保险出单的,不需要在UI界面下一步下一步的出单,接口一调数据入库完事~~~。再啰嗦一句接
    2019-10-27
  • Ubuntu 下使用K3B软件刻录光盘(图)

    Ubuntu 下使用K3B软件刻录光盘(图)

    不知大家会不会在Ubuntu下刻录光盘呢?k3b是KDE环境下的一个CD/DVD刻录软件,有非常容易使用的界面,功能比较齐全。用起来感觉就象是win下的Nero一样简单自然,比ubuntu里原来的刻录CD方式
    2019-10-25