oracle hugepage設置

HugePages是通過使用大頁內存來取代傳統的4kb內存頁面,使得管理虛擬地址數變少,加快了從虛擬地址到物理地址的映射以及通過摒棄內存頁面的換入換出以提高內存的整體性能。尤其是對於8GB以上的內存以及較大的Oracle SGA size,建議配值並使用HugePage特性。本文基於x86_64 Linux下來描述如何配值 HugePages。
    有關HugePages的特性請參考:Linux HugePage 特性
  
1、爲什麼需要配值HugePages ?


2、配值HugePages
  下面列出了配值HugePages的所有步驟
a、查看當前系統是否配值HugePages
  下面的查詢中HugePages相關的幾個值都爲0,表明當前未配值HugePages,其次可以看到Hugepagesize爲2MB。
  $ grep Huge /proc/meminfo
  HugePages_Total:   0
  HugePages_Free:    0
  HugePages_Rsvd:    0
  Hugepagesize:     2048 kB
    
b、修改用戶的memlock限制
  通過修改/etc/security/limits.conf 配值文件來實現
  該參數的值通常配值位略小於當前的已安裝系統內存,如當前你的系統內存爲64GB,可以做如下設置
  *   soft   memlock    60397977
  *   hard   memlock    60397977


  *   soft   memlock    5397977
  *   hard   memlock    5397977


  上述的設置單位爲kb,不會降低系統性能。至少也要配值爲略大於系統上所有SGA的總和。
  使用ulimit -l 來校驗該設置
 
c、禁用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;


SQL> show parameter sga


NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
lock_sga                             boolean     FALSE
pre_page_sga                         boolean     FALSE
sga_max_size                         big integer 2000M
sga_target                           big integer 2000M
SQL> 
SQL> 
SQL> show parameter mem


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
SQL> 


    
d、計算vm.nr_hugepages 的值    
  使用Oracle 提供的腳本hugepages_settings.sh的腳本來計算vm.nr_hugepages的值
  在執行腳本之前確保所有的Oracle 實例已啓動以及ASM也啓動(存在的情形下)
  $ ./hugepages_settings.sh
  ...
  Recommended setting: vm.nr_hugepages = 1496
 
e、 編輯/etc/sysctl.conf 來設置vm.nr_hugepages參數
  $ sysctl -w vm.nr_hugepages = 1496  
  $ sysctl -p
  
  -- Author : Robinson
  -- Blog   : http://blog.csdn.net/robinson_0612
  
f、停止所有的Instance並重啓server
  上述的所有步驟已經實現了動態修改,但對於HugePages的分配需要重新啓動server才能生效。
 
h、驗證配值
  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   
 
3、使用HugePages的注意事項
  下面的三種情形應當重新配置HugePages
    a、物理內存的增減或減少
    b、在當前服務器上新增或移出Instance
    c、Instance的SGA大小增加或減少   
  如果未能調整HugePages,可能會引發下面的問題
    a、數據庫性能地下
    b、出現內存不足或者過度使用交換空間
    c、數據庫實例不能被啓動
    d、關鍵性系統服務故障
   
4、HugePages特性的常見故障處理


設置了大頁,但沒被Oracle使用,原因只有兩個:
1,SGA_MAX_SIZE超過了大頁
2,沒有設置內存鎖
內存:是進程活動的舞臺,ORACLE數據庫在startup時會自動去查找是否設置有大頁。
如有,在大頁中分配SGA。
如沒有,則正常使用默認數據塊大小啓動。


 
5、計算vm.nr_hugepages 值的腳本
[python] view plaincopyprint?
#!/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   
# 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. 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  
HugePages是通過使用大頁內存來取代傳統的4kb內存頁面,使得管理虛擬地址數變少,加快了從虛擬地址到物理地址的映射以及通過摒棄內存頁面的換入換出以提高內存的整體性能。尤其是對於8GB以上的內存以及較大的Oracle SGA size,建議配值並使用HugePage特性。本文基於x86_64 Linux下來描述如何配值 HugePages。
    有關HugePages的特性請參考:Linux HugePage 特性
  
1、爲什麼需要配值HugePages ?

2、配值HugePages
  下面列出了配值HugePages的所有步驟
a、查看當前系統是否配值HugePages
  下面的查詢中HugePages相關的幾個值都爲0,表明當前未配值HugePages,其次可以看到Hugepagesize爲2MB。
  $ grep Huge /proc/meminfo
  HugePages_Total:   0
  HugePages_Free:    0
  HugePages_Rsvd:    0
  Hugepagesize:     2048 kB
    
b、修改用戶的memlock限制
  通過修改/etc/security/limits.conf 配值文件來實現
  該參數的值通常配值位略小於當前的已安裝系統內存,如當前你的系統內存爲64GB,可以做如下設置
  *   soft   memlock    60397977
  *   hard   memlock    60397977

  *   soft   memlock    5397977
  *   hard   memlock    5397977

  上述的設置單位爲kb,不會降低系統性能。至少也要配值爲略大於系統上所有SGA的總和。
  使用ulimit -l 來校驗該設置
 
c、禁用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;

SQL> show parameter sga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
lock_sga                             boolean     FALSE
pre_page_sga                         boolean     FALSE
sga_max_size                         big integer 2000M
sga_target                           big integer 2000M
SQL> 
SQL> 
SQL> show parameter mem

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
SQL> 

    
d、計算vm.nr_hugepages 的值    
  使用Oracle 提供的腳本hugepages_settings.sh的腳本來計算vm.nr_hugepages的值
  在執行腳本之前確保所有的Oracle 實例已啓動以及ASM也啓動(存在的情形下)
  $ ./hugepages_settings.sh
  ...
  Recommended setting: vm.nr_hugepages = 1496
 
e、 編輯/etc/sysctl.conf 來設置vm.nr_hugepages參數
  $ sysctl -w vm.nr_hugepages = 1496  
  $ sysctl -p
  
  -- Author : Robinson
  -- Blog   : http://blog.csdn.net/robinson_0612
  
f、停止所有的Instance並重啓server
  上述的所有步驟已經實現了動態修改,但對於HugePages的分配需要重新啓動server才能生效。
 
h、驗證配值
  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   
 
3、使用HugePages的注意事項
  下面的三種情形應當重新配置HugePages
    a、物理內存的增減或減少
    b、在當前服務器上新增或移出Instance
    c、Instance的SGA大小增加或減少   
  如果未能調整HugePages,可能會引發下面的問題
    a、數據庫性能地下
    b、出現內存不足或者過度使用交換空間
    c、數據庫實例不能被啓動
    d、關鍵性系統服務故障
   
4、HugePages特性的常見故障處理

設置了大頁,但沒被Oracle使用,原因只有兩個:
1,SGA_MAX_SIZE超過了大頁
2,沒有設置內存鎖
內存:是進程活動的舞臺,ORACLE數據庫在startup時會自動去查找是否設置有大頁。
如有,在大頁中分配SGA。
如沒有,則正常使用默認數據塊大小啓動。

 
5、計算vm.nr_hugepages 值的腳本
[python] view plaincopyprint?
#!/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   
# 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. 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  



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章