大页内存(hugepages)
为优化内存管理引入了hugepages 可以自定义设置、将原来标准内存也4k设置为更大。
hugepages 优点:
使得Oracle SGA 不可交换;
减轻 TLB 的压力;
减少页表的开销;
减少页表查询的开销;
提升内存访问的整体性能;
oracle建议设置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=</span><span class="token function">uname</span> -r <span class="token operator">|</span> <span class="token function">awk</span> -F. <span class="token string">'{ printf("%d.%d\n",$1,$2); }'</span><span class="token variable">
# Find out the HugePage size
HPG_SZ=</span><span class="token function">grep</span> Hugepagesize /proc/meminfo <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{print $2}'</span><span class="token variable">
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 </span>ipcs -m <span class="token operator">|</span> <span class="token function">cut</span> -c44-300 <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{print $1}'</span> <span class="token operator">|</span> <span class="token function">grep</span> <span class="token string">"[0-9][0-9]*"</span><span class="token variable">
do
MIN_PG=</span><span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">$SEG_BYTES</span>/(<span class="token variable">$HPG_SZ</span>*1024)"</span> <span class="token operator">|</span> <span class="token function">bc</span> -q<span class="token variable">
if [ \(MIN_PG</span> -gt <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token keyword">then</span>
<span class="token assign-left variable">NUM_PG</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">\)NUM_PG+$MIN_PG+1" | bc -q`
fi
done
RES_BYTES=</span><span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">$NUM_PG</span> * <span class="token variable">$HPG_SZ</span> * 1024"</span> <span class="token operator">|</span> <span class="token function">bc</span> -q<span class="token variable">
# 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</span> <span class="token keyword">in</span>
<span class="token string">'2.4'</span><span class="token punctuation">)</span> <span class="token assign-left variable">HUGETLB_POOL</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">\)NUM_PG*\(HPG_SZ</span>/1024"</span> <span class="token operator">|</span> <span class="token function">bc</span> -q<span class="token variable">`</span></span><span class="token punctuation">;</span>
<span class="token builtin class-name">echo</span> <span class="token string">"Recommended setting: vm.hugetlb_pool = <span class="token variable">\)HUGETLB_POOL" ;;
'2.6') echo "Recommended setting: vm.nr_hugepages = \(NUM_PG</span>"</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token string">'3.8'</span><span class="token punctuation">)</span> <span class="token builtin class-name">echo</span> <span class="token string">"Recommended setting: vm.nr_hugepages = <span class="token variable">\)NUM_PG" ;;
'3.10') echo "Recommended setting: vm.nr_hugepages = \(NUM_PG</span>"</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token string">'4.1'</span><span class="token punctuation">)</span> <span class="token builtin class-name">echo</span> <span class="token string">"Recommended setting: vm.nr_hugepages = <span class="token variable">\)NUM_PG" ;;
'4.14') echo "Recommended setting: vm.nr_hugepages = \(NUM_PG</span>"</span> <span class="token punctuation">;</span><span class="token punctuation">;</span>
*<span class="token punctuation">)</span> <span class="token builtin class-name">echo</span> <span class="token string">"Kernel version <span class="token variable">\)KERN is not supported by this script (yet). Exiting." ;;
esac
# End
配置 memlock(可选)
限制用户内存使用值(可以比SGA略大)
vi /etc/security/limits.conf
oracle hard memlock xxxxx
oracle soft memlock xxxxx
运行脚本hugepages_settings.sh计算推荐页大小
./hugepages_settings.sh
- 1
根据值设置/etc/sysctl.conf文件末尾添加
vi /etc/sysctl.conf
vm.nr_hugepages=xxxxxx
#退出后
sysctl -p #生效
禁用AMM(Oracledb需设置)
因为Oracle自动内存管理的AMM特性与hugetlbfs不兼容、所以需要禁用这个特性,但是可以使用SGA自动管理。
具体做法将MEMORY_TARGET/MEMORY_MAX_TARGET设置为0,并且手工指定SGA_TARGET/SGA_MAX_SIZE/PGA_AGGREGATE_TARGET的值。
重启数据库生效(Oracledb需重启)
lsnrctl stop
shutdow immediate
startup
lsnrctl start