在Linux中配置hugepage可以提高oracle的性能,減少Oracle sga的頁交換,類似於aix中的lagepage。
下面演示配置hugepage的方法。
系統環境:
OS:CentOS5 x86
Oracle:10.2.0.1
配置過程
檢查hugepagesize
ora_test@root[/root]> grep Hugepagesize /proc/meminfo
Hugepagesize: 4096 kB
配置分配hugepage的數量
nr_hugepages的計算公式:nr_hugepages>=sga(mb)/Hugepagesize(mb)
ora_test@root[/root]> echo 50 > /proc/sys/vm/nr_hugepages
ora_test@root[/root]> sysctl -w vm.nr_hugepages=50
vm.nr_hugepages = 50
ora_test@root[/root]> echo "vm.nr_hugepages=50" >> /etc/sysctl.conf
檢查hugepage的分配情況
ora_test@root[/root]> grep HugePages_Total /proc/meminfo
HugePages_Total: 6
這裡顯示的值為6,小於我配置的數量50,所以需要重啟
ora_test@root[/root]> reboot Broadcast message from root (pts/1) (Mon Jan 25 09:38:04 2010): The system is going down for reboot NOW!
重啟之後,檢查hugepage的分配情況
ora_test@root[/root]> grep HugePages_Total /proc/meminfo
HugePages_Total: 50
現在確認hugepage已經分配了50個單位(50×4096kb=200mb)
http://cnhtm.itpub.Net/post/39970/496273
配置Oracle用戶的memlock
需要修改/etc/security/limits.conf文件,加入標記為紅色的兩行
計算公式為:>=HugePages_Total×1024,我這裡設置了2倍的值,即:2×50×1024=102400
ora_test@root[/root]> cat /etc/security/limits.conf|grep lock
# - memlock - max locked-in-memory address space (KB)
# - locks - max number of file locks the user can hold
Oracle soft memlock 102400
Oracle hard memlock 102400
檢查memlock情況
切換到Oracle用戶身份,使用ulimit -l命令檢查memlock情況
ora_test@root[/root]> su - Oracle
ora_test@oracle[/home/Oracle]> ulimit -l
102400
啟動數據庫
ora_test@Oracle[/home/oracle]> sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jan 25 09:50:33 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to an idle instance. idle> startup
Oracle instance started. Total System Global Area 167772160 bytes
Fixed Size 1218292 bytes
Variable Size 67111180 bytes
Database Buffers 92274688 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.
idle> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
檢查是否已經使用了hugepage
ora_test@oracle[/home/Oracle]> grep HugePages_Free /proc/meminfo
HugePages_Free: 30
這裡顯示剩余的hugepage為30,小於HugePages_Total(50),證明Oracle已經使用了hugepage
--end--
為何oracle一起來,系統就會有swap? db是11g,total memory 是16g ,swap 是8g,分給sga_target=8g,pga_aggregate_target=3g.按理說,這個內存分配也不會導致Oracle吞噬過多內存導致系統發生swap,可現在只要db起來,用vmsta 命令觀察就會出現swap, 類似如下。
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 168524 87336 340 26356 128 3014 178 3054 1305 417 0 1 94 5 0
0 3 168524 81336 480 29052 1798 0 3166 8 1243 687 0 0 94 6 0
0 0 171024 85292 496 28984 880 1500 1176 1500 1225 612 0 0 89 11 0
0 0 171024 85292 496 28960 24 0 24 0 1055 348 0 0 99 0 0
0 3 172284 81960 512 34860 372 1158 430 1230 1307 1496 0 2 94 4 0
0 1 167072 84424 320 38828 1564 210 1716 230 1545 2796 0 3 85 12 0
0 1 167072 84008 340 39152 286 0 362 18 1115 504 0 0 96 4 0
0 0 167072 83764 352 39392 34 0 94 6 1069 344 0 0 99 0 0
0 0 167072 83764 352 39580 32 0 32 0 1072 347 0 0 100 0 0
0 0 167072 82896 352 39568 410 0 410 0 1075 367 0 0 99 1 0
我看了alert log,沒有其他報錯。現在系統非常慢,大伙幫我分析分析。 QUOTE: 原帖由 Oracle_kai 於 2010-12-7 18:28 發表 系統使用的就是hugepage,但問題也就出現在hugepage 參數的設置上面。原先vm.nr_hugepages = 41984
cat /proc/memory|grep HugePages_Total HugePages_Total=7925 7925*2m 幾乎就是整個os內存了。後來修改該參數,參考sga=8g,所以新設vm.nr_hugepages =4096 重啟機器,Oracle起來後memory swap 消失,系統反應也正常。
#!/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 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}'` # Initialize the counter
NUM_PG=0 # 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 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
hugepage是不能被swap的,並且,系統啟動後就被占用。你的這個問題就是hugepage過大,導致可用內存過小。 HugePages are not swappable. Therefore there is no page-in/page-out mechanism overhead.HugePages are universally regarded as pinned. metalink Doc ID: 361323.1