Oracle 标准大页和透明大页
說明:
標準大頁(HugePages)
標準大頁(HugePages)是從 Linux Kernel 2.6 后被引入的。
目的是用更大的內存頁面(memory page size)以適應越來越大的系統內存,讓操作系統可以支持現代硬件架構的大頁面容量功能。
透明大頁(Transparent HugePages)
透明大頁(Transparent Huge Pages)縮寫為THP,透明超大頁面(THP)在RHEL 6中默認情況下對所有應用程序都是啟用的。
內核試圖盡可能分配巨大的頁面,主內核地址空間本身被映射為巨大的頁面,減少了內核代碼的TLB壓力。
內核將始終嘗試使用大頁來滿足內存分配。
如果沒有可用的巨大頁面(例如由于物理連續內存不可用),內核將回退到正常的4KB頁面。
THP也是可交換的(不像hugetlbfs)。
這是通過將大頁面分成更小的4KB頁面來實現的,然后這些頁面被正常地換出。
透明大頁存在的問題:
Oracle Linux team在測試的過程中發現,如果linux開啟透明大頁THP,則I/O讀寫性能降低30%;
如果關閉透明大頁THP,I/O讀寫性能則恢復正常。
另,建議在Oracle Database中不要使用THP。
ORACLE官方不建議在使用RedHat 6, OEL 6, SLES 11 and UEK2 kernels 時開啟透明大頁(THP),因為透明大頁存在一些問題:
1. 在RAC環境下,透明大頁(THP)會導致異常節點重啟和性能問題;
2. 在單機環境中,透明大頁(THP)也會導致一些異常的性能問題;
標準大頁和透明大頁區別:
兩者區別在于大頁的分配機制,標準大頁管理是預分配 方式,而透明大頁管理則是動態分配 方式。
目前透明大頁與傳統大頁混合使用會出現一些問題,導致性能問題和系統重啟。
如何開啟標準大頁(HugePages)
適用于:
1.Kernel Version 2.6及更高。
2.Oracle AMM內存管理和HugePages不兼容,確保在AMM關閉的情況下啟動HugePages。
啟用HugePages方法:
1 運行以下命令以確定內核是否支持HugePages
$ grep Huge /proc/meminfo
2 配置memlock
在/etc/security/limits.conf文件中設置memlock值,memlock設置以KB為單位。
當啟用HugePages內存時,最大鎖定內存限制應至少設置為當前服務器內存的90%。
禁用HugePages內存時,最大鎖定內存限制應設置為至少3145728 KB(3 GB)。
例如,如果安裝了64 GB RAM,則添加以下條目以增加最大鎖定內存地址空間:
*? ?soft? ?memlock? ? 60397977
*? ?hard? ?memlock? ? 60397977
也可以將memlock值設置為高于SGA要求的值。
再次以oracle用戶身份登錄并運行ulimit-l命令以驗證新的memlock設置:
su - oracle
$ ulimit -l
3 啟動實例
檢查實例是啟動狀態
srvctl status instance -d dbname
如果沒啟動,手動啟動實例
srvctl start instance -d dbname -i instance_name -o open
4 使用腳本為當前共享內存段計算hugepages配置的建議值:
root用戶下執行
chmod +x hugepages_settings.sh?
./hugepages_settings.sh?
腳本來自My Oracle Support note 401749.1,腳本詳細內容見末尾。
5 停止數據庫實例
srvctl stop instance -d dbname -i instance_name -o immediate
6 設置vm.nr_hugepages內核參數
寫入配置文件,永久生效
vi /etc/sysctl.conf
vm.nr_hugepages=<value from above>
sysctl -p
# sysctl -w vm.nr_hugepages=<value from above> 臨時改變,重啟失效
7 啟動實例
srvctl start instance -d dbname -i instance_name -o open
8 檢查可用的hugepages
$ grep Huge /proc/meminfo
如果配置沒生效,需要重啟服務器
[root@rac1 ~]# grep Huge /proc/meminfo
AnonHugePages:? ? ? ? ?0 kB
HugePages_Total:? ? ?179
HugePages_Free:? ? ? ? 9
HugePages_Rsvd:? ? ? ? 7
HugePages_Surp:? ? ? ? 0
Hugepagesize:? ? ? ?2048 kB
參考:
| 1 2 3 | My?Oracle?Support?note?401749.1? My?Oracle?Support?note?361323.1 Database?Administrator's?Reference?for?Linux?and?UNIX?System-Based?Operating?Systems |
如何關閉透明大頁(Transparent HugePages)
Linux7 默認情況下 是開啟透明大頁功能的。檢查系統對應版本
[root@DB ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)
關閉THP
[root@DB ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
默認情況下,狀態為 always,需要調整為 never
THP 禁用方的幾種方法
方法 1:
[root@DB ~]# vi /etc/default/grub
GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap rd.lvm.lv=rhel/root rhgb quiet transparent_hugepage=never"
運行下列命令使之修改生效:
[root@DB ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
方法 2:
| 1 2 3 4 5 | [root@DB?~]#vi?/etc/rc.local if?test?-f?/sys/kernel/mm/transparent_hugepage/enabled;?then?echo?never?>?/sys/kernel/mm/transparent_hugepage/enabled fi if?test?-f?/sys/kernel/mm/transparent_hugepage/defrag;?then?echo?never?>?/sys/kernel/mm/transparent_hugepage/defrag fi |
[root@DB ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
方法 3:
[root@DB ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@DB ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
always madvise [never]
查看是否關閉透明大頁
[root@DB ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
always madvise [never]
如果輸出結果為[always]表示透明大頁啟用了。[never]表示透明大頁禁用;
[root@DB ~]# grep -i HugePages_Total /proc/meminfo
如果 HugePages_Total,返回 0,也意味著透明大頁禁用了
[root@DB ~]# cat /proc/sys/vm/nr_hugepages
返回 0 也意味著透明大頁禁用了。
hugepages_settings.sh?腳本內容如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #!/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 #? #?Welcome?text echo?" This?script?is?provided?by?Doc?ID?401749.1?from?My?Oracle?Support ()?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?the?overall?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"?;; ????'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"?;; ????'4.14')?echo?"Recommended?setting:?vm.nr_hugepages?=?$NUM_PG"?;; ????'5.4')?echo?"Recommended?setting:?vm.nr_hugepages?=?$NUM_PG"?;; ????*)?echo?"Kernel?version?$KERN?is?not?supported?by?this?script?(yet).?Exiting."?;; esac #?End |
總結
以上是生活随笔為你收集整理的Oracle 标准大页和透明大页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: yuzu模拟器linux,Yuzu Ea
- 下一篇: 【BLOCK】Oracle 块管理常用S