Huge pages (标准大页)和 Transparent Huge pages(透明大页)
在?Linux?中大頁分為兩種:?Huge pages (?標準大頁?)?和??Transparent Huge pages(?透明大頁?)?。?
內存是以塊即頁的方式進行管理的,當前大部分系統默認的頁大小為?4096 bytes?即?4K?。?1MB?內存等于?256?頁;?1GB?內存等于?256000?頁。?
CPU?擁有內置的內存管理單元,包含這些頁面的列表,每個頁面通過頁表條目引用。當內存越來越大的時候,?CPU?需要管理這些內存頁的成本也就越高,這樣會對操作系統的性能產生影響。?
Huge Pages?
Huge pages??是從?Linux Kernel 2.6?后被引入的,目的是通過使用大頁內存來取代傳統的?4kb?內存頁面,?以適應越來越大的系統內存,讓操作系統可以支持現代硬件架構的大頁面容量功能。?
Huge pages??有兩種格式大小:?2MB??和??1GB?,?2MB?頁塊大小適合用于?GB?大小的內存,?1GB?頁塊大小適合用于?TB?級別的內存;?2MB?是默認的頁大小。?
Transparent Huge Pages?
Transparent Huge Pages??縮寫??THP?,這個是?RHEL 6?開始引入的一個功能,在?Linux6?上透明大頁是默認啟用的。?
由于?Huge pages?很難手動管理,而且通常需要對代碼進行重大的更改才能有效的使用,因此?RHEL 6?開始引入了?Transparent Huge Pages?(?THP?),?THP?是一個抽象層,能夠自動創建、管理和使用傳統大頁。?
THP?為系統管理員和開發人員減少了很多使用傳統大頁的復雜性?,??因為?THP?的目標是改進性能?,??因此其它開發人員??(?來自社區和紅帽?)??已在各種系統、配置、應用程序和負載中對??THP??進行了測試和優化。這樣可讓??THP??的默認設置改進大多數系統配置性能。但是?,??不建議對數據庫工作負載使用??THP?。?
這兩者最大的區別在于?:??標準大頁管理是預分配的方式,而透明大頁管理則是動態分配的方式。?
標準大頁的頁面大小
[oracle@we2db1 ~]$ grep Hugepagesize /proc/meminfo?
Hugepagesize:?????? 2048 kB
注:?THP??目前只能映射異步內存區域,比如堆和棧空間?
??
Oracle??官方是推薦我們使用?Huge pages?的,它擁有以下的好處:?
??
-
Larger Page Size and Less # ofPages: Default page size is 4K whereas the HugeTLB size is 2048K. That meansthe system would need to handle 512 times less pages.?
??
-
Reduced Page Table Walking:Since a HugePage covers greater contiguous virtual address range than a regularsized page, a probability of getting a TLB hit per TLB entry with HugePages arehigher than with regular pages. This reduces the number of times page tablesare walked to obtain physical address from a virtual address.?
??
-
Less Overhead for MemoryOperations: On virtual memory systems (any modern OS) each memory operation isactually two abstract memory operations. With HugePages, since there are lessnumber of pages to work on, the possible bottleneck on page table access isclearly avoided.?
??
-
Less Memory Usage: From theOracle Database perspective, with HugePages, the Linux kernel will use lessmemory to create pagetables to maintain virtual to physical mappings for SGAaddress range, in comparison to regular size pages. This makes more memory tobe available for process-private computations or PGA usage.?
??
-
No Swapping: We must avoidswapping to happen on Linux OS at all Document 1295478.1. HugePages are notswappable (whereas regular pages are). Therefore there is no page replacementmechanism overhead. HugePages are universally regarded as pinned.?
??
-
No 'kswapd' Operations: kswapdwill get very busy if there is a very large area to be paged (i.e. 13 millionpage table entries for 50GB memory) and will use an incredible amount of CPUresource. When HugePages are used, kswapd is not involved in managing them. Seealso Document 361670.1?
??
當然使用??Huge pages??也會存在某些缺點:?
首先開啟該功能需要進行額外設置,?
第二,?Huge pages??和?Oracle 11g新?特性?AMM?(?Automatic Memory Management?)是相互沖突的,但是?ASMM?(?Automatic Shared Memory Management?)仍然可以繼續使用。?
??
Oracle?官方雖然推薦我們使用??Huge pages?,但是卻建議我們關閉?Transparent Huge pages?,因為透明大頁存在一些問題:?
??
1.?在?RAC?環境下???透明大頁(?TransparentHugePages??)會導致異常節點重啟,和性能問題;?
??
2.?在單機環境中,透明大頁(?TransparentHugePages??)?也會導致一些異常的性能問題;?
??
注:Transparent Huge Pages在32位的RHEL 6中是不支持的。?
禁用trasnparent hugepage?
查看透明大頁是否已經啟用?
[root@we2db2 ~]# cat /etc/issue?
Red Hat Enterprise Linux Server release 6.9(Santiago)?
Kernel \r on an \m?
??
[root@we2db2 ~]# cat/sys/kernel/mm/transparent_hugepage/enabled?
always madvise [never]?
??
使用命令查看時,如果輸出結果為?[always]?表示透明大頁啟用了。?
[never]?表示透明大頁禁用、?[madvise]?表示(只在?MADV_HUGEPAGE?標志的?VMA?中使用?THP?。?
這里已經禁用了,若未禁用可以使用以下方式禁用?
??
[root@we2db2 ~]# more /etc/grub.conf?
# grub.conf generated by anaconda?
#?
# Note that you do not have to rerun grubafter making changes to this file?
# NOTICE:?You have a /boot partition.? Thismeans that?
#?????????all kernel and initrd paths are relative to /boot/, eg.?
#?????????root (hd0,0)?
#?????????kernel /vmlinuz-version ro root=/dev/mapper/rootvg-lv_root?
#?????????initrd /initrd-[generic-]version.img?
#boot=/dev/sda?
default=0?
timeout=5?
splashimage=(hd0,0)/grub/splash.xpm.gz?
hiddenmenu?
title Red Hat Enterprise Linux 6(2.6.32-696.20.1.el6.x86_64)?
???????root (hd0,0)?
???????kernel /vmlinuz-2.6.32-696.20.1.el6.x86_64 ro root=/dev/mapper/rootvg-lv_root?transparent_hugepage=never???rd_NO_LUKS.UTF-8 rd_LVM_L?
V=rootvg/lv_swap rd_NO_MDSYSFONT=latarcyrheb-sun16 rd_LVM_LV=rootvg/lv_root? KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgbquiet?
???????initrd /initramfs-2.6.32-696.20.1.el6.x86_64.img?
? ? ? ???
配置huge page?
1.??在?/etc/security/limits.conf?加入以下參數?
??
*??soft?? memlock??? 8193024?
*??hard?? memlock??? 8193024?
??
??
這里的試驗環境是?8G??的內存,?memlock??參數的值只需略小于內存的值即可,即使超過了?SGA?的需求,也沒有任何影響。?
??
??
[root@we2db1 ~]# cat /etc/security/limits.conf?
??
*??soft?? memlock??? 8193024?
*??hard?? memlock??? 8193024?
??
??
2.?重新登錄服務器驗證設置?
??
[root@we2db1 ~]# ulimit -l?
8193024?
??
3.?在?Oracle 11g?中禁用??AutomaticMemory Management (AMM)?特性,即?MEMORY_TARGET and MEMORY_MAX_TARGET??值為?。?
??
SQL> show parameter MEMORY_TARGET?
??
NAME???????????????????????????????? TYPE??????? VALUE?
----------------------------------------------- ------------------------------?
memory_target??????????????????????? big integer 0?
SQL> show parameter MEMORY_MAX_TARGET?
??
NAME????????????? ???????????????????TYPE??????? VALUE?
----------------------------------------------- ------------------------------?
memory_max_target??????????????????? big integer 0?
??
這里試驗環境并沒有啟用?AMM?特性,如果啟用了該特性使用一下語句關閉。?
??
alter system setMEMORY_TARGET=0 scope=spfile;?
alter system setMEMORY_MAX_TARGET=0 scope=spfile;?
??
重啟實例后生效。?
??
4.?確認所有需要使用?Hugepage?的實例都是開啟的?(?包括?ASM?實例?)?,然后運行?hugepages_settings.sh(?具體腳本參考文檔??ID 401749.1?)?
??
[root@we2db1 ~]# chmod +xhugepages_settings.sh?
[root@we2db1 ~]# ./hugepages_settings.sh?
??
This script is provided by Doc ID 401749.1from My Oracle Support?
(http://support.oracle.com) where it isintended to compute values for?
the recommended HugePages/HugeTLBconfiguration for the current shared?
memory segments on Oracle Linux. Beforeproceeding 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.?
?* Incase you changes the DB SGA size,?
?? asthe new SGA will not fit in the previous HugePages configuration,?
?? ithad 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 = 1204?
??
5.?在??/etc/sysctl.conf??文件中添加?vm.nr_hugepages?參數?
??
[root@we2db1 ~]# cat /etc/sysctl.conf |grep nr_hugepages?
vm.nr_hugepages = 1204?
[root@we2db2 ~]# cat /etc/sysctl.conf |grep nr_hugepages?
vm.nr_hugepages = 1204?
??
6.?關閉所有數據庫實例并重啟服務器?
??
7.?驗證配置是否正確,如下所示:?
??
[root@we2db2 ~]# grep HugePages? /proc/meminfo?
AnonHugePages:???????? 0 kB?
HugePages_Total:??? 1204?
HugePages_Free:????? 739?
HugePages_Rsvd:????? 736?
HugePages_Surp:??????? 0?
??
為了確保?HugePages?配置的有效性,?HugePages_Free?值應該小于?HugePages_Total??的值,并且有一定的?HugePages_Rsvd?的值。?
??
Also there should be some HugePages_Rsvd ifPRE_PAGE_SGA is 'false' for all the Oracle database instances..?
HugePages_Rsvd counts free pages that arereserved for use (requested for an SGA, but not touched/mapped yet).?
PRE_PAGE_SGA determines if the all SGApages are read-in when the instance starts up.?
If parameter is set to 'true' then the OSpage table entries are prebuilt for each page of the SGA, leading to HugePagesreservation of those pages.?
For Oracle database versions before 12.1the default value for PRE_PAGE_SGA is 'false'. So the HugePages_Rsvd would behigher than 0. But since 12c the PRE_PAGE_SGA defaults to 'true' which wouldcause the HugePages_Rsvd to be 0.?
??
The sum of Hugepages_Free andHugePages_Rsvd may be smaller than your total combined SGA as instancesallocate pages dynamically and proactively as needed.?
??
至此??HugePages??已經配置完成。?
??
雖然?Oracle?官方推薦使用?Huge Pages??但是具體是否使用還得考慮實際情況。?如果您的系統經常碰到因為?swap??引發的性能問題的系統可以考慮啟用?HugePage??。另外,?OS??內存非常大的系統也可以啟用?HugePage??。但是具體多大就一定需要使用?HugePage???這并沒有定論。?
??
參考文檔:?
??
HugePages on Oracle Linux 64-bit (?文檔??ID361468.1)?
??
HugePages and Oracle Database 11g AutomaticMemory Management (AMM) on Linux (?文檔??ID 749851.1)?
??
HugePages on Linux: What It Is... and WhatIt Is Not... (?文檔??ID 361323.1)?
??
Oracle Linux: Shell Script to CalculateValues Recommended Linux HugePages / HugeTLB Configuration (?文檔??ID401749.1)?
??
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-memory-transhuge#s-memory-configure_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"?];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 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?];?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?-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禁用透明大頁?--Transparent Huge Pages (THP)?
如果?HugePages_Total?返回?,也意味著透明大頁禁用了?
grep -i HugePages_Total /proc/meminfo?
若?cat /proc/sys/vm/nr_hugepages?返回?也意味著透明大頁禁用了。?
在以下命令中:?
cat /sys/kernel/mm/transparent_hugepage/enabled?
如果輸出結果為?[always]?表示透明大頁啟用了。?[never]?表示透明大頁禁用、?[madvise]?表示只在?MADV_HUGEPAGE?標志的?VMA?中使用?THP?。?
??
編輯?/etc/default/grub?,在?GRUB_CMDLINE_LINUX?加入選項?transparent_hugepage=never?
[root@rac18c-sharedisks ~]# cat ?/etc/default/grub?
GRUB_TIMEOUT=5?
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"?
GRUB_DEFAULT=saved?
GRUB_DISABLE_SUBMENU=true?
GRUB_TERMINAL_OUTPUT="console"?
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet?transparent_hugepage=never?"?
GRUB_DISABLE_RECOVERY="true"?
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"?
執行生效命令:?
grub2-mkconfig -o /boot/grub2/grub.cfg?
??
最后重啟。?
透明大頁介紹?
Transparent Huge Pages的一些官方介紹資料:?
Transparent Huge Pages???(THP)??are enabled by default in RHEL 6 for all applications. The kernel attempts to allocate hugepages whenever possible and any Linux process will receive 2MB pages if the mmap region is 2MB naturally aligned. The main kernel address space itself is mapped with hugepages, reducing TLB pressure from kernel code. For general information on Hugepages, see: What are Huge Pages and what are the advantages of using them??
The kernel will always attempt to satisfy a memory allocation using hugepages. If no hugepages are available (due to non availability of physically continuous memory for example) the kernel will fall back to the regular 4KB pages. THP are also swappable (unlike hugetlbfs). This is achieved by breaking the huge page to smaller 4KB pages, which are then swapped out normally.?
But to use hugepages effectively, the kernel must find physically continuous areas of memory big enough to satisfy the request, and also properly aligned. For this, a khugepaged kernel thread has been added. This thread will occasionally attempt to substitute smaller pages being used currently with a hugepage allocation, thus maximizing THP usage.?
In userland, no modifications to the applications are necessary (hence transparent). But there are ways to optimize its use. For applications that want to use hugepages, use of posix_memalign() can also help ensure that large allocations are aligned to huge page (2MB) boundaries.?
Also, THP is only enabled for anonymous memory regions. There are plans to add support for tmpfs and page cache. THP tunables are found in the /sys tree under /sys/kernel/mm/redhat_transparent_hugepage.?
??
查看是否啟用透明大頁?
1:命令cat /sys/kernel/mm/redhat_transparent_hugepage/enabled 該命令適用于Red Hat Enterprise Linux系統?
[root@getlnx06?~]#?more?/etc/issue ? Red?Hat?Enterprise?Linux?Server?release?6.6?(Santiago) ? Kernel?\r?on?an?\m ? [root@getlnx06?~]#?cat?/sys/kernel/mm/redhat_transparent_hugepage/enabled ? [always]?madvise?never??
2:命令cat /sys/kernel/mm/transparent_hugepage/enabled 該命令適用于其它Linux系統?
[root@getlnx06?~]#?cat?/sys/kernel/mm/transparent_hugepage/enabled ? always?madvise?[never] ? [root@getlnx06?~]#使用命令查看時,如果輸出結果為[always]表示透明大頁啟用了。[never]表示透明大頁禁用、[madvise]表示?(只在MADV_HUGEPAGE標志的VMA中使用THP?
??
3:如何HugePages_Total返回0,也意味著標準大頁禁用了(注意傳統/標準大頁和透明大頁的區別)?
?? 透明大頁(THP)管理和標準/傳統大頁(HP)管理都是操作系統為了減少頁表轉換消耗的資源而發布的新特性,雖然ORACLE建議利用大頁機制來提高數據庫的性能,但是ORACLE卻同時建議關閉透明大頁管理。這二者的區別在于大頁的分配機制,標準大頁管理是預分配的方式,而透明大頁管理則是動態分配的方式。?
[root@getlnx06?~]#?grep?-i?HugePages_Total?/proc/meminfo ? HugePages_Total:?0??
4:cat /proc/sys/vm/nr_hugepages返回0也意味著傳統大頁禁用了(傳統大頁和透明大頁)。?
[root@getlnx06?~]#?cat?/proc/sys/vm/nr_hugepages ???
禁用、啟用透明大頁功能?
??
方法1:設置/etc/grub.conf文件,在系統啟動是禁用。?
[root@getlnx06?~]#?vi?/etc/grub.conf #?grub.conf?generated?by?anaconda # #?Note?that?you?do?not?have?to?rerun?grub?after?making?changes?to?this?file #?NOTICE:??You?have?a?/boot?partition.??This?means?that #??????????all?kernel?and?initrd?paths?are?relative?to?/boot/,?eg. #??????????root?(hd0,0) #??????????kernel?/vmlinuz-version?ro?root=/dev/mapper/VolGroup--LogVol0-LogVol01 #??????????initrd?/initrd-[generic-]version.img #boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title?Red?Hat?Enterprise?Linux?6?(2.6.32-504.el6.x86_64) ????????root?(hd0,0) ????????kernel?/vmlinuz-2.6.32-504.el6.x86_64?ro?root=/dev/mapper/VolGroup--LogVol0-LogVol01?rd_NO_LUKS.UTF-8?rd_NO_MD?SYSFONT=latarcyrheb-sun16?crashkernel=auto?rd_LVM_LV=VolGroup-LogVol0/LogVol01?rd_LVM_LV=VolGroup-LogVol0/LogVol00??KEYBOARDTYPE=pc?KEYTABLE=us?rd_NO_DM?rhgb?quiet ????????initrd?/initramfs-2.6.32-504.el6.x86_64.img transparent_hugepage=never??
方法2:設置/etc/rc.local文件?
[root@getlnx06?~]#?vi?/etc/rc.local #!/bin/sh # #?This?script?will?be?executed?*after*?all?the?other?init?scripts. #?You?can?put?your?own?initialization?stuff?in?here?if?you?don't #?want?to?do?the?full?Sys?V?style?init?stuff. ? touch?/var/lock/subsys/local ? if?test?-f?/sys/kernel/mm/redhat_transparent_hugepage/enabled;?then ???echo?never?>?/sys/kernel/mm/redhat_transparent_hugepage/enabled fi??
使用上面的配置后必須重啟操作系統才能生效,你也可以運行下面命令不用重啟操作系統。?
You must reboot your system for the setting to take effect, or run the following two echo lines to proceed with the install without rebooting:?
[root@getlnx06?~]#?echo?never?>?/sys/kernel/mm/redhat_transparent_hugepage/enabled [root@getlnx06?~]#?cat?/sys/kernel/mm/redhat_transparent_hugepage/enabled always?madvise?[never] [root@getlnx06?~]#??
小知識點:?
1:從RedHat 6, OEL 6, SLES 11 and UEK2 kernels 開始,系統缺省會啟用 Transparent HugePages :用來提高內存管理的性能透明大頁(Transparent HugePages )和之前版本中的大頁功能上類似。主要的區別是:Transparent HugePages 可以實時配置,不需要重啟才能生效配置;?
??
2:Transparent Huge Pages在32位的RHEL 6中是不支持的。?
Transparent Huge Pages are not available on the 32-bit version of RHEL 6.?
??
3: ORACLE官方不建議我們使用RedHat 6, OEL 6, SLES 11 and UEK2 kernels 時的開啟透明大頁(Transparent HugePages ), 因為透明大頁(Transparent HugePages ) 存在一些問題:?
??????? 1.在RAC環境下 透明大頁(Transparent HugePages )會導致異常節點重啟,和性能問題;?
??????? 2.在單機環境中,透明大頁(Transparent HugePages ) 也會導致一些異常的性能問題;?
Transparent HugePages memory is enabled by default with Red Hat Enterprise Linux 6, SUSE Linux Enterprise Server 11, and Oracle Linux 6 with earlier releases of Oracle Linux Unbreakable Enterprise Kernel 2 (UEK2) kernels. Transparent HugePages memory is disabled in later releases of Oracle Linux UEK2 kernels.Transparent HugePages can cause memory allocation delays during runtime. To avoid performance issues, Oracle recommends that you disable Transparent HugePages on all Oracle Database servers. Oracle recommends that you instead use standard HugePages for enhanced performance.Transparent HugePages memory differs from standard HugePages memory because the kernel khugepaged thread allocates memory dynamically during runtime. Standard HugePages memory is pre-allocated at startup, and does not change during runtime.?
Starting with RedHat 6, OEL 6, SLES 11 and UEK2 kernels, Transparent HugePages are implemented and enabled (default) in an attempt to improve the memory management. Transparent HugePages are similar to the HugePages that have been available in previous Linux releases. The main difference is that the Transparent HugePages are set up dynamically at run time by the khugepaged thread in kernel while the regular HugePages had to be preallocated at the boot up time. Because Transparent HugePages are known to cause unexpected node reboots and performance problems with RAC, Oracle strongly advises to disable the use of Transparent HugePages. In addition, Transparent Hugepages may cause problems even in a single-instance database environment with unexpected performance problems or delays. As such, Oracle recommends disabling Transparent HugePages on all Database servers running Oracle.?
??
4:安裝Vertica Analytic Database時也必須關閉透明大頁功能。?
??
參考資料:?
https://access.redhat.com/solutions/46111?
http://www.soso.io/article/65143.html?
Linux7.4 關閉透明大頁?
在Linux6.x之后的平臺,在安裝Oracle數據庫的時候都建議關閉透明大頁?
Linux下的大頁分為兩種類型:標準大頁(Huge Pages)和透明大頁(Transparent Huge Pages)。?
這兩者的區別在于大頁的分配機制,標準大頁管理是預分配的方式,而透明大頁管理則是動態分配的方式。目前透明大頁與傳統大頁混合使用會出現一些問題,導致性能問題和系統重啟。ORACLE官方不建議在使用RedHat 6, OEL 6, SLES 11 and UEK2 kernels 時開啟透明大頁(THP), 因為透明大頁存在一些問題:?
1.在RAC環境下 透明大頁(Transparent HugePages )會導致異常節點重啟和性能問題;?
2.在單機環境中,透明大頁(Transparent HugePages ) 也會導致一些異常的性能問題;?
2 關閉THP?
Linux7 默認情況下 是開啟透明大頁功能的。?
檢查系統對應版本??
[root@db-server ~]# uname -r?
3.10.0-693.el7.x86_64?
[root@db-server ~]# uname -a?
Linux db-server 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux?
[root@db-server ~]# cat /etc/redhat-release??
CentOS Linux release 7.4.1708 (Core)?
修改文件 /etc/default/grub 文件?
執行生效命令 grub2-mkconfig -o /boot/grub2/grub.cfg?
重啟??
reboot?
檢查是否生效?
如果你也是grub2的linux系統,請通過以下步驟關閉大內存頁面。?
step1 編輯 /etc/default/grub,在GRUB_CMDLINE_LINUX加入選項 transparent_hugepage=never?
| 1? 2? 3? 4? 5? 6? 7? | GRUB_TIMEOUT=5? GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"? GRUB_DEFAULT=saved? GRUB_DISABLE_SUBMENU=true? GRUB_TERMINAL_OUTPUT="console"? GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora/swap rd.lvm.lv=fedora/root rhgb quiet transparent_hugepage=never"? GRUB_DISABLE_RECOVERY="true"? |
step2 重新生成grub配置文件?
| 1? 2? 3? 4? | On BIOS-based machines, issue the following??command???as root:? # grub2-mkconfig -o /boot/grub2/grub.cfg? On UEFI-based machines, issue the following??command???as root:? # grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg? |
step3 重啟你的系統?
至此大功告成,如果你使用的是grub,請把選項寫入grub.conf文件就好了。?
查詢hugepage狀態,第一種方式?
| 1? 2? 3? 4? | [root@localhost yucanlin]?# cat /sys/kernel/mm/transparent_hugepage/enabled? always madvise [never]? [root@localhost yucanlin]?# cat /sys/kernel/mm/transparent_hugepage/defrag? always madvise [never]? |
never就對了。?
第二種方式?
| 1? 2? 3? 4? 5? 6? 7? | [yucanlin@localhost ~]$??grep???Huge?/proc/meminfo? AnonHugePages:???????? 0 kB? HugePages_Total:?????? 0? HugePages_Free:??????? 0? HugePages_Rsvd:??????? 0? HugePages_Surp:??????? 0? Hugepagesize:?????? 2048 kB? |
0就對了。?
不過有個小遺憾,重啟后我發現 enabled 是never,但defrag卻依然是always,不過經過查詢meminfo,大內存頁面是被禁用了。就不去管他了。?
總結
以上是生活随笔為你收集整理的Huge pages (标准大页)和 Transparent Huge pages(透明大页)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图像标注-自动标注图像
- 下一篇: 到底咋做,才能业务财务真的一体化