欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Linux系统下快速配置HugePages的完整步骤

程序员文章站 2022-07-09 16:50:58
前言 关于linux系统的hugepages与oracle数据库优化,可以参考熊爷之前的文章,相关概念介绍的非常清晰: linux大内存页oracle数据库优化...

前言

关于linux系统的hugepages与oracle数据库优化,可以参考熊爷之前的文章,相关概念介绍的非常清晰:

linux大内存页oracle数据库优化

本文旨在linux系统上快速配置hugepages

测试环境:rhel6.8 + 512g物理内存;oracle 11.2.0.4 sga=400g.

1.设置memlock无限制

在/etc/security/limits.conf配置文件中,设置oracle用户memlock无限制:

vi /etc/security/limits.conf

oracle soft memlock unlimited
oracle hard memlock unlimited

2.设置合理的vm.nr_hugepages

在/etc/sysctl.conf配置文件中,设置合理的vm.nr_hugepages值。

运行mos 401749.1提供的hugepages_settings.sh脚本,直接可以得到建议值。

hugepages_settings.sh脚本内容:

#!/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 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 -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.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

直接运行脚本即可得到对应的建议:

--当启动的实例设置sga_max_size=12g,给出建议:
recommended setting: vm.nr_hugepages = 6148

--当启动的实例设置sga_max_size=400g,给出建议:
recommended setting: vm.nr_hugepages = 204805

--当没有启动实例时,会报错提示:
***********
** error **
***********
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

我这里将建议值vm.nr_hugepages = 204805追加到/etc/sysctl.conf配置文件中,然后执行sysctl -p生效配置。

3.确认hugepages设置成功

查看关于hugepages的信息,注意hugepages_total值是之前设置的204805:

grep huge /proc/meminfo

# grep huge /proc/meminfo 
anonhugepages: 0 kb
hugepages_total: 204805
hugepages_free: 168475
hugepages_rsvd: 168471
hugepages_surp: 0
hugepagesize: 2048 kb

数据库在启动时,对应alert日志中会有“large pages information”内容:

wed nov 14 14:38:12 2018
starting oracle instance (normal)
************************ large pages information *******************
per process system memlock (soft) limit = unlimited

total shared global region in large pages = 400 gb (100%)

large pages used by this instance: 204801 (400 gb)
large pages unused system wide = 4 (8192 kb)
large pages configured system wide = 204805 (400 gb)
large page size = 2048 kb
********************************************************************

至此可以确认hugepages设置成功。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。