Linux HugePage 特性

    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.

 

4、Regular Pages 与 HugePages

a、Regular Pages

在下图中有两个不同的进程,两个进程对于内存的访问是首先访问本地的page table,而本地的page table又参照了system-wide table的page(也就是前面描述的TLB),最终system-wide table中的entry指向了实际的物理地址。图中物理地址page size大小4kb。也可以看到进程1和进程2在system-wide table中都指向了page2,也就是同一个物理地址。Oracle sga中共享内存的使用会出现上述情形。

 

b、Huge Pages

在下图中,本地的page table 与system page table中都包含了huge page属性。因此page table中的任意一个page可能使用了常规的page,
也有可能使用了huge page。同样进程1和进程2都共享了其中的Hpage2。图中的物理内存常规的page size是4kb,huge page size 是4mb。

--Author : Robinson
--Blog   : http://blog.csdn.net/robinson_0612

 

5、huge page 的大小
huge page 的大小取决于所使用的操作系统的内核版本以及不同的硬件平台
可以使用$grep Hugepagesize /proc/meminfo来查看huge page 的大小
下面是不同平台常用的huge page 的大小。
HW Platform                        Source Code Tree              Kernel 2.4           Kernel 2.6

-----------------                  ---------------------         ------------          -------------
Linux x86 (IA32)                   i386                          4 MB                  4 MB *
Linux x86-64 (AMD64, EM64T)        x86_64                        2 MB                  2 MB
Linux Itanium (IA64)               ia64                          256 MB                256 MB
IBM Power Based Linux (PPC64)      ppc64/powerpc                 N/A **                16 MB
IBM zSeries Based Linux            s390                          N/A                   1 MB
IBM S/390 Based Linux              s390                          N/A                   N/A

 

6、使用huge page的优点
对于较大的系统内存以及sga,使用hugepage可以极大程度的提高Oracle数据库性能。

a、Not swappable

HugePages are not swappable. Therefore there is no page-in/page-out mechanism overhead.HugePages are universally regarded as pinned.

无需交换。也就是不存在页面由于内存空间不足而存在换入换出的问题

 

b、Relief of TLB pressure
Hugepge uses fewer pages to cover the physical address space, so the size of “book keeping” (mapping from the virtual to the physical address) decreases, so it requiring fewer entries in the TLB
TLB entries will cover a larger part of the address space when use HugePages, there will be fewer TLB misses before the entire or most of the SGA is mapped in the SGA
Fewer TLB entries for the SGA also means more for other parts of the address space

减轻TLB的压力,也就是降低了cpu cache可缓存的地址映射压力。由于使用了huge page,相同的内存大小情况下,管理的虚拟地址数量变少。
TLB entry可以包含更多的地址空间,cpu的寻址能力相应的得到了增强。

 

c、Decreased page table overhead

Each page table entry can be as large as 64 bytes and if we are trying to handle 50GB of RAM, the pagetable will be approximately 800MB in size which is practically will not fit in 880MB size lowmem (in 2.4 kernels - the page table is not necessarily in lowmem in 2.6 kernels) considering the other uses of lowmem. When 95% of memory is accessed via 256MB hugepages, this can work with a page table of approximately 40MB in total. See also Document 361468.1.

降低page table负载,对于普通的page,每个entry需要64bytes进行管理,对于50gb的内存,管理这些entry,需要800mb的大小
(50*1024*1024)kb/4kb*64bytes/1024/1024=800mb。

 

d、Eliminated page table lookup overhead

Since the pages are not subject to replacement, page table lookups are not required.( 消除page table查找负载)

 

e、Faster overall memory performance 

On virtual memory systems each memory operation is actually two abstract memory operations. Since there are fewer pages to work on, the possible bottleneck on page table access is clearly avoided.(提高内存的整体性能)      

 

7、未正确配值huge page的风险
基于大内存(>8GB)的管理,如果配值或正确配值huge page,可能存在下列不确定的隐性问题
    HugePages not used (HugePages_Total = HugePages_Free) at all wasting the amount configured for
    Poor database performance
    System running out of memory or excessive swapping
    Some or any database instance cannot be started
    Crucial system services failing (e.g.: CRS)

 

8、基于2.6内核的配值步骤
The kernel parameter used for HugePages is vm.nr_hugepages which is based on the number of the pages. SLES9, RHEL4 and Asianux 2.0 are  examples of distributions with the 2.6 kernel. For the configuration, follow steps below:

    a. Start instance(s)
    b. Calculate nr_hugepages using script from Document 401749.1
    c. Set kernel parameter:
            # sysctl -w vm.nr_hugepages=<value from above>
         and make sure that the parameter is persistent to reboots. e.g. On SLES9:
            # chkconfig boot.sysctl on

    d. Check available hugepages:
            $ grep Huge /proc/meminfo

    e. Restart instances
    f. Check available hugepages:
            $ grep Huge /proc/meminfo

 

9、注意事项
a、HugePage使用的是共享内存,在操作系统启动期间被动态分配并被保留,因为他们不会被置换。
b、由于不会被置换的特点,在使用hugepage的内存不能被其他的进程使用。所以要合理设置该值,避免造成内存浪费。
c、对于只使用Oracle的服务器来说,把Hugepage设置成SGA(所有instance SGA之和)大小即可。
d、如果增加HugePage或添加物理内存或者是当前服务器增加了新的instance以及SGA发生变化,应该重新设置所需的HugePage。
e、reference: HugePages on Linux: What It Is... and What It Is Not... [ID 361323.1] To Bottom
f、如何配置HugePage,请参考:Linux 下配置 HugePages 

 

更多参考

PL/SQL --> 游标

PL/SQL --> 隐式游标(SQL%FOUND)

批量SQL之 FORALL 语句

批量SQL之 BULK COLLECT 子句

PL/SQL 集合的初始化与赋值

PL/SQL 联合数组与嵌套表
PL/SQL 变长数组
PL/SQL --> PL/SQL记录

SQL tuning 步骤

高效SQL语句必杀技

父游标、子游标及共享游标

绑定变量及其优缺点

dbms_xplan之display_cursor函数的使用

dbms_xplan之display函数的使用

执行计划中各字段各模块描述

使用 EXPLAIN PLAN 获取SQL语句执行计划

Oracle ROWID

NULL 值与索引(一)

NULL 值与索引(二)

启用 AUTOTRACE 功能

函数使得索引列失效

Oracle 绑定变量窥探

Oracle 自适应共享游标

Oracle 表空间与数据文件Oracle 密码文件Oracle 参数文件Oracle 联机重做日志文件(ONLINE LOG FILE)Oracle 控制文件(CONTROLFILE)Oracle 归档日志Oracle 回滚(ROLLBACK)和撤销(UNDO)Oracle 数据库实例启动关闭过程Oracle 10g SGA 的自动化管理Oracle 实例和Oracle数据库(Oracle体系结构)

时间: 2024-08-01 15:21:00

Linux HugePage 特性的相关文章

Linux正则表达式特性详解及BRE与ERE的异同点_正则表达式

Linux正则表达式(Regular Expression)主要遵从POSIX BRE或者POSIX ERE标准.什么是POSIX呢,POSIX Portable Operating System Interface 可移植操作系统接口ERE是BRE的扩展版本,具体更强的处理能力,并增加了一些元字符(metacharactor). BRE主要的能力集有: 1) 普通字符(Literal text),如a,b,c等 2)非打印字符,包括TAB,回车,换行,回车换行(WINDOWS) 3)任意字符.

Linux正则表达式特性详解及BRE与ERE的异同点

Linux正则表达式(Regular Expression)主要遵从POSIX BRE或者POSIX ERE标准.什么是POSIX呢,POSIX Portable Operating System Interface 可移植操作系统接口ERE是BRE的扩展版本,具体更强的处理能力,并增加了一些元字符(metacharactor). BRE主要的能力集有: 1) 普通字符(Literal text),如a,b,c等 2)非打印字符,包括TAB,回车,换行,回车换行(WINDOWS) 3)任意字符.

学习Linux之特性综述_unix linux

    LINUX以其优越.稳定的网络服务器性能征服了许许多多的软.硬件制造商和广大计算机迷.据CNET报导,IDC资料显示,Linux在伺服器市场已经夺下第二名的宝座.从1998到1999,Linux在伺服器市场的占有率从16%大幅成长为25%,IDC原本预期Linux将在2002或2003年成为市占率第二,没想到这个预测1999便即实现. LINUX开始于芬兰赫尔辛基大学的Linus Torvalds的业余爱好,当时他想建立一个代替Minix操作系统的.可用于基于Intel的个人计算机上的U

Suse Linux zmd 耗用100% CPU

    最近的Suse Linux 10(SP3)的top命令总是显示zmd进程耗用了100%的CPU资源,而整个系统中system级别占用CPU则占用了40%以上且根本不曾释放.尝试重启服务器之后,故障依旧.下面是这个问题的描述与处理. 1.top命令显示zmd cpu占用100%,system usage 40%以上top - 09:55:10 up 33 days, 13:44,  4 users,  load average: 1.09, 1.12, 1.06Tasks: 217 tot

Linux 下配置 HugePages

    HugePages是通过使用大页内存来取代传统的4kb内存页面,使得管理虚拟地址数变少,加快了从虚拟地址到物理地址的映射以及通过摒弃内存页面的换入换出以提高内存的整体性能.尤其是对于8GB以上的内存以及较大的Oracle SGA size,建议配值并使用HugePage特性.本文基于x86_64 Linux下来描述如何配值 HugePages.    有关HugePages的特性请参考:Linux HugePage 特性   1.为什么需要配值HugePages ?a.Larger Pa

让你的PHP7更快之Hugepage用法分析_php技巧

本文实例讲述了让你的PHP7更快之Hugepage用法.分享给大家供大家参考,具体如下: PHP7刚刚发布了RC4, 包含一些bug修复和一个我们最新的性能提升成果(NEWS), 那就是"HugePageFy PHP TEXT segment", 通过启用这个特性,PHP7会把自身的TEXT段(执行体)"挪"到Huagepage上,之前的测试,我们能稳定的在Wordpress上看到2%~3%的QPS提升. 关于Hugepage是啥,简单的说下就是默认的内存是以4KB

戴文的Linux内核专题:10 配置内核(6)

欢迎来到下一篇关于内核配置文章!还有大量的选项需要配置.这篇文章将主要讨论PCI和ACPI. 这里我们可以启用由ACPI控制的扩展坞和可移动驱动器槽的支持(Dock).记住,ACPI(Advanced Configuration and Power Management Interface)是一个电源管理系统.扩展坞是一种其他的设备通过额外的接口插入的设备.扩展坞可以容纳许多不同的端口和连接器.一个ACPI控制的扩展坞是指其电源管理是通过ACPI进行的.驱动器槽是一套可以增加硬盘的设备,这也可以

Linux到底“错”在哪?

就在刚刚过去的 12 月 14 日,又有一位用户放弃了 Linux 平台,转向了对他来说更好用的 Mac OS .这是他自己的选择,并没有什么应让外人指指点点:但如果从国内最近 Linux 相关论坛的活跃度看来,中国 Linux 用户正在日趋减少却似乎成了事实.如果把这作为背景,那么我们是不是就可以说,正在有更多的人离开 Linux  呢? 这是一个值得再做调查的问题.但是,至少我看见的,他,他和他,都离开了这个他们曾称赞过(或可能称赞过)的平台,专心于 Windows 或 Mac 去了.但是,

Linux 性能诊断 perf使用指南

标签 Linux , perf , 性能诊断 , stap , systemtap , strace , dtrace , dwarf , profiler , perf_events 背景 Linux在服务端已占据非常大的比例,很多业务很多服务都跑在Linux上面. 软件运行在Linux下,软件本身.以及Linux系统的性能诊断也成为热门的话题. 例如,你要如何回答这些问题 Why is the kernel on-CPU so much? What code-paths? Which cod