配置Hugepages官方文档地址
HugePages是集成到Linux内核2.6中的功能。启用HugePages使操作系统能够支持大于默认值(通常为4KB)的内存页面。使用大页可以减少访问页表条目所需的系统资源量来提高系统性能。HugePages可用于32位和64位的系统配置。根据内核版本和硬件架构,大页大小从2MB到256MB不等。对于Oracle数据库,使用HugePages可减少页面状态的操作系统维护,并增加页表缓冲(TBL)的命中率
没有HugePages,操作系统将每个4KB的内存保存为一个页面,当它被分配给SGA时,该页面的生命周期(dirty,free,mapped to process等)根据系统内核保持最新的状态。
使用HugePages,操作系统页表(虚拟内存到物理内存映射)较小,因为每个页表条目都指向从2MB到256MB的页面。并且内核较少的页面,其生命周期一定会被监视。
注意2MB大小的HugePages可用于Linux x86-64,Linux x86和IBM:Linux on System z.
以下是使用HugePages的优点:
·通过增加TLB命中来提高性能。
·页面被锁定在内存中,不会被交换出来,保证像SGA这样的共享内存保留在RAM中。
·连续的页面是预先分配的,不能用于其他任何东西,而只能用于System V共享内存(例如:SGA)
·由于更大的页面大小,对于虚拟内存的这部分的内核而言,更少的记录工作
*soft memlock 60397977
*hard memlock 60397977
你还可以设置比SGA更高的memlock值
ulimit -l
grep Hugepagesize /proc/meminfo
下面的例子需要根据自己的环境进行更改
a.创建一个名称为 hugepages_setting.sh
b.添加下面内容到文件中
#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
#
# 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.
# 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'}`
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk {'print $5'} | 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
# 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'|'3.8') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
*) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac
# End
c.运行下面的语句修改文件权限
chmod +x hugepages_settings.sh
./hugepages_settting.sh
sysctl -w vm.nr_hugepages=value_displayed_in_srtp_5
(第5步得出来的值)
vm.nr_hugepages=value_displayed_in_step_5
注意
运行下面的命令,去查看hugepages是否有效的
grep Huge /proc/meminfo
自动内存管理(AMM)和HugePages不兼容。当您使用AMM时,通过创建文件/dev/shm分配整个SGA内存。当Oracle数据库使用AMM分配SGA时,不会保留HugePages。要在Oracle数据库12c上使用HugePages,必须禁用AMM。
如果在32位环境中使用VLM,则不能使用HugePages作为数据缓冲区缓存。可以使用SGA的其他部分,如大页面 share_pool,large_pool等,使用共享内存文件系统
除非管理员通过修改可用页面数量或修改池大小来更改HugePages配置,否则HugePages不会在系统启动后分配或释放。如果在系统启动期间所需的空间不保留在内存中,则HugePages分配失败。
实验环境:oracle11g11.2.0.4单实例+centos7
[root@orcl oracle]# uname -r
3.10.0-327.el7.x86_64
oracle sofr memlock 3072
oracle hard memlock 3072
切换为oracle用户确认参数生效
[oracle@orcl ~]$ ulimit -l
64
[oracle@orcl ~]$ grep Hugepagesize /proc/meminfo
Hugepagesize: 2048 kB
#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
#
# 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.
# 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'}`
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk {'print $5'} | 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
# 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'|'3.8') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
*) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac
# End
创建一个脚本,并赋予执行权限,将上面脚本添加进文件
[oracle@orcl ~]$ touch hugepages_setting.sh
[oracle@orcl ~]$ chmod +x hugepages_setting.sh
执行
[oracle@orcl ~]$ ./hugepages_setting.sh
注意!
这里我执行的时候遇到三个问题:
解决办法:
[root@orcl oracle]# yum -y install bc
[root@orcl oracle]# ./hugepages_setting.sh
Unrecognized kernel version 3.10. Exiting.
解决办法:这里主要是我的内核版本之前查看过是3.10,而这脚本不识别,所以我们需要把我们的内核版本添加进去,如下所示,在3.8之后添加上我们的内核版本。
#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
#
# 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.
# 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'}`
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk {'print $5'} | 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
# 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'|'3.8'|'3.10') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
*) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac
# End
解决办法:
1).启动数据库
2).查看参数
SQL> show parameter target
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target integer 0
db_flashback_retention_target integer 1440
fast_start_io_target integer 0
fast_start_mttr_target integer 0
memory_max_target big integer 0
memory_target big integer 0
parallel_servers_target integer 16
pga_aggregate_target big integer 236M
sga_target big integer 500M
不使用AMM的标志,
四个参数(也就是只设置pga和sga的大小)修改命令,修改完之后需要重启数据库:
ALTER SYSTEM RESET memory_target SCOPE=SPFILE;
ALTER SYSTEM RESET memory_max_target SCOPE=SPFILE;
ALTER SYSTEM SET sga_target=? m SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target=? m SCOPE=SPFILE;
SHUTDOWN IMMEDIATE;
STARTUP;
修改完上面的问题之后执行得到的结果
[root@orcl oracle]# ./hugepages_setting.sh
Recommended setting: vm.nr_hugepages = 255
5.设置内核参数并将语句添加到/etc/sysctl.conf中
[root@orcl oracle]# sysctl -w vm.nr_hugepages=255
vm.nr_hugepages = 255
[root@orcl oracle]# echo "vm.nr_hugepages=255" >> /etc/sysctl.conf
6.重启服务器并查看参数是否配置正确
[root@orcl oracle]# grep Huge /proc/meminfo
AnonHugePages: 10240 kB
HugePages_Total: 255
HugePages_Free: 255
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
7.重点–一定要重启服务器只有重启才会生效
整个配置过程结束
简单介绍下AMM:是oracle11g提供的自动内存管理结合10提到ASMM我们可以大致配置为以下几种(这里不写参数只是介绍概念)
AMM:只需设置memory_target,memory_max_memory_target(这个参数不是强制控制内存上限)不设置SGA和PGA大小,有Oracle自动管理内存
不使用AMM就是值设置sga和pga大小,我们也可以设置memory大小和sga的大小。这样pga会由oracle自动管理,反之亦然。
以上是我整个实验的过程,如有错误还请之处。