服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Linux - 关于Linux的透明大页详细介绍

关于Linux的透明大页详细介绍

2021-10-28 16:15潇湘隐者 Linux

这片文章介绍了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.

查看是否启用透明大页

1:命令cat /sys/kernel/mm/redhat_transparent_hugepage/enabled 该命令适用于red hat enterprise linux系统

?
1
2
3
4
5
6
7
8
9
[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系统

?
1
2
3
4
5
[root@getlnx06 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
 
always madvise [never]
 
[root@getlnx06 ~]#

 

使用命令查看时,如果输出结果为[always]表示透明大页启用了。[never]表示透明大页禁用、[madvise]表示

 3:如何hugepages_total返回0,也意味着透明大页禁用了

?
1
2
3
[root@getlnx06 ~]# grep -i hugepages_total /proc/meminfo
 
hugepages_total: 0

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

?
1
2
3
[root@getlnx06 ~]# cat /proc/sys/vm/nr_hugepages
 
0

 

禁用、启用透明大页功能

 方法1:设置/etc/grub.conf文件,在系统启动是禁用。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[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
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title red hat enterprise linux 6 (2.6.32-504.el6.x86_64)
  root (hd0,0)
  kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/volgroup--logvol0-logvol01 rd_no_luks lang=en_us.utf-8 rd_no_md sysfont=latarcyrheb-sun16 crashkernel=auto rd_lvm_lv=volgroup-logvol0/logvol01 rd_lvm_lv=volgroup-logvol0/logvol00 keyboardtype=pc keytable=us rd_no_dm rhgb quiet
  initrd /initramfs-2.6.32-504.el6.x86_64.img
transparent_hugepage=never

关于Linux的透明大页详细介绍

 

方法2:设置/etc/rc.local文件

?
1
2
3
4
5
6
7
8
9
10
11
12
[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的透明大页详细介绍

使用上面的配置后必须重启操作系统才能生效,你也可以运行下面命令不用重启操作系统。

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
2
3
4
[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 可以实时配置,不需要重启才能生效配置;

 

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 ) 存在一些问题:

        a.在rac环境下 透明大页(transparent hugepages )会导致异常节点重启,和性能问题;

        b.在单机环境中,透明大页(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时也必须关闭透明大页功能。

延伸 · 阅读

精彩推荐
  • LinuxLinux中环境变量配置的步骤详解

    Linux中环境变量配置的步骤详解

    Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登录到系统的用户都要读取的系统变量,而用户级的环境变量则是该用户使用系统时加载的...

    Myths7882022-02-10
  • Linux手把手教您在 Linux 上使用 GPG 加解密文件

    手把手教您在 Linux 上使用 GPG 加解密文件

    在本教程中,我将告诉你如何用 GPG 加密和解密文件。这是一个简单的教程,你可以在你的 Linux 系统上尝试所有的练习。这将帮助你练习 GPG 命令,并在你...

    Linux中国6962021-12-15
  • LinuxLinux常用的日志文件和常用命令

    Linux常用的日志文件和常用命令

    成功地管理任何系统的关键之一,是要知道系统中正在发生什么事。 Linux 中提供了异常日志,并且日志的细节是可配置的。Linux 日志都以明文形式存储,所...

    Linux教程网2632020-04-18
  • Linuxlinux中rmdir命令使用详解(删除空目录)

    linux中rmdir命令使用详解(删除空目录)

    今天学习一下linux中命令: rmdir命令。rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的 ...

    linux命令大全5372019-11-19
  • Linux详解Linux系统下PXE服务器的部署过程

    详解Linux系统下PXE服务器的部署过程

    这篇文章主要介绍了Linux系统下PXE服务器的部署过程,包括对PXE的API架构作了一个基本的简介,需要的朋友可以参考下...

    运维之道9812019-07-04
  • LinuxLinux lnmp下无法使用mail发邮件的两种解决方法

    Linux lnmp下无法使用mail发邮件的两种解决方法

    在配置了lnmp环境后,出现了mail函数不能发送邮件的问题,其实有两种方法,一是使用sendmail组件,而是使用postfix。下面为大家一一介绍下 ...

    Linux之家4042019-09-17
  • LinuxLinux上设置用户通过SFTP访问目录的权限的方法

    Linux上设置用户通过SFTP访问目录的权限的方法

    这篇文章主要介绍了Linux上设置用户通过SFTP访问目录的权限的方法,SFTP可以理解为使用SSH协议进行FTP传输的协议,因而同时要对OpenSSH进行相关设置,需要的朋...

    OSChina10022019-06-19
  • Linux确保Linux系统安全的前提条件 漏洞防护

    确保Linux系统安全的前提条件 漏洞防护

    Linux 作为开放式的操作系统受到很多程序员的喜爱,很多高级程序员都喜欢编写Linux操作系统的相关软件。这使得Linux操作系统有着丰富的软件支持,还有无...

    Linux之家2642020-04-11