Huge pages (标准大页)和 Transparent Huge pages(透明大页)
在?Linux?中大頁(yè)分為兩種:?Huge pages (?標(biāo)準(zhǔn)大頁(yè)?)?和??Transparent Huge pages(?透明大頁(yè)?)?。?
內(nèi)存是以塊即頁(yè)的方式進(jìn)行管理的,當(dāng)前大部分系統(tǒng)默認(rèn)的頁(yè)大小為?4096 bytes?即?4K?。?1MB?內(nèi)存等于?256?頁(yè);?1GB?內(nèi)存等于?256000?頁(yè)。?
CPU?擁有內(nèi)置的內(nèi)存管理單元,包含這些頁(yè)面的列表,每個(gè)頁(yè)面通過頁(yè)表?xiàng)l目引用。當(dāng)內(nèi)存越來越大的時(shí)候,?CPU?需要管理這些內(nèi)存頁(yè)的成本也就越高,這樣會(huì)對(duì)操作系統(tǒng)的性能產(chǎn)生影響。?
Huge Pages?
Huge pages??是從?Linux Kernel 2.6?后被引入的,目的是通過使用大頁(yè)內(nèi)存來取代傳統(tǒng)的?4kb?內(nèi)存頁(yè)面,?以適應(yīng)越來越大的系統(tǒng)內(nèi)存,讓操作系統(tǒng)可以支持現(xiàn)代硬件架構(gòu)的大頁(yè)面容量功能。?
Huge pages??有兩種格式大小:?2MB??和??1GB?,?2MB?頁(yè)塊大小適合用于?GB?大小的內(nèi)存,?1GB?頁(yè)塊大小適合用于?TB?級(jí)別的內(nèi)存;?2MB?是默認(rèn)的頁(yè)大小。?
Transparent Huge Pages?
Transparent Huge Pages??縮寫??THP?,這個(gè)是?RHEL 6?開始引入的一個(gè)功能,在?Linux6?上透明大頁(yè)是默認(rèn)啟用的。?
由于?Huge pages?很難手動(dòng)管理,而且通常需要對(duì)代碼進(jìn)行重大的更改才能有效的使用,因此?RHEL 6?開始引入了?Transparent Huge Pages?(?THP?),?THP?是一個(gè)抽象層,能夠自動(dòng)創(chuàng)建、管理和使用傳統(tǒng)大頁(yè)。?
THP?為系統(tǒng)管理員和開發(fā)人員減少了很多使用傳統(tǒng)大頁(yè)的復(fù)雜性?,??因?yàn)?THP?的目標(biāo)是改進(jìn)性能?,??因此其它開發(fā)人員??(?來自社區(qū)和紅帽?)??已在各種系統(tǒng)、配置、應(yīng)用程序和負(fù)載中對(duì)??THP??進(jìn)行了測(cè)試和優(yōu)化。這樣可讓??THP??的默認(rèn)設(shè)置改進(jìn)大多數(shù)系統(tǒng)配置性能。但是?,??不建議對(duì)數(shù)據(jù)庫(kù)工作負(fù)載使用??THP?。?
這兩者最大的區(qū)別在于?:??標(biāo)準(zhǔn)大頁(yè)管理是預(yù)分配的方式,而透明大頁(yè)管理則是動(dòng)態(tài)分配的方式。?
標(biāo)準(zhǔn)大頁(yè)的頁(yè)面大小
[oracle@we2db1 ~]$ grep Hugepagesize /proc/meminfo?
Hugepagesize:?????? 2048 kB
注:?THP??目前只能映射異步內(nèi)存區(qū)域,比如堆和棧空間?
??
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?
??
當(dāng)然使用??Huge pages??也會(huì)存在某些缺點(diǎn):?
首先開啟該功能需要進(jìn)行額外設(shè)置,?
第二,?Huge pages??和?Oracle 11g新?特性?AMM?(?Automatic Memory Management?)是相互沖突的,但是?ASMM?(?Automatic Shared Memory Management?)仍然可以繼續(xù)使用。?
??
Oracle?官方雖然推薦我們使用??Huge pages?,但是卻建議我們關(guān)閉?Transparent Huge pages?,因?yàn)橥该鞔箜?yè)存在一些問題:?
??
1.?在?RAC?環(huán)境下???透明大頁(yè)(?TransparentHugePages??)會(huì)導(dǎo)致異常節(jié)點(diǎn)重啟,和性能問題;?
??
2.?在單機(jī)環(huán)境中,透明大頁(yè)(?TransparentHugePages??)?也會(huì)導(dǎo)致一些異常的性能問題;?
??
注:Transparent Huge Pages在32位的RHEL 6中是不支持的。?
禁用trasnparent hugepage?
查看透明大頁(yè)是否已經(jīng)啟用?
[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]?
??
使用命令查看時(shí),如果輸出結(jié)果為?[always]?表示透明大頁(yè)啟用了。?
[never]?表示透明大頁(yè)禁用、?[madvise]?表示(只在?MADV_HUGEPAGE?標(biāo)志的?VMA?中使用?THP?。?
這里已經(jīng)禁用了,若未禁用可以使用以下方式禁用?
??
[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?加入以下參數(shù)?
??
*??soft?? memlock??? 8193024?
*??hard?? memlock??? 8193024?
??
??
這里的試驗(yàn)環(huán)境是?8G??的內(nèi)存,?memlock??參數(shù)的值只需略小于內(nèi)存的值即可,即使超過了?SGA?的需求,也沒有任何影響。?
??
??
[root@we2db1 ~]# cat /etc/security/limits.conf?
??
*??soft?? memlock??? 8193024?
*??hard?? memlock??? 8193024?
??
??
2.?重新登錄服務(wù)器驗(yàn)證設(shè)置?
??
[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?
??
這里試驗(yàn)環(huán)境并沒有啟用?AMM?特性,如果啟用了該特性使用一下語(yǔ)句關(guān)閉。?
??
alter system setMEMORY_TARGET=0 scope=spfile;?
alter system setMEMORY_MAX_TARGET=0 scope=spfile;?
??
重啟實(shí)例后生效。?
??
4.?確認(rèn)所有需要使用?Hugepage?的實(shí)例都是開啟的?(?包括?ASM?實(shí)例?)?,然后運(yùn)行?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?參數(shù)?
??
[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.?關(guān)閉所有數(shù)據(jù)庫(kù)實(shí)例并重啟服務(wù)器?
??
7.?驗(yàn)證配置是否正確,如下所示:?
??
[root@we2db2 ~]# grep HugePages? /proc/meminfo?
AnonHugePages:???????? 0 kB?
HugePages_Total:??? 1204?
HugePages_Free:????? 739?
HugePages_Rsvd:????? 736?
HugePages_Surp:??????? 0?
??
為了確保?HugePages?配置的有效性,?HugePages_Free?值應(yīng)該小于?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??已經(jīng)配置完成。?
??
雖然?Oracle?官方推薦使用?Huge Pages??但是具體是否使用還得考慮實(shí)際情況。?如果您的系統(tǒng)經(jīng)常碰到因?yàn)?swap??引發(fā)的性能問題的系統(tǒng)可以考慮啟用?HugePage??。另外,?OS??內(nèi)存非常大的系統(tǒng)也可以啟用?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?
腳本內(nèi)容:?
#!/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禁用透明大頁(yè)?--Transparent Huge Pages (THP)?
如果?HugePages_Total?返回?,也意味著透明大頁(yè)禁用了?
grep -i HugePages_Total /proc/meminfo?
若?cat /proc/sys/vm/nr_hugepages?返回?也意味著透明大頁(yè)禁用了。?
在以下命令中:?
cat /sys/kernel/mm/transparent_hugepage/enabled?
如果輸出結(jié)果為?[always]?表示透明大頁(yè)啟用了。?[never]?表示透明大頁(yè)禁用、?[madvise]?表示只在?MADV_HUGEPAGE?標(biāo)志的?VMA?中使用?THP?。?
??
編輯?/etc/default/grub?,在?GRUB_CMDLINE_LINUX?加入選項(xiàng)?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"?
執(zhí)行生效命令:?
grub2-mkconfig -o /boot/grub2/grub.cfg?
??
最后重啟。?
透明大頁(yè)介紹?
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.?
??
查看是否啟用透明大頁(yè)?
1:命令cat /sys/kernel/mm/redhat_transparent_hugepage/enabled 該命令適用于Red Hat Enterprise Linux系統(tǒng)?
[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系統(tǒng)?
[root@getlnx06?~]#?cat?/sys/kernel/mm/transparent_hugepage/enabled ? always?madvise?[never] ? [root@getlnx06?~]#使用命令查看時(shí),如果輸出結(jié)果為[always]表示透明大頁(yè)啟用了。[never]表示透明大頁(yè)禁用、[madvise]表示?(只在MADV_HUGEPAGE標(biāo)志的VMA中使用THP?
??
3:如何HugePages_Total返回0,也意味著標(biāo)準(zhǔn)大頁(yè)禁用了(注意傳統(tǒng)/標(biāo)準(zhǔn)大頁(yè)和透明大頁(yè)的區(qū)別)?
?? 透明大頁(yè)(THP)管理和標(biāo)準(zhǔn)/傳統(tǒng)大頁(yè)(HP)管理都是操作系統(tǒng)為了減少頁(yè)表轉(zhuǎn)換消耗的資源而發(fā)布的新特性,雖然ORACLE建議利用大頁(yè)機(jī)制來提高數(shù)據(jù)庫(kù)的性能,但是ORACLE卻同時(shí)建議關(guān)閉透明大頁(yè)管理。這二者的區(qū)別在于大頁(yè)的分配機(jī)制,標(biāo)準(zhǔn)大頁(yè)管理是預(yù)分配的方式,而透明大頁(yè)管理則是動(dòng)態(tài)分配的方式。?
[root@getlnx06?~]#?grep?-i?HugePages_Total?/proc/meminfo ? HugePages_Total:?0??
4:cat /proc/sys/vm/nr_hugepages返回0也意味著傳統(tǒng)大頁(yè)禁用了(傳統(tǒng)大頁(yè)和透明大頁(yè))。?
[root@getlnx06?~]#?cat?/proc/sys/vm/nr_hugepages ???
禁用、啟用透明大頁(yè)功能?
??
方法1:設(shè)置/etc/grub.conf文件,在系統(tǒng)啟動(dòng)是禁用。?
[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:設(shè)置/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??
使用上面的配置后必須重啟操作系統(tǒng)才能生效,你也可以運(yùn)行下面命令不用重啟操作系統(tǒng)。?
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?~]#??
小知識(shí)點(diǎn):?
1:從RedHat 6, OEL 6, SLES 11 and UEK2 kernels 開始,系統(tǒng)缺省會(huì)啟用 Transparent HugePages :用來提高內(nèi)存管理的性能透明大頁(yè)(Transparent HugePages )和之前版本中的大頁(yè)功能上類似。主要的區(qū)別是:Transparent HugePages 可以實(shí)時(shí)配置,不需要重啟才能生效配置;?
??
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 時(shí)的開啟透明大頁(yè)(Transparent HugePages ), 因?yàn)橥该鞔箜?yè)(Transparent HugePages ) 存在一些問題:?
??????? 1.在RAC環(huán)境下 透明大頁(yè)(Transparent HugePages )會(huì)導(dǎo)致異常節(jié)點(diǎn)重啟,和性能問題;?
??????? 2.在單機(jī)環(huán)境中,透明大頁(yè)(Transparent HugePages ) 也會(huì)導(dǎo)致一些異常的性能問題;?
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時(shí)也必須關(guān)閉透明大頁(yè)功能。?
??
參考資料:?
https://access.redhat.com/solutions/46111?
http://www.soso.io/article/65143.html?
Linux7.4 關(guān)閉透明大頁(yè)?
在Linux6.x之后的平臺(tái),在安裝Oracle數(shù)據(jù)庫(kù)的時(shí)候都建議關(guān)閉透明大頁(yè)?
Linux下的大頁(yè)分為兩種類型:標(biāo)準(zhǔn)大頁(yè)(Huge Pages)和透明大頁(yè)(Transparent Huge Pages)。?
這兩者的區(qū)別在于大頁(yè)的分配機(jī)制,標(biāo)準(zhǔn)大頁(yè)管理是預(yù)分配的方式,而透明大頁(yè)管理則是動(dòng)態(tài)分配的方式。目前透明大頁(yè)與傳統(tǒng)大頁(yè)混合使用會(huì)出現(xiàn)一些問題,導(dǎo)致性能問題和系統(tǒng)重啟。ORACLE官方不建議在使用RedHat 6, OEL 6, SLES 11 and UEK2 kernels 時(shí)開啟透明大頁(yè)(THP), 因?yàn)橥该鞔箜?yè)存在一些問題:?
1.在RAC環(huán)境下 透明大頁(yè)(Transparent HugePages )會(huì)導(dǎo)致異常節(jié)點(diǎn)重啟和性能問題;?
2.在單機(jī)環(huán)境中,透明大頁(yè)(Transparent HugePages ) 也會(huì)導(dǎo)致一些異常的性能問題;?
2 關(guān)閉THP?
Linux7 默認(rèn)情況下 是開啟透明大頁(yè)功能的。?
檢查系統(tǒng)對(duì)應(yīng)版本??
[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 文件?
執(zhí)行生效命令 grub2-mkconfig -o /boot/grub2/grub.cfg?
重啟??
reboot?
檢查是否生效?
如果你也是grub2的linux系統(tǒng),請(qǐng)通過以下步驟關(guān)閉大內(nèi)存頁(yè)面。?
step1 編輯 /etc/default/grub,在GRUB_CMDLINE_LINUX加入選項(xiàng) 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 重啟你的系統(tǒng)?
至此大功告成,如果你使用的是grub,請(qǐng)把選項(xiàng)寫入grub.conf文件就好了。?
查詢hugepage狀態(tài),第一種方式?
| 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就對(duì)了。?
第二種方式?
| 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就對(duì)了。?
不過有個(gè)小遺憾,重啟后我發(fā)現(xiàn) enabled 是never,但defrag卻依然是always,不過經(jīng)過查詢meminfo,大內(nèi)存頁(yè)面是被禁用了。就不去管他了。?
總結(jié)
以上是生活随笔為你收集整理的Huge pages (标准大页)和 Transparent Huge pages(透明大页)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图像标注-自动标注图像
- 下一篇: 到底咋做,才能业务财务真的一体化