Huge Pages and Transparent Huge Pages

概念:

內存是由塊管理,即衆所周知的頁面。一個頁面有 4096 字節。1MB 內存等於 256 個頁面。1GB 內存等於 256000 個頁面等等。CPU 有內嵌的內存管理單元,這些單元中包含這些頁面列表,每個頁面都使用頁表條目參考。
讓系統管理大量內存有兩種方法:
A.增加硬件內存管理單元中頁表數
B.增大頁面大小
第一個方法很昂貴,因爲現代處理器中的硬件內存管理單元只支持數百或者書籤頁表條目。另外適用於管理數千頁面(MB 內存)硬件和內存管理算法可能無法很好管理數百萬(甚至數十億)頁面。這會造成性能問題:但程序需要使用比內存管理單元支持的更多的頁面,該系統會退回到緩慢的基於軟件的內存管理,從而造成整個系統運行緩慢。
紅帽企業版 Linux 6 採用第二種方法,即使用超大頁面。
簡單說,超大頁面是 2MB 和 1GB 大小的內存塊。2MB 使用的頁表可管理多 GB 內存,而 1GB 頁是 TB 內存的最佳選擇。
超大頁面必須在引導時分配。它們也很難手動管理,且經常需要更改代碼以便可以有效使用。因此紅帽企業版 Linux 也部署了透明超大頁面 (THP)。THP 是一個提取層,可自動創建、管理和使用超大頁面的大多數方面。

THP 系統管理員和開發者減少了很多使用超大頁面的複雜性。因爲 THP 的目的是改進性能,所以其開發者(社區和紅帽開發者)已在各種系統、配置、程序和負載中測試並優化了 THP。這樣可讓 THP 的默認設置改進大多數系統配置性能。


HugePages是Linux 2.6及以上版本內核的一個特性,它允許較大的頁面管理內存,作爲小型4KB頁面大小的替代,它將SGA鎖定到物理內存中,從而無需對SGA進行系統頁表查找。透明HugePages內存與標準HugePages內存不同,因爲內核khugepaged線程在運行時動態分配內存。標準HugePages內存在啓動時預先分配,並且在運行時不會更改。Red
 Hat Enterprise Linux 6,Red Hat Enterprise Linux 7,SUSE 11,Oracle Linux
6和Oracle Linux 7默認啓用透明HugePages內存,早期版本的Oracle Linux具有Unbreakable
Enterprise Kernel 2(UEK2)內核。

透明HugePages雖然比HugePages更加靈活卻可能會在運行時導致內存分配延遲,導致節點重新啓動和性能問題,爲避免性能問題,Oracle建議所有Oracle數據庫服務器上禁用透明HugePages。使用標準HugePages來提高性能。


優點:
Larger Page Size and Less # of Pages: Default page size is 4K whereas the HugeTLB size is 2048K. That means the system would need to handle 512 times less pages.

較大的頁大小與較少的頁數:默認頁大小爲4K,HugeTLB爲2048K,相同條件下,意味着系統需要處理512倍的頁面。


Reduced Page Table Walking: Since a HugePage covers greater contiguous virtual address range than a regular sized page, a probability of getting a TLB hit per TLB entry with HugePages are higher than with regular pages. This reduces the number of times page tables are walked to obtain physical address from a virtual address.

由於HugePage覆蓋了比常規頁面更大的連續虛擬地址範圍,因此使用HugePages獲得每個TLB條目的TLB命中的概率高於常規頁面。這減少了頁面表從虛擬地址獲取物理地址的次數。


Less Overhead for Memory Operations: On virtual memory systems (any modern OS) each memory operation is actually two abstract memory operations. With HugePages, since there are less number of pages to work on, the possible bottleneck on page table access is clearly avoided.

在虛擬內存系統(任何現代操作系統)上,每個內存操作實際上是兩個抽象內存操作。使用HugePages,由於要處理的頁面數量較少,因此可以明顯避免頁表訪問的可能瓶頸。


Less Memory Usage: From the Oracle Database perspective, with HugePages, the Linux kernel will use less memory to create pagetables to maintain virtual to physical mappings for SGA address range, in comparison to regular size pages. This makes more memory to be available for process-private computations or PGA usage.

從Oracle數據庫的角度來看,與常規大小的頁面相比,使用HugePages,Linux內核將使用更少的內存來創建頁表,以維護SGA地址範圍的虛擬到物理映射。這使得更多內存可用於進程專用計算或PGA使用。


No Swapping: We must avoid swapping to happen on Linux OS at all Document 1295478.1. HugePages are not swappable (whereas regular pages are). Therefore there is no page replacement mechanism overhead. HugePages are universally regarded as pinned.

HugePages不可交換(而常規頁面是)。因此,沒有頁面替換機制開銷。HugePages被普遍認爲是固定的。


No 'kswapd' Operations: kswapd will get very busy if there is a very large area to be paged (i.e. 13 million page table entries for 50GB memory) and will use an incredible amount of CPU resource. When HugePages are used, kswapd is not involved in managing them. See also Document 361670.1
如果有一個非常大的區域被分頁(即50GB內存的1300萬頁表條目),kswapd將變得非常繁忙,並將使用大量的CPU資源。使用HugePages時,kswapd不參與管理它們。另見文件361670.1


名詞解釋:

Page Table: A page table is the data structure of a virtual memory system in an operating system to store the mapping between virtual addresses and physical addresses. This means that on a virtual memory system, the memory is accessed by first accessing a page table and then accessing the actual memory location implicitly.
TLB: A Translation Lookaside Buffer (TLB) is a buffer (or cache) in a CPU that contains parts of the page table. This is a fixed size buffer being used to do virtual address translation faster.
hugetlb: This is an entry in the TLB that points to a HugePage (a large/big page larger than regular 4K and predefined in size). HugePages are implemented via hugetlb entries, i.e. we can say that a HugePage is handled by a "hugetlb page entry". The 'hugetlb" term is also (and mostly) used synonymously with a HugePage (See Note 261889.1). In this document the term "HugePage" is going to be used but keep in mind that mostly "hugetlb" refers to the same concept.
hugetlbfs: This is a new in-memory filesystem like tmpfs and is presented by 2.6 kernel. Pages allocated on hugetlbfs type filesystem are allocated in HugePages.


AMM和HugePages不兼容:

MEMORY_TARGET / MEMORY_MAX_TARGET實例初始化參數啓用了11g AMM功能。使用DBCA創建的默認數據庫實例也是如此,從11.2.0.3開始,如果DBCA檢測到機器的RAM超過4GB,則默認情況下不再配置AMM。使用AMM,通過在/ dev / shm下創建文件來分配所有SGA內存。當Oracle DB執行SGA分配時,不會使用HugePages。如果要使用HugePages,請確保爲數據庫實例取消設置MEMORY_TARGET / MEMORY_MAX_TARGET初始化參數(即使用“ALTER SYSTEM RESET”)。在使用HugePages的系統上,嘗試設置MEMORY_TARGET / MEMORY_MAX_TARGET實例初始化參數可能會導致以下錯誤消息:ORA-00845: MEMORY_TARGET not supported on this system


引用:

https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-memory-transhuge 
HugePages on Linux: What It Is... and What It Is Not... (文檔 ID 361323.1)
HugePages on Oracle Linux 64-bit (文檔 ID 361468.1)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章