共計 7555 個字符,預計需要花費 19 分鐘才能閱讀完成。
這篇文章主要介紹 Oracle 中如何配置 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 限制 (root 操作)
通過修改 /etc/security/limits.conf 配值文件來實現
該參數的值通常配值位略小于當前的已安裝系統內存,如當前你的系統內存為 64GB,可以做如下設置
* soft memlock 664377747
* hard memlock 664377747
上述的設置單位為 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 用戶執行)
使用 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 參數(root 操作)
$ sysctl -w vm.nr_hugepages = 125447
$ sysctl -p
1.6、停止所有的 Instance 并重啟 server
上述的所有步驟已經實現了動態修改,但對于 HugePages 的分配需要重新啟動 server 才能生效。
1.7、驗證配值
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
二、使用 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
Troubleshooting Action:
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
Possible Cause:
The SGA of the specific database could not find available HugePages and remaining RAM is not enough.
Troubleshooting Action:
Make sure that the RAM and HugePages are enough to cover all your database SGAs
Symptom D:
Cluster Ready Services (CRS) fail to start
Possible Cause:
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
Possible Cause:
HugePages are not used at all. No database instances are up or using AMM.
Troubleshooting Action:
Disable AMM and make sure that the database instances are up.
Symptom F:
Database started successfully and the performance is slow
Possible Cause:
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
Troubleshooting Action:
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 腳本
若 HugePages 配置可行,他就會推薦一個內存大小,若不可行則報錯
#!/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`
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.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
以上是“Oracle 中如何配置 HugePages 內存”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注丸趣 TV 行業資訊頻道!