一·为什么需要大页面?
如果您有一个大的RAM和SGA,那么HugePages对于Linux上更快的Oracle数据库性能是至关重要的。如果您的组合数据库SGAs很大(比如超过8GB,甚至对于更小的数据库也很重要),则需要配置更大的页面。请注意,SGA的大小很重要。HugePages的优势有:
更大的页面大小和更少的页面数量:默认页面大小为4K,而HugeTLB大小为2048K。这意味着系统需要处理512倍的页面。
减少页表遍历:由于HugePage比常规大小的页面包含更大的连续虚拟地址范围,因此使用HugePages的每个TLB条目被TLB命中的概率要高于使用常规页面。这减少了从虚拟地址获取物理地址遍历页面表的次数。
减少内存操作的开销:在虚拟内存系统(任何现代操作系统)上,每个内存操作实际上是两个抽象的内存操作。使用HugePages,由于要处理的页面数量较少,因此显然避免了页面表访问上可能出现的瓶颈。
内存使用量更少:从Oracle数据库的角度来看,与常规大小的页面相比,Linux内核将使用更少的内存来创建pagetables,以维护SGA地址范围的虚拟到物理映射。这使得更多的内存可用于进程私有计算或PGA使用。
无交换:在所有文档1295478.1中,我们必须避免在Linux操作系统上发生交换。大页是不可交换的(而常规页是可交换的)。因此,不存在页面替换机制开销。大页通常被认为是固定的。
没有“kswapd”操作:如果有一个非常大的区域需要分页(例如,对于50GB内存有1300万个页表条目),那么kswapd将非常繁忙,并且会使用大量的CPU资源。当使用HugePages时,kswapd不参与管理它们。另见文件361670.1
二、大页配置(Doc ID 361468.1)
1.设置内存锁,假如我这里64G内存,设置如下,值单位kb
* soft memlock 60397977
* hard memlock 60397977
2.检查设置的值
$ ulimit -l
60397977
3.关闭AMM
oracle11g以后默认自动内存管理( Automatic Memory Management (AMM)),跟这个大页设置冲突了,所以需要关闭AMM. 需要把MEMORY_TARGET and MEMORY_MAX_TARGET 这2个参数设置为 0,如果已经是0就不用设置了
06:55:02 SYS@db01> show parameter memory
NAME TYPE VALUE
------------------------------------ ------------------------------ ------------------------------
hi_shared_memory_address integer 0
memory_max_target big integer 0
memory_target big integer 0
shared_memory_address integer 0
如果不为0则需要设置
alter system reset memory_max_target scope=spfile sid='*';
4. 使用推荐脚本计算vm.nr_hugepages 的值
$ ./hugepages_settings.sh
...
Recommended setting: vm.nr_hugepages = 1496
5.进行设置vm.nr_hugepages
vi /etc/sysctl.conf
vm.nr_hugepages = 1496
6.停止数据库,重启操作系统
7.检查和验证配置
# grep HugePages /proc/meminfo
HugePages_Total: 1496
HugePages_Free: 485
HugePages_Rsvd: 446
HugePages_Surp: 0
三、使用官方脚本计算出推荐设置大页值,参考Doc ID 401749.1
#!/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