服务器之家

服务器之家 > 正文

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

时间:2021-10-28 16:15     来源/作者:潇湘隐者

 透明大页介绍

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时也必须关闭透明大页功能。

标签:

相关文章

热门资讯

yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
2021年耽改剧名单 2021要播出的59部耽改剧列表
2021年耽改剧名单 2021要播出的59部耽改剧列表 2021-03-05
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部