歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux HugePage 特性

Linux HugePage 特性

日期:2017/2/28 14:50:27   编辑:Linux教程

HugePage,就是指的大頁內存管理方式。與傳統的4kb的普通頁管理方式相比,HugePage為管理大內存(8GB以上)更為高效。本文描述了什麼是HugePage,以及HugePage的一些特性。

1、Hugepage的引入
操作系統對於數據的存取直接從物理內存要比從磁盤讀寫數據要快的多,但是物理內存是有限的,這樣就引出了物理內存與虛擬內存的概念。虛擬內存就是為了滿足物理內存的不足而提出的策略,它是利用磁盤空間虛擬出的一塊邏輯內存,這部分磁盤空間Windows下稱之為虛擬內存,Linux下被稱為交換空間(Swap Space)。

對於這個大內存的管理(物理內存+虛擬內存),大多數操作系統采用了分段或分頁的方式進行管理。分段是粗粒度的管理方式,而分頁則是細粒度管理方式,分頁方式可以避免內存空間的浪費。相應地,也就存在內存的物理地址與虛擬地址的概念。通過前面這兩種方式,CPU必須把虛擬地址轉換程物理內存地址才能真正訪問內存。為了提高這個轉換效率,CPU會緩存最近的虛擬內存地址和物理內存地址的映射關系,並保存在一個由CPU維護的映射表中。為了盡量提高內存的訪問速度,需要在映射表中保存盡量多的映射關系。

linux的內存管理采取的是分頁存取機制,為了保證物理內存能得到充分的利用,內核會按照LRU算法在適當的時候將物理內存中不經常使用的內存頁自動交換到虛擬內存中,而將經常使用的信息保留到物理內存。通常情況下,Linux默認情況下每頁是4K,這就意味著如果物理內存很大,則映射表的條目將會非常多,會影響CPU的檢索效率。因為內存大小是固定的,為了減少映射表的條目,可采取的辦法只有增加頁的尺寸。因此Hugepage便因此而來。也就是打破傳統的小頁面的內存管理方式,使用大頁面2m,4m,16m等等。如此一來映射條目則明顯減少。如果系統有大量的物理內存(大於8G),則物理32位的操作系統還是64位的,都應該使用Hugepage。

2、Hugepage的相關術語

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.

如前所述,page table也就是一種用於內存管理的實現方式,用於物理地址到虛擬之間的映射。因此對於內存的訪問,先是訪問Page Table,然後根據Page Table 中的映射關系,隱式的轉移到物理地址來存取數據。

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.

CPU中的一塊固定大小的cache,包含了部分page table的映射關系,用於快速實現虛擬地址到物理地址的轉換。

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.

hugetlb 是TLB中指向HugePage的一個entry(通常大於4k或預定義頁面大小)。 HugePage 通過hugetlb entries來實現,也可以理解為HugePage 是hugetlb page entry的一個句柄。

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.
一個類似於tmpfs的新的in-memory filesystem,在2.6內核被提出。

3、常見的錯誤概念
WRONG: HugePages is a method to be able to use large SGA on 32-bit VLM systems
RIGHT: HugePages is a method to have larger pages where it is useful for working with very large memory. It is both useful in 32- and 64-bit configurations

WRONG: HugePages cannot be used without USE_INDIRECT_DATA_BUFFERS
RIGHT: HugePages can be used without indirect buffers. 64-bit systems does not need to use indirect buffers to have a large buffer cache for the RDBMS instance and HugePages can be used there too.

WRONG: hugetlbfs means hugetlb
RIGHT: hugetlbfs is a filesystem type **BUT** hugetlb is the mechanism employed in the back where hugetlb can be employed WITHOUT hugetlbfs

WRONG: hugetlbfs means hugepages
RIGHT: hugetlbfs is a filesystem type **BUT** HugePages is the mechanism employed in the back (synonymously with hugetlb) where HugePages can be employed WITHOUT hugetlbfs.

Copyright © Linux教程網 All Rights Reserved