HugePage是Oracle在Linux版本下一種性能優化手段。對於共享內存區域(SGA)的數據庫系統,Oracle通常都推薦在操作系統層面配置上HugePage,為Oracle實例准備更大的可用共享內存和整塊的內存。
本文主要介紹在Oracle 11gR2版本上,進行HugePage配置全過程。記錄下來,共需要的朋友待查。
1、環境介紹
筆者使用Oracle 11gR2系統,具體版本為11.2.0.4。
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 – Production
當前數據庫配置內存策略為ASMM,也就是分別設置PGA和SGA的大小范圍。Oracle根據負載情況動態自己調節內部各個子池的空間。注意:在當前版本中,AMM(Automatic Memory Management)和HugePage之間還是不能兼容。所以,如果要求配置HugePage,就只能退而求其次選擇ASMM。
數據庫設置的SGA空間如下:
SQL> show parameter sga;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 12G
sga_target big integer 12G
12G的SGA,Oracle在啟動過程中,針對大內存情況給出了提示在alert log中。
ue Jan 12 11:31:33 2016
Starting ORACLE instance (normal)
************************ Large Pages Information *******************
Per process system memlock (soft) limit = 64 KB
Total Shared Global Region in Large Pages = 0 KB (0%)
Large Pages used by this instance: 0 (0 KB)
Large Pages unused system wide = 0 (0 KB)
Large Pages configured system wide = 0 (0 KB)
Large Page size = 2048 KB
RECOMMENDATION:
Total System Global Area size is 12 GB. For optimal performance,
prior to the next instance restart:
1. Increase the number of unused large pages by
at least 6145 (page size 2048 KB, total size 12 GB) system wide to
get 100% of the System Global Area allocated with large pages
2. Large pages are automatically locked into physical memory.
Increase the per process memlock (soft) limit to at least 12 GB to lock
100% System Global Area's large pages into physical memory
首先Oracle發現當前系統並沒有設置HugePage,只有默認的2M大小的Page可選。於是,從建議的角度,給出了提示意見,建議開啟HugePage選項在操作系統層面。此時,操作系統層面也沒有專門的設置。
[oracle@PROD_PC-DB trace]$ grep Huge /proc/meminfo
AnonHugePages: 36864 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
2、配置HugePage
在11.2的小版本中,HugePage處理的行為其實是在變化的。在11.2.0.2中,Oracle推出了一個參數use_large_page,作為從實例層面控制Oracle使用Huge Page的開關。
SQL> show parameter large_pages
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
use_large_pages string TRUE
該參數默認取值為true,是一種向上最優策略。如果設置為true,Oracle實例會去檢查是否操作系統開啟了HugePage,如果有就采用,如果沒有就不用。另外兩個取值分別為false和only,如果選擇為false,表示Oracle實例不管操作系統設置,都不會使用HugePage。如果選擇為only,就表示Oracle實例只會選擇HugePage上運行。
此外,在行為上也有一些變化。在11.2.0.2版本中,如果操作系統沒有足夠的HugePage使用,SGA內存就只有使用系統剩下的小頁(Small Pages)。如果余下的小頁small page不夠用,或者內核使用的比較多,系統會報錯ora-4030錯誤。
這個情況在11.2.0.3版本中有一些變化。Oracle首先會使用可用的HugePage,如果使用盡了,同樣會采用剩下的small pages作為SGA使用。變化在於對使用HugePage的方式上,根據官方的說法:
With this new behavior additional shared memory segments are an expected side effect. Part of the change is to ensure that each shared memory segment making up the SGA only contains sub-areas with an identical alignment requirement - hence the SGA will spread over more separate SHM segments. In this supported mixed page mode the database will exhaust the available hugepages, before switching to regular sized pages.
新版本的操作方式可以更好的使用可用的大頁資源。當前操作系統版本為Linux 2.6內核版本。
[oracle@PROD_PC-DB trace]$ uname -r
2.6.32-431.el6.x86_64
這個過程中涉及到不同操作系統環境、不同Oracle配置下的推薦HugePage數量問題。Oracle在MOS上發布出一個Shell腳本hugepages_settings.sh,可以動態計算出推薦的HugePage數量。
具體腳本內容可以從MOS Doc ID 401749.1上進行下載,在筆者之前關於HugePage的文章中也有所涉及。執行腳本后結果如下:
[oracle@PROD_PC-DB trace]$ ls -l | grep hugepag
-rw-r--r--. 1 oracle oinstall 3129 Jan 12 13:32 hugepages_settings.sh
[oracle@PROD_PC-DB trace]$ chmod +x hugepages_settings.sh
[oracle@PROD_PC-DB trace]$ ls -l | grep hugepag
-rwxr-xr-x. 1 oracle oinstall 3129 Jan 12 13:32 hugepages_settings.sh
[oracle@PROD_PC-DB trace]$ uname -r
2.6.32-431.el6.x86_64
[oracle@PROD_PC-DB trace]$ ./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 -m
Press Enter to proceed...
Recommended setting: vm.nr_hugepages = 6148
操作系統層面配置HugePage,需要在兩個層面進行配置。事先是limits.conf文件,開啟對用戶的內存限制。
[root@PROD_PC-DB security]# vi limits.conf
# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
(篇幅原因,有省略……)
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft memlock 32879476 --對應內存總量
oracle hard memlock 32879476
確認修改。
[oracle@PROD_PC-DB ~]$ ulimit -l
32879476
將腳本計算出的結果,修改入/etc/sysctl.conf文件。
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
fs.file-max = 6815744
vm.nr_hugepages = 6148
"/etc/sysctl.conf" 67L, 1631C written
執行sysctl –p落實修改。
[root@PROD_PC-DB security]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
(篇幅原因,有省略……)
fs.file-max = 6815744
vm.nr_hugepages = 6148
重新啟動實例數據庫。
SQL> conn / as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 1.2827E+10 bytes
Fixed Size 2265224 bytes
Variable Size 2214596472 bytes
Database Buffers 1.0603E+10 bytes
Redo Buffers 7307264 bytes
Database mounted.
Database opened.
SQL>
在操作系統層面上,可以看到HugePage使用情況。
[oracle@PROD_PC-DB ~]$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 786435 oracle 640 67108864 22
0x00000000 819204 oracle 640 12817793024 22
0x617ab988 851973 oracle 640 2097152 22
[oracle@PROD_PC-DB ~]$ grep Huge /proc/meminfo
AnonHugePages: 20480 kB
HugePages_Total: 6148
HugePages_Free: 5531
HugePages_Rsvd: 5528
HugePages_Surp: 0
Hugepagesize: 2048 kB
同時,啟動過程中的推薦提示信息消失。
Tue Jan 12 14:26:30 2016
Starting ORACLE instance (normal)
************************ Large Pages Information *******************
Per process system memlock (soft) limit = 31 GB
Total Shared Global Region in Large Pages = 12 GB (100%)
Large Pages used by this instance: 6145 (12 GB)
Large Pages unused system wide = 3 (6144 KB)
Large Pages configured system wide = 6148 (12 GB)
Large Page size = 2048 KB
********************************************************************
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Initial number of CPU is 8
Number of processor cores in the system is 8
Number of processor sockets in the system is 1
Picked latch-free SCN scheme 3
Using LOG_ARCHIVE_DEST_1 parameter default value as USE_DB_RECOVERY_FILE_DEST
Autotune of undo retention is turned on.
IMODE=BR
3、結論
對於投產在Linux版本下的Oracle共享內存系統而言,配置HugePage還是有現實意義的。
轉:http://blog.itpub.net/17203031/viewspace-1975653/