Huge pages ( 标准大页 ) 和 Transparent Huge pages( 透明大页 )

原文

在 Linux 中大页分为两种: Huge pages ( 标准大页 ) 和  Transparent Huge pages( 透明大页 ) 。

内存是以块即页的方式进行管理的,当前大部分系统默认的页大小为 4096 bytes 即 4K 。 1MB 内存等于256 页; 1GB 内存等于 256000 页。

CPU 拥有内置的内存管理单元,包含这些页面的列表,每个页面通过页表条目引用。当内存越来越大的时候,CPU 需要管理这些内存页的成本也就越高,这样会对操作系统的性能产生影响。Huge Pages

Huge pages  是从 Linux Kernel 2.6 后被引入的,目的是通过使用大页内存来取代传统的 4kb 内存页面,以适应越来越大的系统内存,让操作系统可以支持现代硬件架构的大页面容量功能。

Huge pages  有两种格式大小: 2MB  和  1GB , 2MB 页块大小适合用于 GB 大小的内存, 1GB 页块大小适合用于 TB 级别的内存; 2MB 是默认的页大小。Transparent Huge Pages

Transparent Huge Pages  缩写  THP ,这个是 RHEL 6 开始引入的一个功能,在 Linux6 上透明大页是默认启用的。

由于 Huge pages 很难手动管理,而且通常需要对代码进行重大的更改才能有效的使用,因此 RHEL 6 开始引入了 Transparent Huge Pages ( THP ), THP 是一个抽象层,能够自动创建、管理和使用传统大页。

THP 为系统管理员和开发人员减少了很多使用传统大页的复杂性 ,  因为 THP 的目标是改进性能 ,  因此其它开发人员  ( 来自社区和红帽 )  已在各种系统、配置、应用程序和负载中对  THP  进行了测试和优化。这样可让 THP  的默认设置改进大多数系统配置性能。但是 ,  不建议对数据库工作负载使用  THP 。

这两者最大的区别在于 :  标准大页管理是预分配的方式,而透明大页管理则是动态分配的方式。

标准大页的页面大小

[oracle@we2db1 ~]$ grep Hugepagesize /proc/meminfo

Hugepagesize:       2048 kB

注: THP  目前只能映射异步内存区域,比如堆和栈空间

Oracle  官方是推荐我们使用 Huge pages 的,它拥有以下的好处:

  • Larger Page Size and Less # ofPages: Default page size is 4K whereas the HugeTLB size is 2048K. That meansthe system would need to handle 512 times less pages.
  • Reduced Page Table Walking:Since a HugePage covers greater contiguous virtual address range than a regularsized page, a probability of getting a TLB hit per TLB entry with HugePages arehigher than with regular pages. This reduces the number of times page tablesare walked to obtain physical address from a virtual address.
  • Less Overhead for MemoryOperations: On virtual memory systems (any modern OS) each memory operation isactually two abstract memory operations. With HugePages, since there are lessnumber of pages to work on, the possible bottleneck on page table access isclearly avoided.
  • Less Memory Usage: From theOracle Database perspective, with HugePages, the Linux kernel will use lessmemory to create pagetables to maintain virtual to physical mappings for SGAaddress range, in comparison to regular size pages. This makes more memory tobe available for process-private computations or PGA usage.
  • No Swapping: We must avoidswapping to happen on Linux OS at all Document 1295478.1. HugePages are notswappable (whereas regular pages are). Therefore there is no page replacementmechanism overhead. HugePages are universally regarded as pinned.
  • No ‘kswapd’ Operations: kswapdwill get very busy if there is a very large area to be paged (i.e. 13 millionpage table entries for 50GB memory) and will use an incredible amount of CPUresource. When HugePages are used, kswapd is not involved in managing them. Seealso Document 361670.1

当然使用  Huge pages  也会存在某些缺点:

首先开启该功能需要进行额外设置,

第二, Huge pages  和 Oracle 11g新 特性 AMM ( Automatic Memory Management )是相互冲突的,但是 ASMM ( Automatic Shared Memory Management )仍然可以继续使用。

Oracle 官方虽然推荐我们使用  Huge pages ,但是却建议我们关闭 Transparent Huge pages ,因为透明大页存在一些问题:

1. 在 RAC 环境下   透明大页( TransparentHugePages  )会导致异常节点重启,和性能问题;

2. 在单机环境中,透明大页( TransparentHugePages  ) 也会导致一些异常的性能问题;

注:Transparent Huge Pages在32位的RHEL 6中是不支持的。禁用trasnparent hugepage

查看透明大页是否已经启用

[root@we2db2 ~]# cat /etc/issue

Red Hat Enterprise Linux Server release 6.9(Santiago)

Kernel \r on an \m

[root@we2db2 ~]# cat/sys/kernel/mm/transparent_hugepage/enabled

always madvise [never]

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

[never] 表示透明大页禁用、 [madvise] 表示(只在 MADV_HUGEPAGE 标志的 VMA 中使用 THP 。

这里已经禁用了,若未禁用可以使用以下方式禁用

[root@we2db2 ~]# more /etc/grub.conf

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grubafter making changes to this file

# NOTICE: You have a /boot partition.  Thismeans that

#         all kernel and initrd paths are relative to /boot/, eg.

#         root (hd0,0)

#         kernel /vmlinuz-version ro root=/dev/mapper/rootvg-lv_root

#         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-696.20.1.el6.x86_64)

       root (hd0,0)

       kernel /vmlinuz-2.6.32-696.20.1.el6.x86_64 ro root=/dev/mapper/rootvg-lv_roottransparent_hugepage=never   rd_NO_LUKS.UTF-8 rd_LVM_L

V=rootvg/lv_swap rd_NO_MDSYSFONT=latarcyrheb-sun16 rd_LVM_LV=rootvg/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgbquiet

       initrd /initramfs-2.6.32-696.20.1.el6.x86_64.img配置huge page

1.  在 /etc/security/limits.conf 加入以下参数

*  soft   memlock    8193024

*  hard   memlock    8193024

这里的试验环境是 8G  的内存, memlock  参数的值只需略小于内存的值即可,即使超过了 SGA 的需求,也没有任何影响。

[root@we2db1 ~]# cat /etc/security/limits.conf

*  soft   memlock    8193024

*  hard   memlock    8193024

2. 重新登录服务器验证设置

[root@we2db1 ~]# ulimit -l

8193024

3. 在 Oracle 11g 中禁用  AutomaticMemory Management (AMM) 特性,即 MEMORY_TARGET and MEMORY_MAX_TARGET  值为 。

SQL> show parameter MEMORY_TARGET

NAME                                 TYPE        VALUE

———————————————– ——————————

memory_target                        big integer 0

SQL> show parameter MEMORY_MAX_TARGET

NAME                                 TYPE        VALUE

———————————————– ——————————

memory_max_target                    big integer 0

这里试验环境并没有启用 AMM 特性,如果启用了该特性使用一下语句关闭。

alter system setMEMORY_TARGET=0 scope=spfile;

alter system setMEMORY_MAX_TARGET=0 scope=spfile;

重启实例后生效。

4. 确认所有需要使用 Hugepage 的实例都是开启的 ( 包括 ASM 实例 ) ,然后运行 hugepages_settings.sh(具体脚本参考文档  ID 401749.1 )

[root@we2db1 ~]# chmod +xhugepages_settings.sh

[root@we2db1 ~]# ./hugepages_settings.sh

This script is provided by Doc ID 401749.1from My Oracle Support

(http://support.oracle.com) where it isintended to compute values for

the recommended HugePages/HugeTLBconfiguration for the current shared

memory segments on Oracle Linux. Beforeproceeding with the execution please note following:

 *For ASM instance, it needs to configure ASMM instead of AMM.

 *The ‘pga_aggregate_target’ is outside the SGA and

  you should accommodate this while calculating SGA size.

 * Incase you changes the DB SGA size,

   asthe new SGA will not fit in the previous HugePages configuration,

   ithad better disable the whole HugePages,

  start the DB with new SGA size and run the script again.

And make sure that:

 *Oracle Database instance(s) are up and running

 *Oracle Database 11g Automatic Memory Management (AMM) is not setup

  (See Doc ID 749851.1)

 *The shared memory segments can be listed by command:

    # ipcs -m

Press Enter to proceed…

Recommended setting:vm.nr_hugepages = 1204

5. 在  /etc/sysctl.conf  文件中添加 vm.nr_hugepages 参数

[root@we2db1 ~]# cat /etc/sysctl.conf |grep nr_hugepages

vm.nr_hugepages = 1204

[root@we2db2 ~]# cat /etc/sysctl.conf |grep nr_hugepages

vm.nr_hugepages = 1204

6. 关闭所有数据库实例并重启服务器

7. 验证配置是否正确,如下所示:

[root@we2db2 ~]# grep HugePages  /proc/meminfo

AnonHugePages:         0 kB

HugePages_Total:    1204

HugePages_Free:      739

HugePages_Rsvd:      736

HugePages_Surp:        0

为了确保 HugePages 配置的有效性, HugePages_Free 值应该小于 HugePages_Total  的值,并且有一定的HugePages_Rsvd 的值。

Also there should be some HugePages_Rsvd ifPRE_PAGE_SGA is ‘false’ for all the Oracle database instances..

HugePages_Rsvd counts free pages that arereserved for use (requested for an SGA, but not touched/mapped yet).

PRE_PAGE_SGA determines if the all SGApages are read-in when the instance starts up.

If parameter is set to ‘true’ then the OSpage table entries are prebuilt for each page of the SGA, leading to HugePagesreservation of those pages.

For Oracle database versions before 12.1the default value for PRE_PAGE_SGA is ‘false’. So the HugePages_Rsvd would behigher than 0. But since 12c the PRE_PAGE_SGA defaults to ‘true’ which wouldcause the HugePages_Rsvd to be 0.

The sum of Hugepages_Free andHugePages_Rsvd may be smaller than your total combined SGA as instancesallocate pages dynamically and proactively as needed.

至此  HugePages  已经配置完成。

虽然 Oracle 官方推荐使用 Huge Pages  但是具体是否使用还得考虑实际情况。 如果您的系统经常碰到因为swap 引发的性能问题的系统可以考虑启用 HugePage 。另外, OS 内存非常大的系统也可以启用 HugePage。但是具体多大就一定需要使用 HugePage ?这并没有定论。

参考文档:

HugePages on Oracle Linux 64-bit ( 文档  ID361468.1)

HugePages and Oracle Database 11g AutomaticMemory Management (AMM) on Linux ( 文档  ID 749851.1)

HugePages on Linux: What It Is… and WhatIt Is Not… ( 文档  ID 361323.1)

Oracle Linux: Shell Script to CalculateValues Recommended Linux HugePages / HugeTLB Configuration ( 文档  ID401749.1)

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-memory-transhuge#s-memory-configure_hugepages


脚本内容:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980#!/bin/bash## hugepages_settings.sh## Linux bash script to compute values for the# recommended HugePages/HugeTLB configuration# on Oracle Linux## Note: This script does calculation for all shared memory# segments available when the script is run, no matter it# is an Oracle RDBMS shared memory segment or not.## This script is provided by Doc ID 401749.1 from My Oracle Support # http://support.oracle.com# Welcome textecho "This script is provided by Doc ID 401749.1 from My Oracle Support (http://support.oracle.com) where it is intended to compute values for the recommended HugePages/HugeTLB configuration for the current shared memory segments on Oracle Linux. Before proceeding with the execution please note following:* For ASM instance, it needs to configure ASMM instead of AMM.* The 'pga_aggregate_target' is outside the SGA and you should accommodate this while calculating SGA size.* In case you changes the DB SGA size, as the new SGA will not fit in the previous HugePages configuration, it had better disable the whole HugePages, start the DB with new SGA size and run the script again.And make sure that:* Oracle Database instance(s) are up and running* Oracle Database 11g Automatic Memory Management (AMM) is not setup (See Doc ID 749851.1)* The shared memory segments can be listed by command:# ipcs -mPress Enter to proceed..."read# Check for the kernel versionKERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`# Find out the HugePage sizeHPG_SZ=`grep Hugepagesize /proc/meminfo awk '{print $2}'`if [ -z "$HPG_SZ" ];thenecho "The hugepages may not be supported in the system where the script is being executed."exit 1fi# Initialize the counterNUM_PG=0# Cumulative number of pages required to handle the running shared memory segmentsfor SEG_BYTES in `ipcs -m | cut -c44-300 | awk '{print $1}' grep "[0-9][0-9]*"`doMIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" bc -q`if [ $MIN_PG -gt 0 ]; thenNUM_PG=`echo "$NUM_PG+$MIN_PG+1" bc -q`fidoneRES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" bc -q`# An SGA less than 100MB does not make sense# Bail out if that is the caseif [ $RES_BYTES -lt 100000000 ]; thenecho "***********"echo "** ERROR **"echo "***********"echo "Sorry! There are not enough total of shared memory segments allocated for HugePages configuration. HugePages can only be used for shared memory segments that you can list by command:# ipcs -mof a size that can match an Oracle Database SGA. Please make sure that:* Oracle Database instance is up and running * Oracle Database 11g Automatic Memory Management (AMM) is not configured"exit 1fi# Finish with resultscase $KERN in'2.2'echo "Kernel version $KERN is not supported. Exiting." ;;'2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" bc -q`;echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;'2.6'echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;'3.8'echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;'3.10'echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;'4.1'echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;esac# End


禁用透明大页 –Transparent Huge Pages (THP)

如果 HugePages_Total 返回 ,也意味着透明大页禁用了

grep -i HugePages_Total /proc/meminfo

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

在以下命令中:

cat /sys/kernel/mm/transparent_hugepage/enabled

如果输出结果为 [always] 表示透明大页启用了。 [never] 表示透明大页禁用、 [madvise] 表示只在 MADV_HUGEPAGE 标志的 VMA 中使用 THP 。

编辑 /etc/default/grub ,在 GRUB_CMDLINE_LINUX 加入选项 transparent_hugepage=never

[root@rac18c-sharedisks ~]# cat  /etc/default/grub

GRUB_TIMEOUT=5

GRUB_DISTRIBUTOR=”$(sed ‘s, release .*$,,g’ /etc/system-release)”

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT=”console”

GRUB_CMDLINE_LINUX=”crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet transparent_hugepage=never “

GRUB_DISABLE_RECOVERY=”true”

GRUB_CMDLINE_LINUX_DEFAULT=”console=ttyS0″

执行生效命令:

grub2-mkconfig -o /boot/grub2/grub.cfg

最后重启。

透明大页介绍

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]表示 (只在MADV_HUGEPAGE标志的VMA中使用THP

3:如何HugePages_Total返回0,也意味着标准大页禁用了(注意传统/标准大页和透明大页的区别)

   透明大页(THP)管理和标准/传统大页(HP)管理都是操作系统为了减少页表转换消耗的资源而发布的新特性,虽然ORACLE建议利用大页机制来提高数据库的性能,但是ORACLE却同时建议关闭透明大页管理。这二者的区别在于大页的分配机制,标准大页管理是预分配的方式,而透明大页管理则是动态分配的方式。

[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

禁用、启用透明大页功能

方法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.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
clip_image001

方法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
clip_image002

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

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

        1.在RAC环境下 透明大页(Transparent HugePages )会导致异常节点重启,和性能问题;

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

参考资料:

https://access.redhat.com/solutions/46111
http://www.soso.io/article/65143.html

Linux7.4 关闭透明大页

在Linux6.x之后的平台,在安装Oracle数据库的时候都建议关闭透明大页 
Linux下的大页分为两种类型:标准大页(Huge Pages)和透明大页(Transparent Huge Pages)。

1). 标准大页(Huge Pages)是从Linux Kernel 2.6后被引入的。目的是使用更大的内存页面(memory page size) 以适应越来越大的系统内存,让操作系统可以支持现代硬件架构的大页面容量功能。
2). 透明大页(Transparent Huge Pages)缩写为THP,这个是RHEL 6开始引入的一个功能。

这两者的区别在于大页的分配机制,标准大页管理是预分配的方式,而透明大页管理则是动态分配的方式。目前透明大页与传统大页混合使用会出现一些问题,导致性能问题和系统重启。ORACLE官方不建议在使用RedHat 6, OEL 6, SLES 11 and UEK2 kernels 时开启透明大页(THP), 因为透明大页存在一些问题: 
1.在RAC环境下 透明大页(Transparent HugePages )会导致异常节点重启和性能问题; 
2.在单机环境中,透明大页(Transparent HugePages ) 也会导致一些异常的性能问题;

2 关闭THP

Linux7 默认情况下 是开启透明大页功能的。 
检查系统对应版本  
[root@db-server ~]# uname -r 
3.10.0-693.el7.x86_64 
[root@db-server ~]# uname -a 
Linux db-server 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux 
[root@db-server ~]# cat /etc/redhat-release  
CentOS Linux release 7.4.1708 (Core)

默认情况下,状态为always,需要调整为never
Linux7.4 关闭透明大页
Linux7.4 关闭透明大页

修改文件 /etc/default/grub 文件 

Linux7.4 关闭透明大页

执行生效命令 grub2-mkconfig -o /boot/grub2/grub.cfg 

重启  
reboot

检查是否生效 

如果你也是grub2的linux系统,请通过以下步骤关闭大内存页面。

step1 编辑 /etc/default/grub,在GRUB_CMDLINE_LINUX加入选项 transparent_hugepage=never

1234567GRUB_TIMEOUT=5GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"GRUB_DEFAULT=savedGRUB_DISABLE_SUBMENU=trueGRUB_TERMINAL_OUTPUT="console"GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora/swap rd.lvm.lv=fedora/root rhgb quiet transparent_hugepage=never"GRUB_DISABLE_RECOVERY="true"

step2 重新生成grub配置文件

1234On BIOS-based machines, issue the following  command   as root:# grub2-mkconfig -o /boot/grub2/grub.cfgOn UEFI-based machines, issue the following  command   as root:# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

step3 重启你的系统

至此大功告成,如果你使用的是grub,请把选项写入grub.conf文件就好了。

查询hugepage状态,第一种方式

1234[root@localhost yucanlin] # cat /sys/kernel/mm/transparent_hugepage/enabledalways madvise [never][root@localhost yucanlin] # cat /sys/kernel/mm/transparent_hugepage/defragalways madvise [never]

never就对了。

第二种方式

1234567[yucanlin@localhost ~]$  grep   Huge /proc/meminfoAnonHugePages:         0 kBHugePages_Total:       0HugePages_Free:        0HugePages_Rsvd:        0HugePages_Surp:        0Hugepagesize:       2048 kB

0就对了。

不过有个小遗憾,重启后我发现 enabled 是never,但defrag却依然是always,不过经过查询meminfo,大内存页面是被禁用了。就不去管他了。



About Me

…………………………………………………………………………………………………………● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除● 本文在itpub(  http://blog.itpub.net/26736162  )、博客园(  http://www.cnblogs.com/lhrbest  )和个人weixin公众号( xiaomaimiaolhr  )上有同步更新● 本文itpub地址:  http://blog.itpub.net/26736162● 本文博客园地址:  http://www.cnblogs.com/lhrbest● 本文pdf版、个人简介及小麦苗云盘地址:  http://blog.itpub.net/26736162/viewspace-1624453/● 数据库笔试面试题库及解答:  http://blog.itpub.net/26736162/viewspace-2134706/● DBA宝典今日头条号地址:  http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826…………………………………………………………………………………………………………● QQ群号:  230161599  (满)  、618766405● weixin群:可加我weixin,我拉大家进群,非诚勿扰● 联系我请加QQ好友  (  646634621  )  ,注明添加缘由● 于 2018-09-01 06:00 ~ 2018-09-31 24:00 在魔都完成● 最新修改时间:2018-09-01 06:00 ~ 2018-09-31 24:00● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解● 版权所有,欢迎分享本文,转载请保留出处…………………………………………………………………………………………………………●  小麦苗的微店  :  https://weidian.com/s/793741433?wfr=c&ifr=shopdetail●  小麦苗出版的数据库类丛书  :  http://blog.itpub.net/26736162/viewspace-2142121/●  小麦苗OCP、OCM、高可用网络班  :  http://blog.itpub.net/26736162/viewspace-2148098/●  小麦苗腾讯课堂主页  :  https://lhr.ke.qq.com/………………………………………………………………………………….

Leave a Reply