参考文档:
HugePages and Oracle Database 11g Automatic Memory Management (AMM) on Linux ( 文档 ID 749851.1)
HugePages on Linux: What It Is... and What It Is Not... ( 文档 ID 361323.1)
HugePages on Oracle Linux 64-bit ( 文档 ID 361468.1)
Shell Script to Calculate Values Recommended Linux HugePages / HugeTLB Configuration ( 文档 ID 401749.1)
/proc/meminfo Does Not Provide HugePages Information on Oracle Enterprise Linux (OEL5) ( 文档 ID 860350.1)
Hugepages are Not used by Database Buffer Cache ( 文档 ID 829850.1)
正文:
HugePages 是通过使用大页内存来取代传统的 4kb 内存页面,使得管理虚拟地址数变少,加快了从虚拟地址到物理地址的映射以及通过摒弃内存页面的换入换出以提高内存的整体性能。尤其是对于 8GB 以上的内存以及较大的 Oracle SGA size ,建议配值并使用 HugePage 特性
的大小
huge page 的大小取决于所使用的操作系统的内核版本以及不同的硬件平台 可以使用 $grep Hugepagesize /proc/meminfo 来查看 huge page 的大小,对于较大的系统内存以及 sga ,使用 hugepage 可以极大程度的提高 Oracle 数据库性能
本次配置过程详见文档: HugePages on Oracle Linux 64-bit ( 文档 ID 361468.1)
本操作基于 RHEL 6 进行测试:
[root@rehl6 ~]# more /etc/redhat-release
Red Hat Enterprise Linux Server release 6.2 (Santiago)
[root@rehl6 ~]# uname -a
Linux rehl6 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
查看当前系统是否配值HugePages
下面的查询中 HugePages 相关的几个值都为 0 ,表明当前未配值 HugePages ,其次可以看到
[root@rehl6 ~]#
AnonHugePages: 1142784 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
修改用户的memlock 限制
通过修改 /etc/security/limits.conf 配值文件来实现
该参数的值通常配值位略小于当前的已安装系统内存,如当前你的系统内存为 64GB ,可以做如下设置
* soft memlock 60397977
* hard memlock 60397977
上述的设置单位为 kb ,不会降低系统性能。至少也要配值为略大于系统上所有 SGA 的总和。
使用 ulimit -l 来校验该设置
禁用AMM(Oracle 11g)
如果当前的 Oracle 版本为 10g ,可以跳过此步骤。
如果当前的 Oracle 版本为 11g ,由于 AMM(Automatic Memory Management) 特性与 Hugepages 不兼容,需要禁用 AMM 。
ALTER SYSTEM RESET memory_target SCOPE=SPFILE;
ALTER SYSTEM RESET memory_max_target SCOPE=SPFILE;
ALTER SYSTEM SET sga_target=<n>g SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target=<n>g SCOPE=SPFILE;
SHUTDOWN IMMEDIATE;
STARTUP;
计算vm.nr_hugepages 值
简单的计算方法如下:(只做系统估计)
简单的计算原理是 total SGA_MAX_SIZE( 多个 instance 的总和) /hugepagesize + N
N 为少量内存盈余,一般多出 100 就足够了。如果主机内存 128GB ,计划 70GB 用于 SGA 共享内存,则大内存页需 70×1024/2=35840
使用 Oracle 提供的脚本 hugepages_settings.sh 的脚本来计算 vm.nr_hugepages 的值(这个值设置的是 hugepage momory 的大小)
在执行脚本之前确保所有的 Oracle 实例已启动以及 ASM 也启动 ( 存在的情形下 )
$ ./hugepages_settings.sh
该文档脚本可以参看 MOS 文档,附录一提供摘录
:
Shell Script to Calculate Values Recommended Linux HugePages / HugeTLB Configuration ( 文档 ID 401749.1)
设置vm.nr_hugepages 参数
编辑 /etc/sysctl.conf 来设置 vm.nr_hugepages 参数
$ sysctl -w vm.nr_hugepages = 1496 (该值为上述脚本获得的值, vm.nr_hugepages 指明了内存页数)
$ sysctl -p
重启实例及服务:
上述的所有步骤已经实现了动态修改,但对于 HugePages 的分配需要重新启动主机 server 才能生效。
验证
HugePages 相关参数的值会随着当前服务器上的实例的停止与启动而动态发生变化
通常情况下, HugePages_Free 的值应当小于 HugePages_Total 的值,在 HugePages 被使用时 HugePages_Rsvd 值应当为非零值。
$ grep Huge /proc/meminfo
HugePages_Total: 131
HugePages_Free: 20
HugePages_Rsvd: 20
Hugepagesize: 2048 kB
如下面的情形,当服务器上仅有的一个实例被关闭后, HugePages_Rsvd 的值为零。且 HugePages_Free 等于 HugePages_Total
$ grep Huge /proc/meminfo
HugePages_Total: 131
HugePages_Free: 131
HugePages_Rsvd: 0
Hugepagesize: 2048 kB
后续备注 :
/etc/security/limits.conf 配值文件中 memlock 参数的值通常配值位略小于当前的已安装系统内存
2. Hugepagesize LINUX 的大页的大小为 2M 这是不能改变的,而且大页在 oracle 服务器上只与参数 sga_max_size 有关, hugepage 目前只能用于共享内存段等少量内存类型,例如 oracle SGA 。 PGA 则不适用,所以不能随便乱设置大页内容,如果没有 oracle 提供的脚本,我们只需要简单的计算原理: total SGA_MAX_SIZE( 多个 instance 的总和) /hugepagesize + N N 为稍微超出一点的内存大小,如果主机内存 128GB ,计划 70GB 用于 SGA 共享内存,则大内存页需 70×1024/2=35840
vm.nr_hugepages 参数指定了大页的数目,大页数目 *2 ( 2048K 大页每页的大小)就是可以使用的内存大页总大小。
huge page 的大小 huge page 的大小取决于所使用的操作系统的内核版本以及不同的硬件平台 可以使用 $grep Hugepagesize /proc/meminfo 来查看 huge page 的大小 下面是不同平台常用的 huge page 的大小。 HW Platform Source Code Tree Kernel 2.4 Kernel 2.6 ----------------- --------------------- ------------ ------------- Linux x86 (IA32) i386 4 MB 4 MB * Linux x86-64 (AMD64, EM64T) x86_64 2 MB 2 MB Linux Itanium (IA64) ia64 256 MB 256 MB IBM Power Based Linux (PPC64) ppc64/powerpc N/A ** 16 MB IBM zSeries Based Linux s390 N/A 1 MB IBM S/390 Based Linux s390 N/A N/A
附录
附录一
( 该脚本不同版本或许会有些许变化,建议参考文件重新下载)
hugepages_settings.sh
|
#!/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. # # This script is provided by Doc ID 401749.1 from My Oracle Support #
# Welcome text echo " This script is provided by Doc ID 401749.1 from My Oracle Support () where it is intended to compute values for the recommended HugePages/HugeTLB configuration for the current shared memory segments. 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.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" ;; *) echo "Unrecognized kernel version $KERN. Exiting." ;; esac
# End |
