oracle数据库HugePages配置
HugePages是集成到Linux kernel 2.6中的一個功能。啟用HugePages可以使用操作系統來支持比缺省的內存頁(4KB)更大的內存頁。使用非常大的內存頁大小可以通過減少訪問頁表條目所需要的系統資源數量而提高系統性能。HugePages對于32位與64位系統都是有效的。HugePage的大小范圍從2MB到256MB,依賴于內核版本和硬件架構。對于Oracle數據庫,使用HugePages減少操作系統維護內存頁
狀態并增加Translation Lookaside Buffer(TLB)的撞擊率。
1.使用HugePages來優化SGA
不使用HugePages時,操作系統將保持每個內存頁大小為4KB,當為SGA分配內存頁時,操作系統內核必須對分配給SGA的每個4KB頁使用頁生命周期(臟,可用,映射到進程,等等)持續更新。
使用HugePages時,操作系統頁表(虛擬內存到物理內存的映射)很小,因為每個頁表條目指向的內存頁大小從2MB到256MB。同時內核有比較少的內存頁生命周期被監控。例如,如果64位硬件使用HugePages,并且想要映射256MB的內存,你可能只需要一個頁表條目(PTE)。如果不使用HugePages并且想要映射256MB內存,那么必須有256*1024KB/4KB=65536個PTEs。
HugePages提供了以下優點:
通過增加TLB撞擊率來提高性能
內存頁被鎖定在內存中并且不會發生交換,對共享內存結構比如SGA提供了隨機訪問
連續內存頁預分配除了用于系統的共享內存比如SGA不能用于其它的目的
因為使用大的內存頁大小所以虛擬內存相關的內核有較少性能開銷
-------------啟用hugepages,數據庫在asmm下運行
數據庫實例在啟動狀態下
運行 sh /tmp/hugepages_settings.sh
根據hugepages_settings.sh的輸出值對內核參數vm.nr_hugepages進行設置
例如:Recommended setting: vm.nr_hugepages = 160264
設置在/etc/sysctl.conf 文件尾部添加或修改參數
vm.nr_hugepages = 160264
2 對Linux配置HugePages
運行以下命令來判斷內核是否支持HugePages:
有一些Linux缺省情況下是不支持HugePages的。 對于這樣的系統使用config_hugetlbfs和config_hugetlb_page配置選項來構建Linux內核。config_hugetlbfs位于文件系統并且當你選擇config_hugetlbfs時需要同時選擇config_hugetlb_page。
編輯/etc/security/limits.conf文件來設置memlock。memlock設置以KB為單位,并且當啟用HugePages內存時,最大鎖定內存限制應該被設置為當前可隨機訪問內存的90%,當沒有啟用HugePages內存時,最大鎖定內存限制應該被設置成至少3145728KB(3GB)。例如,如果有2G可隨機訪問內存,并且增加以下條目來增加最大鎖定內存地址空間:
[root@jyrac1 ~]# vi /etc/security/limits.conf grid soft memlock 2097152 grid hard memlock 2097152 oracle soft memlock 2097152 oracle hard memlock 2097152也可以將memlock的值設置為比SGA的值大
以grid用戶登錄,并執行ulimit -l命令來驗證新設置的memlock是否生效
[grid@jyrac1 ~]$ ulimit -l 2097152以oracle用戶登錄,并執行ulimit -l命令來驗證新設置的memlock是否生效
[oracle@jyrac1 ~]$ ulimit -l 2097152運行以下命令來顯示Hugepagesize變量:
[oracle@jyrac1 ~]$ grep Hugepagesize /proc/meminfo Hugepagesize: 2048 kB完成以下過程來創建一個腳本用來為當前共享內存段計算hugepages配置的建議值創建一個hugepages_settings.sh腳本并增加以下內容:
[root@jyrac1 /]# vi 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 -mPress 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" ];thenecho "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]*"` doMIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`if [ $MIN_PG -gt 0 ]; thenNUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`fi doneRES_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 ]; thenecho "***********"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 -mof 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.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執行以下命令來改變hugepages_settings.sh腳本的權限
[root@jyrac1 /]# chmod +x hugepages_settings.sh運行hugepages_settings.sh腳本來計算hugepages配置的參數值
[root@jyrac1 /]# ./hugepages_settings.sh 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 -mPress Enter to proceed...*********** ** ERROR ** *********** 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 -mof 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從上面的信息可以看到需要確認Oracle實例是否正在運行,如果是Oracle 11g不能使用AMM
[root@jyrac1 ~]# ps -ef | grep pmon grid 4116 1 0 Apr18 ? 00:00:03 asm_pmon_+ASM1 oracle 4944 1 0 Apr18 ? 00:00:03 ora_pmon_jyrac1 root 18184 29273 0 15:15 pts/1 00:00:00 grep pmon上面信息可以看到Oracle實例正在運行。
[grid@jyrac1 ~]$ sqlplus / as sysasmSQL*Plus: Release 11.2.0.4.0 Production on Wed Apr 20 15:20:23 2016Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production With the Real Application Clusters and Automatic Storage Management optionsSQL> set long 900 SQL> set linesize 900 SQL> show parameter instance_nameNAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ instance_name string +ASM1SQL> show parameter memoryNAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ memory_max_target big integer 1076M memory_target big integer 1076M [oracle@jyrac1 ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Wed Apr 20 15:21:04 2016Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing optionsSQL> set long 900 SQL> set linesize 900 SQL> show parameter instance_nameNAME TYPE VALUE ------------------------------------ ----------- ------------------------------ instance_name string jyrac1 SQL> show parameter memoryNAME TYPE VALUE ------------------------------------ ----------- ------------------------------ hi_shared_memory_address integer 0 memory_max_target big integer 2G memory_target big integer 2G shared_memory_address integer 0確實asm與數據庫實例都啟用了AMM,需要禁用AMM但是可以使用ASMM修改ASM實例,禁用AMM,但使用ASMM,如果是RAC所有節點都需要修改
SQL> alter system set sga_max_size=640M scope=spfile sid='*';System altered.SQL> alter system set sga_target=640M scope=spfile sid='*';System altered.SQL> alter system set pga_aggregate_target=320M scope=spfile sid='*';System altered.SQL> alter system set memory_target=0 scope=spfile sid='*';System altered.#這里對于memory_target不能使用reset否則會出現以下錯誤:SQL> startup ORA-01078: failure in processing system parameters ORA-00843: Parameter not taking MEMORY_MAX_TARGET into account ORA-00849: SGA_TARGET 671088640 cannot be set to more than MEMORY_MAX_TARGET 0. SQL> alter system reset memory_max_target scope=spfile sid='*';System altered. #修改數據庫實例,禁用AMM,但使用ASMM,如果是RAC所有節點都需要修改SQL> alter system set sga_max_size=640M scope=spfile sid='*';System altered.SQL> alter system set sga_target=640M scope=spfile sid='*';System altered.SQL> alter system set pga_aggregate_target=320M scope=spfile sid='*';System altered.SQL> alter system reset memory_max_target scope=spfile sid='*';System altered.SQL> alter system reset memory_target scope=spfile sid='*';System altered.重啟ASM與數據庫實例,如果是RAC所有節點都需要重啟,首先停止ASM與數據庫實例
[grid@jyrac1 ~]$ srvctl stop asm -n jyrac1 -f [grid@jyrac1 ~]$ srvctl stop asm -n jyrac2 -f [grid@jyrac1 ~]$ srvctl stop database -d jyrac [grid@jyrac1 ~]$ crsctl stat res -tNAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.CRSDG.dgOFFLINE OFFLINE jyrac1 OFFLINE OFFLINE jyrac2 ora.DATADG.dgOFFLINE OFFLINE jyrac1 OFFLINE OFFLINE jyrac2 ora.LISTENER.lsnrONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.asmOFFLINE OFFLINE jyrac1 Instance Shutdown OFFLINE OFFLINE jyrac2 Instance Shutdown ora.gsdONLINE OFFLINE jyrac1 ONLINE OFFLINE jyrac2 ora.net1.networkONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.onsONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.registry.acfsOFFLINE OFFLINE jyrac1 OFFLINE OFFLINE jyrac2 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr1 ONLINE ONLINE jyrac2 ora.cvu1 ONLINE ONLINE jyrac2 ora.jyrac.db1 OFFLINE OFFLINE Instance Shutdown 2 OFFLINE OFFLINE Instance Shutdown ora.jyrac1.vip1 ONLINE ONLINE jyrac1 ora.jyrac2.vip1 ONLINE ONLINE jyrac2 ora.oc4j1 ONLINE ONLINE jyrac2 ora.scan1.vip1 ONLINE ONLINE jyrac2啟動ASM與數據庫實例
grid@jyrac1 ~]$ sqlplus / as sysasmSQL*Plus: Release 11.2.0.4.0 Production on Wed Apr 20 17:48:32 2016Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to an idle instance.SQL> startup ASM instance startedTotal System Global Area 669581312 bytes Fixed Size 1366724 bytes Variable Size 643048764 bytes ASM Cache 25165824 bytes ASM diskgroups mounted ASM diskgroups volume enabledSQL> show parameter instance_nameNAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ instance_name string +ASM2 SQL> show parameter memoryNAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ memory_max_target big integer 0 memory_target big integer 0 SQL> show parameter sgaNAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ lock_sga boolean FALSE sga_max_size big integer 640M sga_target big integer 640Mgrid@jyrac2 ~]$ sqlplus / as sysasmSQL*Plus: Release 11.2.0.4.0 Production on Wed Apr 20 17:48:32 2016Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to an idle instance.SQL> startup ASM instance startedTotal System Global Area 669581312 bytes Fixed Size 1366724 bytes Variable Size 643048764 bytes ASM Cache 25165824 bytes ASM diskgroups mounted ASM diskgroups volume enabledSQL> show parameter instance_nameNAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ instance_name string +ASM2 SQL> show parameter memoryNAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ memory_max_target big integer 0 memory_target big integer 0 SQL> show parameter sgaNAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ lock_sga boolean FALSE sga_max_size big integer 640M sga_target big integer 640M [grid@jyrac1 ~]$ crsctl stat res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.CRSDG.dgONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.DATADG.dgONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.LISTENER.lsnrONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.asmONLINE ONLINE jyrac1 Started ONLINE ONLINE jyrac2 Started ora.gsdONLINE OFFLINE jyrac1 ONLINE OFFLINE jyrac2 ora.net1.networkONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.onsONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.registry.acfsONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr1 ONLINE ONLINE jyrac1 ora.cvu1 ONLINE ONLINE jyrac1 ora.jyrac.db1 OFFLINE OFFLINE Instance Shutdown 2 OFFLINE OFFLINE Instance Shutdown ora.jyrac1.vip1 ONLINE ONLINE jyrac1 ora.jyrac2.vip1 ONLINE ONLINE jyrac2 ora.oc4j1 ONLINE ONLINE jyrac1 ora.scan1.vip1 ONLINE ONLINE jyrac1從上面的信息可以看到asm實例已經啟動了并且禁用了AMM
[grid@jyrac1 ~]$ srvctl start database -d jyrac [grid@jyrac1 ~]$ crsctl stat res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.CRSDG.dgONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.DATADG.dgONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.LISTENER.lsnrONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.asmONLINE ONLINE jyrac1 Started ONLINE ONLINE jyrac2 Started ora.gsdONLINE OFFLINE jyrac1 ONLINE OFFLINE jyrac2 ora.net1.networkONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.onsONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 ora.registry.acfsONLINE ONLINE jyrac1 ONLINE ONLINE jyrac2 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr1 ONLINE ONLINE jyrac1 ora.cvu1 ONLINE ONLINE jyrac1 ora.jyrac.db1 ONLINE ONLINE jyrac1 Open 2 ONLINE ONLINE jyrac2 Open ora.jyrac1.vip1 ONLINE ONLINE jyrac1 ora.jyrac2.vip1 ONLINE ONLINE jyrac2 ora.oc4j1 ONLINE ONLINE jyrac1 ora.scan1.vip1 ONLINE ONLINE jyrac1 SQL> show parameter instance_nameNAME TYPE VALUE ------------------------------------ ----------- ------------------------------ instance_name string jyrac1 SQL> show parameter memoryNAME 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> show parameter sgaNAME TYPE VALUE ------------------------------------ ----------- ------------------------------ lock_sga boolean FALSE pre_page_sga boolean FALSE sga_max_size big integer 640M sga_target big integer 640MSQL> show parameter instance_nameNAME TYPE VALUE ------------------------------------ ----------- ------------------------------ instance_name string jyrac2 SQL> show parameter memoryNAME 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> show parameter sgaNAME TYPE VALUE ------------------------------------ ----------- ------------------------------ lock_sga boolean FALSE pre_page_sga boolean FALSE sga_max_size big integer 640M sga_target big integer 640M數據庫也已經成功啟動并且禁用了AMM
再次執行hugepages_settings.sh腳本計算HugePages的大小
[root@jyrac1 /]# ./hugepages_settings.sh Recommended setting: vm.nr_hugepages = 649編輯/etc/sysctl.conf文件增加參數vm.nr_hugepages = 649,并執行sysctl -p命令使用修改立即生效,但oracle實例并沒有使用HugePages從HugePages_Total與HugePages_Free相等可以判斷出來。
[root@jyrac1 /]# vi /etc/sysctl.conf vm.nr_hugepages = 649 [root@jyrac1 /]# sysctl -p [root@jyrac1 /]# grep Huge /proc/meminfo HugePages_Total: 649 HugePages_Free: 649 HugePages_Rsvd: 0 Hugepagesize: 2048 kB重啟實例
SQL> startup ASM instance startedTotal System Global Area 669581312 bytes Fixed Size 1366724 bytes Variable Size 643048764 bytes ASM Cache 25165824 bytes ASM diskgroups mounted ASM diskgroups volume enabled查看asm實例的alert_+ASM1.log可以看到如下信息:
Starting ORACLE instance (normal) ************************ Large Pages Information ******************* Per process system memlock (soft) limit = 2048 MBTotal Shared Global Region in Large Pages = 642 MB (100%)Large Pages used by this instance: 321 (642 MB) Large Pages unused system wide = 328 (656 MB) Large Pages configured system wide = 649 (1298 MB) Large Page size = 2048 KB SQL> startup ORACLE instance started.Total System Global Area 669581312 bytes Fixed Size 1366724 bytes Variable Size 243270972 bytes Database Buffers 419430400 bytes Redo Buffers 5513216 bytes Database mounted. Database opened.查看實例jyrac1的alert_jyrac1.log可以看到如下信息:
Starting ORACLE instance (normal) ************************ Large Pages Information ******************* Per process system memlock (soft) limit = 2048 MBTotal Shared Global Region in Large Pages = 642 MB (100%)Large Pages used by this instance: 321 (642 MB) Large Pages unused system wide = 7 (14 MB) Large Pages configured system wide = 649 (1298 MB) Large Page size = 2048 KB [root@jyrac1 /]# grep Huge /proc/meminfo HugePages_Total: 649 HugePages_Free: 239 HugePages_Rsvd: 232 Hugepagesize: 2048 kB從上面的信息可以看到已經使用了Hugepages
3.HugePages的限制
HugePages有以下限制:
a.對于Oracle 11g及以上版本數據庫實例必須對memory_target與memory_max_target參數執行alter system reset命令,但對于ASM實例,對于memory_target參數只能設置為0。
b.AMM與HugePages是不兼容的,當使用AMM,整個SGA內存通過在/dev/shm創建文件來進行內存的分配,當使用AMM分配SGA時,HugePages不會被保留。
c.如果在32位系統中使用VLM,那么對數據庫buffer cache不能使用HugePages。但對于SGA中的其它組件比如shared_pool,
large_pool等等可以使用HugePages。對于VLM(buffer cache)分配內存是通過使用共享內存文件系統(ramfs/tmpfs/shmfs)來實現的。
d.HugePgaes在系統啟動后不受分配或釋放,除非系統管理員通過修改可用頁數或改變池大小來改變HugePages的配置。如果在系統啟動時內存中沒有保留所需要內存空間,那么HugePages會分配失敗。
e.確保HugePages配置合理,如果內存耗盡,應用將不能使用HugePages。
總結
以上是生活随笔為你收集整理的oracle数据库HugePages配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: stata16 安装教程 资源
- 下一篇: 医疗器械网络安全定义