oracle12c rac 开启hugepage

1、需求背景

在数据库集成巡检中发现oracle rac其中有一个节点的内存使用率非常高,而且42core的cpu5分钟负载已经达到219,167,131,swap free已经为0了。由于该主机内存比较大230g以上,所以当内存耗尽的时候,会导致频繁的cpu调度产生,所以导致了上述cpu5分钟负载也过高的问题。

2hugepages简介

HugePages是Linux内核的一项功能,它允许较大的页面来管理内存,以替代较小的4KB页面大小。有关详细介绍,请参见文档361323.1

为什么需要巨大的页面?

如果您有较大的RAM和SGA,则HugePages对于在Linux上提高Oracle数据库性能至关重要。如果组合的数据库SGA很大(例如超过8GB,甚至对于较小的数据库甚至很重要),则需要配置HugePages。请注意,SGA的大小很重要。HugePages的优点是:

  • 较大的页面大小和较少的页面数:默认页面大小为4K,而HugeTLB大小为2048K。这意味着系统将需要处理少512倍的页面。
  • 减少页面表遍历:由于HugePage比常规大小的页面覆盖更大的连续虚拟地址范围,因此使用HugePages的每个TLB条目获得TLB命中的可能性高于常规页面。这减少了遍历页表以从虚拟地址获取物理地址的次数。
  • 减少内存操作的开销:在虚拟内存系统(任何现代OS)上,每个内存操作实际上是两个抽象内存操作。使用HugePages,由于要处理的页面数量较少,因此可以避免页面表访问中可能出现的瓶颈。
  • 更少的内存使用:从Oracle数据库的角度来看,与常规大小的页面相比,Linux内核通过HugePages将使用更少的内存来创建页表来维护SGA地址范围的虚拟到物理映射。这使更多的内存可用于进程专用计算或PGA使用。
  • 不交换:我们必须避免在所有文档1295478.1上的Linux OS上进行交换。HugePages是不可交换的(而常规页面是可交换的)。因此,没有页面替换机制的开销。HugePages通常被认为是固定的。
  • 没有“ kswapd”操作:如果要分页的区域很大(例如,用于50GB内存的1300万页表项),则kswapd将变得非常繁忙,并且将使用大量CPU资源。使用HugePages时,kswapd不会参与管理它们。另见文档361670.1

3、开启步骤

3.1、前提条件检查

3.1.1、检查操作系统Transparent HugePages是否关闭

root@rac1[/root]#cat /sys/kernel/mm/transparent_hugepage/defrag

always madvise [never]

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

always madvise [never]

root@rac1[/root]#

root@rac1[/root]#grep HugePages /proc/meminfo

AnonHugePages:         0 kB

HugePages_Total:       0

HugePages_Free:        0

HugePages_Rsvd:        0

HugePages_Surp:        0

如果都是never表示操作系统禁用了transparent_hugepage条件满足

3.1.2、关闭操作系统transparent_hugepage

否则就需要关闭操作系统的transparent_hugepage

备份启动文件

# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak

# cp /etc/default/grub /etc/default/grub.bak

编辑启动文件

vi /etc/default/grub

GRUB_CMDLINE_LINUX="crashkernel=128M rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet transparent_hugepage=never"

重新生成启动文件

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

确认启动文件已添加transparent_hugepage=never选项

cat /boot/grub2/grub.cfg

添加启动项

# vi /etc/rc.d/rc.local

添加如下内容:

# Disable Transparent HugePages

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then

echo never > /sys/kernel/mm/transparent_hugepage/enabled

fi

if test -f /sys/kernel/mm/transparent_hugepage/defrag; then

echo never > /sys/kernel/mm/transparent_hugepage/defrag

fi

赋予可执行权限

#chmod +x /etc/rc.d/rc.local

重启虚机

# su - grid

$crsctl stop instance -d cc -n rac1

$crsctl stop instance -d rb -n rac1

$exit

#locate crsctl

# /u01/app/grid/product/bin/crsctl stop crs

#reboot

再次回到3.1.1检查transparent_hugepage是否已经关闭。

3.1.3、检查memory_target参数

oraclerac@rac1[/home/oraclerac]$export ORACLE_SID=test1

oraclerac@rac1[/home/oraclerac]$sqlplus / as sysdba

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

SQL>

如果两个都配置为0,表明未开启自动内存管理,条件满足。

3.1.4检查use_large_pages参数

SQL> show parameter USE_LARGE_PAGES

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

use_large_pages                      string      TRUE

SQL>

如果值为TRUE,表示支持开启oracle hugepages,条件满足。

3.2、配置os资源限制

此处配置值略小于系统安装物理内存,大概可以配置90%安装物理内存。此处以安装物理内存为230G为例。单位kb。

vi /etc/security/limits.conf

*   soft   memlock    217055232

*   hard   memlock    217055232

 

3.3、重新登陆oracle用户执行检查

oracle@rac1[/home/oracle]$ulimit -l

2217055232

应该是你刚才设置的值。

3.4、检查所有的数据库实例

确保所有的数据库实例(包括ASM实例)均已启动,并且可以在生产环境中运行。

root@rac1[/root]#su - grid

grid@rac1[/home/grid]$crsctl stat res -t

ora.asm

      1        ONLINE  ONLINE       rac1                     Started,STABLE

      2        ONLINE  ONLINE       rac2                     Started,STABLE

      3        OFFLINE OFFLINE                               STABLE

ora.joyce.db

      2        ONLINE  ONLINE       rac1                     Open,HOME=/u01/app/o

                                                             racle/product/12.1.0

                                                             ,STABLE

ora.test.db

      1        ONLINE  ONLINE       rac1                     Open,HOME=/u01/app/o

                                                             racle/product/12.1.0

                                                             ,STABLE

      2        ONLINE  ONLINE       rac2                     Open,HOME=/u01/app/o

                                                             racle/product/12.1.0

                                                             ,STABLE

检查所有oracle实例和asm实例都已经启动运行

3.5、计算hugepages内核参数大小

使用脚本hugepages_settings.sh来计算vm.nr_hugepages内核参数。脚本内容如下:

#!/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 text
echo "
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 the overall 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 -m


Press Enter to proceed..."

read

# Check for the kernel version
KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`

# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`
if [ -z "$HPG_SZ" ];then
    echo "The hugepages may not be supported in the system where the script is being executed."
    exit 1
fi

# Initialize the counter
NUM_PG=0

# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | cut -c44-300 | awk '{print $1}' | grep "[0-9][0-9]*"`
do
    MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
    if [ $MIN_PG -gt 0 ]; then
        NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
    fi
done

RES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" | bc -q`

# An SGA less than 100MB does not make sense
# Bail out if that is the case
if [ $RES_BYTES -lt 100000000 ]; then
    echo "***********"
    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 -m

of 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 1
fi

# Finish with results
case $KERN in
    '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" ;;
    '4.14') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
    *) echo "Kernel version $KERN is not supported by this script (yet). Exiting." ;;
esac

# End

修改脚本权限

root@rac1[/root]#chmod 755 hugepages_settings.sh

root@rac1[/root]#./hugepages_settings.sh

 

Press Enter to proceed...

 

Recommended setting: vm.nr_hugepages = 4325

3.6、新增内核参数

根据上面算出来的值,新增内核参数vm.nr_hugepages

root@rac1[/root]#vi /etc/sysctl.conf

vm.nr_hugepages = 4325

3.7、重启虚机

# su - grid

$srvctl stop instance -d cc -n rac1

$srvctl stop instance -d rb -n rac1

$exit

#locate crsctl

# /u01/app/grid/product/bin/crsctl stop crs

#reboot

3.8、检查hugepages

root@rac1[/root]#grep HugePages /proc/meminfo

AnonHugePages:         0 kB

HugePages_Total:    4325

HugePages_Free:     4304

HugePages_Rsvd:       71

HugePages_Surp:        0

3.9启动数据库实例

#locate crsctl

# /u01/app/grid/product/bin/crsctl start crs

#su - grid

$srvctl start instance -d cc -n rac1

$srvctl start instance -d rb -n rac1

$crsctl stat res -t

确保所有的数据库实例和asm实例都起了。

3.10、检查hugepages

root@rac1[/root]#grep HugePages /proc/meminfo

AnonHugePages:         0 kB

HugePages_Total:    4325

HugePages_Free:     1272

HugePages_Rsvd:       72

HugePages_Surp:        0

4影响说明

由于使用的是oracle12.2版本的rac版本,我们执行操作的时候是两个节点滚动执行该操作,在同一个时刻只会停机一个节点,另一个节点仍然可以提供服务,所以业务不会有停机时间。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章