HugePages是通過使用大頁記憶體來取代傳統的4kb記憶體頁面,使得管理虛拟位址數變少,加快了從虛拟位址到實體位址的映射以及通過摒棄記憶體頁面的換入換出以提高記憶體的整體性能。尤其是對于8GB以上的記憶體以及較大的Oracle SGA size,建議配值并使用HugePage特性。本文基于x86_64 Linux下來描述如何配值 HugePages。
一、 為oracle伺服器配置Hugepages
1.1、檢視目前系統是否配值HugePages
下面的查詢中HugePages相關的幾個值都為0,表明目前未配值HugePages,其次可以看到Hugepagesize為2MB。
$ grep Huge /proc/meminfo
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB
1.2、修改使用者的memlock限制
通過修改/etc/security/limits.conf 配值檔案來實作
該參數的值通常配值位略小于目前的已安裝系統記憶體,如目前你的系統記憶體為64GB,可以做如下設定
* soft memlock 60397977
* hard memlock 60397977
上述的設定機關為kb,不會降低系統性能。至少也要配值為略大于系統上所有SGA的總和。
使用ulimit -l 來校驗該設定
1.3、禁用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;
-----------------------------------------------------------------
禁用memory_max_target和memory_target參數方法
這裡注意,官方文檔說的是“unset” ,直接alter system set memory_target=0 scope=spfile;是更改不成功的。直接設定為‘0’,就抱如下的錯誤
ORA-00843: Parameter not taking MEMORY_MAX_TARGET into account
ORA-00849: SGA_TARGET 35433480192 cannot be set to more than MEMORY_MAX_TARGET 0.
ORA-01078: failure in processing system parameters
通過建立pfile.ora檔案,然後在檔案裡删除兩個參數"MEMORY_TARGET/MEMORY_MAX_TARGET"。然後再建立spfile就可以了。
1.4、計算vm.nr_hugepages 的值
使用Oracle 提供的腳本hugepages_settings.sh的腳本來計算vm.nr_hugepages的值
在執行腳本之前確定所有的Oracle 執行個體已啟動以及ASM也啟動(存在的情形下)
若HugePages配置可行,他就會推薦一個記憶體大小,若不可行則報錯
$ ./hugepages_settings.sh (具體腳本在下面)
...
Recommended setting: vm.nr_hugepages = 1496 ( sga_m / 4m + 3 )
1.5、 編輯/etc/sysctl.conf 來設定vm.nr_hugepages參數
$ sysctl -w vm.nr_hugepages = 1496
$ sysctl -p
1.6、停止所有的Instance并重新開機server
上述的所有步驟已經實作了動态修改,但對于HugePages的配置設定需要重新啟動server才能生效。
1.7、驗證配值
HugePages相關參數的值會随着目前伺服器上的執行個體的停止與啟動而動态發生變化
通常情況下,HugePages_Free的值應當小于HugePages_Total的值,在HugePages被使用時HugePages_Rsvd值應當為非零值。
HugePages_Total: 131
HugePages_Free: 20
HugePages_Rsvd: 20
Hugepagesize: 2048 kB
如下面的情形,當伺服器上僅有的一個執行個體被關閉後,HugePages_Rsvd的值為零。且HugePages_Free等于HugePages_Total
HugePages_Free: 131
二、使用HugePages的注意事項
下面的三種情形應當重新配置HugePages
a、實體記憶體的增減或減少
b、在目前伺服器上新增或移出Instance
c、Instance的SGA大小增加或減少
如果未能調整HugePages,可能會引發下面的問題
a、資料庫性能地下
b、出現記憶體不足或者過度使用交換空間
c、資料庫執行個體不能被啟動
d、關鍵性系統服務故障
三、HugePages特性的常見故障處理
Symptom A:
System is running out of memory or swapping
Possible Cause:
Not enough HugePages to cover the SGA(s) and therefore the area reserved for HugePages are wasted where SGAs are allocated through regular pages.
Troubleshooting Action:
Review your HugePages configuration to make sure that all SGA(s) are covered.
Symptom B:
Databases fail to start
Possible Cause:
memlock limits are not set properly
Make sure the settings in limits.conf apply to database owner account.
Symptom C:
One of the database fail to start while another is up
The SGA of the specific database could not find available HugePages and remaining RAM is not enough.
Make sure that the RAM and HugePages are enough to cover all your database SGAs
Symptom D:
Cluster Ready Services (CRS) fail to start
HugePages configured too large (maybe larger than installed RAM)
Troubleshooting Action:
Make sure the total SGA is less than the installed RAM and re-calculate HugePages.
Symptom E:
HugePages_Total = HugePages_Free
HugePages are not used at all. No database instances are up or using AMM.
Disable AMM and make sure that the database instances are up.
Symptom F:
Database started successfully and the performance is slow
The SGA of the specific database could not find available HugePages and therefore the SGA is handled by regular pages, which leads to slow performance
Make sure that the HugePages are many enough to cover all your database SGAs
Reference: [ID 361468.1]
四、如何控制資料庫SGA是否使用Hugepages?
11.2.0.2之前的版本,database的SGA隻能選擇全部使用hugepages或者完全不使用hugepages。
11.2.0.2 及以後的版本, oracle增加了一個新的參數“USE_LARGE_PAGES”來管理資料庫如何使用 hugepages.
USE_LARGE_PAGES參數有三個值: "true" (default), "only", "false" and "auto"(since 11.2.0.3 patchset).
1. 現在預設值是"true",如果系統設定Hugepages的話,SGA會優先使用hugepages,有多少用多少。
11.2.0.2 如果沒有足夠的 hugepages, SGA是不會使用hugepages的. 這會導緻ORA-4030錯誤,因為hugepages已經從實體記憶體配置設定,但是SGA沒有使用它,卻使用其他部分記憶體,導緻記憶體資源不足
但是在11.2.0.3版本這個使用政策被改變了,SGA可以一部分使用hugepages,剩餘部分使用small pages。這樣,SGA會有限使用hugepages,在hugepages用完之後,再使用regular sized pages。
2. 如果設定為"false" , SGA就不會使用hugepages
3. 如果設定為 "only" 如果hugepages大小不夠的話,資料庫執行個體是無法啟動的 (防止記憶體溢出的情況發生).
4. 11.2.0.3版本之後,可以設定為 "auto".這個選項會觸發oradism程序重新配置linux核心,以增加hugepages的數量。Oradism需要被賦予相應的權限,如下
-rwsr-x--- 1 root <oracle group>
它不會去改變/etc/sysctl.conf檔案中的hugepages值,當OS重新開機後,系統會再恢複到/etc/sysctl.conf中配置的hugepages值。
五、注意事項
a、HugePage使用的是共享記憶體,在作業系統啟動期間被動态配置設定并被保留,因為他們不會被置換。
b、由于不會被置換的特點,在使用hugepage的記憶體不能被其他的程序使用。是以要合理設定該值,避免造成記憶體浪費。
c、對于隻使用Oracle的伺服器來說,把Hugepage設定成SGA(所有instance SGA之和)大小即可。
d、如果增加HugePage或添加實體記憶體或者是目前伺服器增加了新的instance以及SGA發生變化,應該重新設定所需的HugePage。
-- 補充 hugepages_settings.sh 腳本
#!/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 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`
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 "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:
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"
# Finish with results
case $KERN in
'2.2') echo "Kernel version $KERN is not supported. Exiting." ;;
'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" ;;
esac
# End
結果如下
[oracle@n3 ~]$ chmod +x hugepages_settings.sh
[oracle@n3 ~]$ sh hugepages_settings.sh
Press Enter to proceed...
Recommended setting: vm.nr_hugepages = 125447
文章可以轉載,必須以連結形式标明出處。
本文轉自 張沖andy 部落格園部落格,原文連結: http://www.cnblogs.com/andy6/p/7481721.html ,如需轉載請自行聯系原作者