小知识:关于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系统

?
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 dont
# 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的透明大页详细介绍-1猿站网-插图

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

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

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:LNMP编译安装之nginx安装配置方法图文教程

2023-4-22 23:55:25

建站知识

小知识:Apache 的 httpd.conf 中文详解

2023-4-22 23:56:09

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索