百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>服务器> Linux对于透明大页的运用与禁用介绍
分享文章到:

Linux对于透明大页的运用与禁用介绍

发布时间:05/13 来源:未知 浏览: 关键词:

引言

随着盘算需求规模的一直增大,利用程序对内存的需求也越来越大。为了实现虚拟内存治理机制,操纵系统对内存履行分页治理。自内存“分页机制”提出之始,内存页面的默许大小便被设置为 4096 字节(4KB),虽然准则上内存页面大小是可配置的,但绝大多数的操纵系统实现中依然采纳默许的 4KB 页面。 4KB 大小的页面在“分页机制”提出的时候是合理的,由于当时的内存大小不过几十兆字节,然而当物理内存容量增长到几 G 甚至几十 G 的时候,操纵系统依然以 4KB 大小为页面的根本单位,是否仍然合理呢?

在 Linux 操纵系统上运转内存需求量较大的利用程序时,因为其采纳的默许页面大小为 4KB,因此将会发生较多 TLB Miss 和缺页中止,从而大大影相应用程序的机能。当操纵系统以 2MB 甚至更大作为分页的单位时,将会大大减少 TLB Miss 和缺页中止的数目,显著提高利用程序的机能。这也正是 Linux 内核引入大页面支撑的直接缘由。益处是很显明的,假如利用程序需要 2MB 的内存,要是操纵系统以 4KB 作为分页的单位,则需要 512 个页面,进而在 TLB 中需要 512 个表项,同时也需要 512 个页表项,操纵系统需要阅历至少 512 次 TLB Miss 和 512 次缺页中止才能将 2MB 利用程序空间全部映射到物理内存;然而,当操纵系统采纳 2MB 作为分页的根本单位时,只需要一次 TLB Miss 和一次缺页中止,就可认为 2MB 的利用程序空间创立虚实映射,并在运转历程中无需再阅历 TLB Miss 和缺页中止(假如未产生 TLB 项替代和 Swap)。

为了能以最小的代价实现大页面支撑,Linux 操纵系统采纳了基于 hugetlbfs 特别文件系统 2M 字节大页面支撑。这种采纳特别文件系统情势支撑大页面的方式,使得利用程序可以依据需要灵活地选中虚存页面大小,而不会被强迫运用 2MB 大页面。

Redis在Linux中启动时平常会报“WARNING you have Transparent Huge Pages (THP) support enabled in your kernel”的告诫信息,意思是:你运用的是透明大页,可能导致redis推迟和内存运用题目。

对于透明大页,我们看看官方的介绍

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系统

[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系统

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

运用下令查看时,要是输出效果为[always]表示透明大页启用了。[never]表示透明大页禁用、[madvise]表示

3:怎样HugePages_Total返回0,也意味着透明大页禁用了

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

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

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

0

禁用、启用透明大页功能

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

[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

要领2:设置/etc/rc.local文件

[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

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

[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中是不支撑的。

3: ORACLE官方不倡议我们运用RedHat 6, OEL 6, SLES 11 and UEK2 kernels 时的开启透明大页(Transparent HugePages ), 由于透明大页(Transparent HugePages ) 存在一些题目:

  • 在RAC环境下 透明大页(Transparent HugePages )会导致异样节点重启,和机能题目
  • 在单机环境中,透明大页(Transparent HugePages ) 也会导致一些异样的机能题目

总结

以上就是这篇文章的全部内容了,但愿本文的内容对大家的学习或者工作拥有一定的参考学习价值,感谢大家对脚本之家的支撑。要是你想理解更多相干内容请查看下面相干链接

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有156人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板