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

[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

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

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:

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

(0)

相关推荐

  • 关于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 i

  • 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

  • Linux关于透明大页的使用与禁用介绍

    引言 随着计算需求规模的不断增大,应用程序对内存的需求也越来越大.为了实现虚拟内存管理机制,操作系统对内存实行分页管理.自内存"分页机制"提出之始,内存页面的默认大小便被设置为 4096 字节(4KB),虽然原则上内存页面大小是可配置的,但绝大多数的操作系统实现中仍然采用默认的 4KB 页面. 4KB 大小的页面在"分页机制"提出的时候是合理的,因为当时的内存大小不过几十兆字节,然而当物理内存容量增长到几 G 甚至几十 G 的时候,操作系统仍然以 4KB 大小为页面

  • Linux内存管理和寻址详细介绍

    目录 1.概念 内存管理模式 地址类型划分 说明: 2.页式管理 x86架构32位cpu x86架构 64位cpu 3.地址划分 4. 调试 结语 1.概念 内存管理模式 段式:内存分为了多段,每段都是连续的内存,不同的段对应不用的用途.每个段的大小都不是统一的,会导致内存碎片和内存交换效率低的问题. 页式:内存划分为多个内存页进行管理,如在 Linux 系统中,每一页的大小为 4KB.由于分了页后,就不会产生细小的内存碎片.但是仍然也存在内存碎片问题. 段页式:段式和页式结合. 地址类型划分

  • linux命令scp和sftp详细介绍

    linux命令scp和sftp详细介绍 1. 使用 scp 命令传输文件: 使用 scp 命令可以用来通过安全.加密的连接在不同主机之间传输文件. (1)把本地文件传输到远程主机: 一般语法:scp [本地文件] [用户名@远程主机IP地址:/目标文件夹] (2) 把远程文件传输到本地主机: 一般语法:scp [用户名@远程主机IP地址:/源文件] [本地目录] Note: scp后加 -r 选项可以传输文件夹. 2.使用sftp命令建立FTP会话: 使用sftp命令可以用来打开安全互动的.加密

  • Linux系统下netstat命令详细介绍

    目录 一.介绍 二.输出信息描述 三.netstat常见参数 四.netstat网络状态详解 Linux的相关keepalive参数 五.常用netstat相关命令 一.介绍 Netstat是控制台命令,是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实际的网络连接以及每一个网络接口设备的状态信息. Netstat用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况. 二.输出信息描述 执行netstat后输出如下: [root@sy-s

  • Linux shell脚本基础学习详细介绍(完整版)第1/2页

    Linux shell脚本基础学习这里我们先来第一讲,介绍shell的语法基础,开头.注释.变量和 环境变量,向大家做一个基础的介绍,虽然不涉及具体东西,但是打好基础是以后学习轻松地前提. 1. Linux 脚本编写基础 ◆1.1 语法基本介绍1.1.1 开头程序必须以下面的行开始(必须方在文件的第一行):#!/bin/sh符号#!用来告诉系统它后面的参数是用来执行该文件的程序.在这个例子中我们使用/bin/sh来执行程序.当编辑好脚本时,如果要执行该脚本,还必须使其可执行.要使脚本可执行:编译

  • Linux 重命名命令自制详细介绍

    Linux 重命名命令 相比于Windows上的ren命名,Linux还真的是没有一个特定的重命名的命令.(虽然可以间接的使用mv来实现).下面我就来自己写一个简单的重命名命令. 准备工作 操作系统: Linux内核的系统都可以 Shell:我用的系统默认的bash,(其实这个无所谓了) 基础: 了解关于shell脚本的基本的语法即可. 代码实现 #!/bin/bash #filename: rename.sh #description: rename file or directory by

  • Linux ProFTPd安装与卸载详细介绍

    Linux系统上ProFTPd安装与卸载的详细过程 yum install proftpd vi /etc/proftpd.conf ← 修改ProFTPD的配置文件 ServerType standalone ← 找到这一行,在行首添加"#" ↓ #ServerType standalone ← 变为此状态,不使用常驻模式 #ServerType inetd ← 找到这一行,去掉行首的"#" ↓ ServerType inetd ← 变为此状态,通过超级服务器来启

  • Linux  ProFTPd安装与卸载详细介绍

    Linux系统上ProFTPd安装与卸载的详细过程 yum install proftpd vi /etc/proftpd.conf ← 修改ProFTPD的配置文件 ServerType standalone ← 找到这一行,在行首添加"#" ↓ #ServerType standalone ← 变为此状态,不使用常驻模式 #ServerType inetd ← 找到这一行,去掉行首的"#" ↓ ServerType inetd ← 变为此状态,通过超级服务器来启

随机推荐