OracleLinux传统Huge Pages与Transparent Huge Pages再次上总结

 

Linux下的大页分为两栽档次:标准大页(Huge
Pages)和透亮大页(Transparent Huge Pages)。Huge
Pages有时光吧翻成大页/标准大页/传统大页,它们都是Huge
Pages的不等中文翻译名而已,顺带提一下斯,免得有人叫这些名词给混淆、误导了。Huge Pages是自从Linux Kernel
2.6继被引入的。目的是以重复老的内存页面(memory page size)
以适应更深的系内存,让操作系统可以支持现代硬件架构的酷页面容量功能。透明大页(Transparent Huge
Pages)缩写为THP,这个是RHEL 6(其它分支版本SUSE Linux Enterprise Server 11, and Oracle
Linux 6 with earlier releases of Oracle Linux Unbreakable Enterprise
Kernel 2
(UEK2))开始引入的一个功力。具体可以参照官方文档。这有限啊生出吗区别也?这两者的别在于大页的分配机制,标准大页管理是预分配的艺术,而透明大页管理则是动态分配的方式。相信有成千上万口用Huge Page和Transparent Huge
Pages混为一谈。目前透明大页与传统HugePages联用会出现有题材,导致性问题同系重启。Oracle
建议禁用透明大页(Transparent Huge Pages)。在 Oracle Linux 6.5
版中,已去透明
HugePages。

 

专业大页(HuagePage)英文介绍

 

HugePages
is a feature integrated into the Linux kernel with release 2.6. It is a
method to have larger pages where it is useful for working with very
large memory. It can be useful for both 32-bit and 64-bit
configurations. HugePage sizes vary from 2MB to 256MB, depending on the
kernel version and the hardware architecture. For Oracle Databases,
using HugePages reduces the operating system maintenance of page states,
and increases TLB (Translation Lookaside Buffer) hit ratio.

 

 

RHEL的官方文档对人情大页(Huge
Pages)和晶莹剔透大页(Transparent Huge
Pages)这两边的讲述如下(https://access.redhat.com/documentation/en-US/Red\_Hat\_Enterprise\_Linux/6/html/Performance\_Tuning\_Guide/s-memory-transhuge.html)

 

Huge
pages can be difficult to manage manually, and often require significant
changes to code in order to be used effectively. As such, Red Hat
Enterprise Linux 6 also implemented the use of transparent huge
pages
(THP). THP is an abstraction layer that automates most aspects of
creating, managing, and using huge pages.

 

THP
hides much of the complexity in using huge pages from system
administrators and developers. As the goal of THP is improving
performance, its developers (both from the community and Red Hat) have
tested and optimized THP across a wide range of systems, configurations,
applications, and workloads. This allows the default settings of THP to
improve the performance of most system configurations. However, THP is
not recommended for database workloads.

 

风大页很麻烦手动管理,
而且通常要针对代码进行重点改观才能够立竿见影地用。因此, 红帽企业 Linux 6
实现引入了晶莹剔透大页面 (THP)。THP 是一个抽象层,
可以自行创建、管理及使用传统大页的多数地方。

THP为系统管理员和开发人员减少了累累使用传统大页的扑朔迷离, 因为THP的靶子是改善性能, 因此别开发人员 (来自社区以及红帽)
已在各种系统、配置、应用程序和负载着针对 THP 进行了测试与优化。这样只是吃 THP
的默认设置改进大多数系布局性能。但是, 不建议针对性数据库工作负荷使用 THP。

 

流动:THP
目前只好照射异步内存区域,比如堆和栈空间

 

俺们掌握,x86架构使的是虚拟内存架构,其同意寻址范围越硬件中之可用物理内存。这通过同意每个过程具有好只是寻址的内存来促成。该过程看这内存是把供自己下的。这叫做进程的虚拟内存。实际上,此内存可以是实际上驻留于RAM
芯片上之情理内存,也堪是储存在大体磁盘上于名交换区或分页区的专用区域被。进程不知情虚拟内存是储存在RAM
中尚是磁盘上;内存由操作系统管理。如果所急需内存超过可用物理内存,操作系统会将部分外存移出至分页区。这种活动频率极低,是引致性问题的宽广原因。由于磁盘的存取速度远低于RAM,“分页”的进程会遇到强烈的特性问题。

 

另外,随着硬件的飞速发展,服务器的内存越来越深,系统受采取的内存越多,管理该内存所用的资源为便愈多。对于Linux 操作系统,通过 Linux kswapd 进程和页表(Page
Table)内存结构(针对网被有的每个过程包含一修记下)实现内存管理。每条记下包含进程使的每页虚拟内存及其物理地址(RAM
或磁盘)。通过以微机的TLB( Translation
Lookaside Buffer CPU中一致略片缓存)为该过程提供赞助。操作系统使用页表条目管理体系受经过所用之内存。在 Linux
中,执行之管理之操作系统进程被称为kswapd,可于操作系统工具中找到。TLB
缓存将缓存页表条目来增进性能。典型的 TLB 缓存可保留 4 到 4096
独章。对于数百万竟数十亿个页表条目,这种缓存就不够用了。

 

当大气内存为用来ORACLE数据库或其他以时,操作系统将吃大量资源来保管虚拟地址到大体地址转换,其结果往往是一个那个非常的页表结构(Page
Table)。由于每条页表条目包含进程在下的富有内存页面的虚拟地址到大体地址之更换,因此于充分深的网全局区
(SGA),每个过程的页表条目都可能非常非常。举个例子,我们的一个测试服务器,内存也64GB,SGA_TARGET为32G,如果没使传统大页,页表结构(PageTables)大小也1573080 kB,接近1.5G大小了。您得见见,要治本的页面数量巨大。这将招致显著的性能开销。

 

#
grep PageTables /proc/meminfo

PageTables:      1573080
kB

 

这些就是是人情大页为什么会让引入的来由。
引入其能够解决什么问题呢?内存是出于片管理,即明确的页面。我们了解,在Linux 64各系统里面,默认内存是以4K的页面(Page)来管理之。也就是说一个页面有 4096 字节。1MB 内存等于 256 独页面。2MB内存等于512个页面。管理这些内存的损耗就比较特别。CPU
有内嵌的内存管理单元TLB,这些单元中带有这些页面列表,每个页面都运页表条目。页表(Page
Table)用来存放在虚拟内存和物理内存页对承诺涉及之内存结构。如果page
size较小,那么相应的页表内存结构即见面比老。而Hugepages的默认值page size为2M,是4KB的500倍,所以可以大大削弱小Page
Table的分寸。通过启用
HugePages使用非常页面,可以为此一个页表条目代表一个生页面,而未是动过多条条框框代表于小之页面,从而可以管理还多内存,减少操作系统对页面状态的保障并加强 TLB
缓存命中率。注意,Hugepagesize的大小默认为2M,这个邪是足以调的。区间范围也2MB
to 256MB。

 

使地方就段解释还不够清晰、彻底,那么看看下面就段摘抄的解说:

 

多数操作系统采用了分或分页的章程进行管理。分段是聊粒度的管制章程,而分页则是细粒度管理法,分页方式得以免内存空间的荒废。相应地,也便有内存的物理地址及虚拟地址的定义。通过前这半种植艺术,CPU必须将虚拟地址转换程物理内存地址才能真的访问内存。为了增强是转换效率,CPU会缓存最近底虚拟内存地址及大体内存地址的投关系,并保存在一个由CPU维护的映射表中。为了尽量提高内存的访问速度,需要以映射表中保存尽量多之炫耀关系。Linux的内存管理下的是分页存取机制,为了保险物理内存能得到充分的动,内核会按照LRU算法在相当的早晚以大体内存中不经常应用的外存页自动交换到虚拟内存中,而用经常用的消息保存到大体内存。通常状态下,Linux默认情况下每页是4K,这虽意味着如果物理内存很十分,则映射表的条目将会充分多,会潜移默化CPU的寻找效率。因为内存大小是一定的,为了减小映射表的条款,可利用的主意才发增加页的尺码。因此Hugepage便因此而来。也即是打破传统的小页面的内存管理方法,使用非常页面2M,4M等。如此一来映射条目则明确减小。TLB
缓存命中率将大大提高。

 

 

设ORACLE为什么而下专业大页(Huge
Pages)来增强性?因为ORACLE数据库使用共享内存(SGA)来保管得共享的片资源;比如shared pool中蕴藏了共享的SQL语句及执行计划,buffer
pool中贮存了数据块。对这些资源的造访,其实就是是ORACLE使用OS的API来访问内存资源的过程。内存操作理应/通常意义及且是快的,这时候Oracle数据库可生健康的做事。但是发生几情况下吧会起性能问题:

 

a)如果SGA内的某平组成部分被swap到硬盘上,那么又访问它,就得花费大多之时空。

 

b)如果OS本身的内存非常的不得了,那么管理/访问到我们需要的内存的过程尽管需要再行增长日子。

 

当这些情形下,我们数会遇见诸如latch/mutex/library cache
lock[pin]/row cache lock的问题.

 

Linux下HugePage可以化解由于上述两栽问题引发的性质波动。

 

咱俩了解,在Linux 64各项系统里面,默认内存是以4K的页面(Page)来治本之,当系统发生那个多之内存的时光,管理这些内存的吃就于坏;而HugePage使用2M分寸的页面来减多少管理支付。HugePage管理的内存并无克为Swap,这即避免了Swap引发的数据库性能问题。所以,如果您的网时遇到以swap引发的习性问题之系毫无疑问要启用HugePage。另外,OS内存非常坏之系统吧用启用HugePage。但是具体多可怜就是必将要以HugePage?这并不曾结论,有些文档曾经关系12G以上就引进开启,我们强烈建议您于测试环境进行了充分的测试之后,再决定是否当生产环境下HugePage。

 

本来,任何工作还是产生两面性的,HugePage也来若干稍瑕疵。第一只缺陷是其要格外安排,但是这一点一滴是可以忽略的。另外, 如果使用了HugePage,11g新特性 AMM(Automatic Memory
Management)就未能够采用了,但是ASMM(Automatic Shared Memory
Management)仍然可继续行使。

 

下面是部分系名词和Huge
Pages的性状等等。大部分还是RHEL官网或Mos上系英文材料以及对应的有些翻译:

 

·        
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.

 

HugePages
in 2.4 Kernels

 

The
HugePages feature is backported to some 2.4 kernels. Kernel versions
2.4.21-* has this feature (See Note 311504.1 for the distributions with
2.4.21 kernels) but it is implemented in a different way. The feature is
completely available. The difference from 2.6 implementation is the
organization within the source code and the kernel parameters that are
used for configuring HugePages. See Parameters/Setup section
below.

 

 

Advantages
of HugePages Over Normal Sharing Or AMM (see below)

 

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

 

 

    不可交换:HugePages不可交换。 因此没有页面换入/页面换来之建制初步销.HugePages被普遍认为是原则性在RAM中之。

 

·        
Relief
of TLB pressure:

o   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

o   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

o   Fewer
TLB entries for the SGA also means more for other parts of the address
space

 

    减轻TLB的压力

 

    Hugepge使用于少的页面来覆盖物理地址空间,因此“保留书签”(从虚拟地址到大体地址之投射)的深浅减少,因此在TLB中求比少的条文

    当使用HugePages时,TLB条目将涵盖更特别的地方空间,对于SGA中之整个要大部分之外存映射,TLB未命中将会大大减少。

    SGA需要再行少的TLB条目意味着TLB中可发再多之条文来保存其他地方空间。

 

    TLB是一直缓存虚拟地址到大体地址的缓存表,用于升级性,省去查找page
table从而减少支出,但是一旦起的大气的TLB
miss,必然会吃系统的性带来比较充分的负面影响,尤其对连日来的宣读操作。从第二首稿子中我们解如果应用hugepages能大量调减PTE的数码,也就是表示访问同多之情节需之PTE会更不见,而通常TLB的槽位是简单的,一般只有发512只,所以又少的PTE也就算代表又胜之TLB的命中率。

 

·        
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.

 

    减少页表的开销:每个页表条目可以高及64字节,如果我们50GB的RAM保存在页表(page table)当中,那么页表(page
table)大小约为800MB,实际上对lowmem来说,考虑到lowmem的其他用途,880MB大小是匪得当的(在2.4舅核当中 ,page tabel在低于2.6的根本当中无是必须的), lowmem中经256MB的hugepages访问95%的内存时,可以运用大约40MB的页表。
另见文档361468.1。

 

·        
Eliminated
page table lookup overhead: Since the pages are not subject to
replacement, page table lookups are not required.

 

   减少页表查询的开发:PTE的多寡缩减,那么让森页表的查询就不需了,并且又不见的PTE使得页表的询问更快。如果TLB
miss,则可能需要额外三破内存读取操作才能够拿线性地址翻译为大体地址。

 

  

·        
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.

 

      提升内存访问的整性能:应用虚拟内存,每一样糟糕针对内存的看实际上都是由于个别次等抽象的内存操作成。如果假定使用更不见之页面,那么原来以页表访问的瓶颈也得避免

 

HugePages
Reservation

 

The
HugePages reservation feature is fully implemented in 2.6.17 kernel, and
thus EL5 (based on 2.6.18) has this feature. The alloc_huge_page() is
improved for this. (See kernel source mm/hugetlb.c)

 

From
/usr/share/doc/kernel-doc-2.6.18/Documentation/vm/hugetlbpage.txt:

HugePages_Rsvd
is short for “reserved,” and is the number of hugepages for which a
commitment to allocate from the pool has been made, but no allocation
has yet been made. It’s vaguely analogous to overcommit.

This
feature in the Linux kernel enables the Oracle Database to be able to
allocate hugepages for the sublevels of the SGA on-demand. The same
behaviour is expected for various Oracle Database versions that are
certified on EL5.

 

HugePages
and Oracle 11g Automatic Memory Management (AMM)

 

The
AMM and HugePages are not compatible. One needs to disable AMM on 11g to
be able to use HugePages. See Document 749851.1 for further
information.

 

 

于Linux中,
kswapd是负担基本页面交换管理之一个医护进程,它的天职是保Linux内存管理操作的神速。当物理内存不够时,它便会转换得不可开交aggressive,有些情况下能占据单核CPU的100%.  
kswapd 进程负责管内存空间总是在为放被,它监控内核中的pages_high和pages_low阀值。如果空闲内存的数值低于pages_low,则每次 kswapd
进程启动扫描并尝试释放32单free pages.并一直重复是过程,直到空闲内存的数值高于 pages_high。kswapd
进程就以下几只操作:

o   
如果该页处于无修改状态,则以该页放置回空闲列表中.

o   
如果该页处于已经改状态并而备份回文件系统,则用页内容写副到磁盘.

o   
如果该页处于已经改状态而没有其余磁盘备份,则拿页内容写副到swap device.

 

 

专业大页的配备查看

 

查阅标准大页(Huage
Pages)的页面大小:

 

[root@DB-Server ~]$ grep Hugepagesize /proc/meminfo

Hugepagesize:     2048 kB

 

肯定标准大页(传统大页/大页/HuagePage)是否配备、并当使的办法:

 

[oracle@DB-Server ~]$ cat /proc/sys/vm/nr_hugepages 

0

[oracle@DB-Server ~]$ grep -i HugePages_Total /proc/meminfo 

HugePages_Total:     0

 

如果HugePages_Total为0,意味着正式大页(大页、传统大页)没有装或用。nr_hugepages为0,意味着正式大页没有设置。

 

业内大页的一对基础参数。如下所示:

 

[oracle@DB-Server ~]$ more /etc/issue

Red Hat Enterprise Linux Server release 5.7 (Tikanga)

Kernel \r on an \m

 

[oracle@DB-Server ~]$ grep Huge /proc/meminfo

HugePages_Total:     0

HugePages_Free:      0

HugePages_Rsvd:      0

Hugepagesize:     2048 kB

 

[root@mylnx02 ~]# more /etc/issue

Red Hat Enterprise Linux Server release 6.6 (Santiago)

Kernel \r on an \m

 

[root@mylnx02 ~]#  grep Huge /proc/meminfo

AnonHugePages:     18432 kB

HugePages_Total:       0

HugePages_Free:        0

HugePages_Rsvd:        0

HugePages_Surp:        0

Hugepagesize:       2048 kB

 

AnonHugePages:         匿名 HugePages 数量。Oracle Linux 6.5
中早就去除此计数器。与透明 HugePages 有关。

HugePages_Total:       分配的页面数目,和Hugepagesize相乘后取所分配的内存大小

HugePages_Free:        从来没让用了之Hugepages数目。即使oracle
sga已经分配了立有内存,但是要没有实际写入,那么看看底尚是Free的。这是很易误解的地方(池中从不分配的 HugePages 数量。)

HugePages_Rsvd:        已经被分配预留但是还没行使的page数目。在Oracle刚刚起步时,大部分内存应该还是Reserved并且Free的,随着ORACLE SGA的下,Reserved和Free都见面随地的骤降

HugePages_Surp:        “surplus”的缩写形式,表示池中胜出/proc/sys/vm/nr_hugepages 中值的 HugePages
数量。剩余
HugePages 的尽酷数量由 /proc/sys/vm/nr_overcommit_hugepages 控制。此值为0的情状万分常见

Hugepagesize:         
页面大小

 

HugePages_Free

HugePages_Rsvd 这有的凡是绝非为采取及的内存,如果无任何的oracle
instance,这部分内存也许永远都未会见受运用到,也即是给荒废了。HugePages_Total-HugePages_Free+HugePages_Rsvd
就是眼下实例需要之页面数量.

 

  

怎么设置标准大页(Huge
Page)的轻重缓急也?一般都是修改内核参数nr_hugepages。在/etc/sysctl.conf配置文件被设置参数vm.nr_hugepages

 

#
echo “vm.nr_hugepages=512” >> /etc/sysctl.conf

 

下我们来介绍一下,在64各类Linux服务器下为ORACLE数据库设置规范大页的中坚步骤,具体要基于实际状况作出调整。关于怎样安排标准大页,可以参照官方文档HugePages on Oracle Linux 64-bit
(文档 ID
361468.1)或文档(Configuring HugePages for Oracle on Linux
(x86-64))来演示一下安设置Huge Pages。

 

步骤1:在/etc/security/limits.conf文件中上加memlock的范围,注意该值略轻于实际物理内存的轻重缓急(单位也KB)。比如物理内存是64GB,可以设置为如下:

 

*
 
soft 

memlock   
60397977

*
 
hard    memlock
 
   60397977

 

只要此的值超过了SGA的求,也从不不利于的熏陶。如果采取了Oracle Linux的oracle­-validated包,或者Exadata DB
compute则会活动配置是参数。下面来探视一个实际测试环境,内存也16G

 

[root@mylnx02 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:         16077       9520       6556          0         37        766

-/+ buffers/cache:       8716       7361

Swap:        14015          0      14015

 

 

那我们修改/etc/security/limits.conf,设置memlock的价值吗16384000(16077*1024)

 

 vi
/etc/security/limits.conf

 

*
soft memlock 16384000

*
hard memlock 16384000

 

 

步骤2:重新登录安装Oracle产品之账号并证实memlock。如下所示,当前测试环境的账号也oracle

 

[oracle@mylnx02
~]$ ulimit -l

16384000

 

 

手续3: 11g遇禁用AMM  如果ORACLE
11g假设运用专业大页,就非得禁用AMM(Automatic
Memory Management),如果是ORACLE
10g虽说足以忽略该步骤。

 

 

[oracle@DB-Server ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 27 14:43:12 2017

 

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

SQL> show parameter memory_target;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

memory_target                        big integer 1552M

SQL> show parameter memory_max_target;

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

memory_max_target                    big integer 1552M

SQL> 

 

SQL> alter system set memory_target=0 scope=both;

SQL> alter system set memory_max_target=0 scope=spfile;

 

 

 

若果Oracle 是11g以后的本子,那么默认创建的实例会使Automatic Memory Management
(AMM)的风味,该特性和HugePage不兼容。在装HugePage之前要事先禁用AMM。设置初始化参数MEMORY_TARGET 和MEMORY_MAX_TARGET
为0即可。

 

利用AMM的动静下,所有的SGA 内存都是当/dev/shm
下分配的,因此当分配SGA时无会见动HugePage。这为是AMM 与HugePage不兼容的来由。

 

此外:默认情况下ASM instance
也是采用AMM的,但以ASM 实例不待大SGA,所以对ASM 实例使用HugePages意义不深。

 

倘我们若以HugePage,那么就算非得先保证无安装MEMORY_TARGET/
MEMORY_MAX_TARGET参数。

 

 

步骤4:确保您所有的ORACLE数据库实例都曾经启动(包括ASM实例),然后运行hugepages_settings.sh(具体参考Mos文档Document
401749.1,脚本内容如下)获取基本参数vm.nr_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" ];then

    echo "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]*"`

do

    MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`

    if [ $MIN_PG -gt 0 ]; then

        NUM_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 ]; then

    echo "***********"

    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

 

 

[root@mylnx02 ~]# ./hugepages_settings.sh 

 

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...

 

Recommended setting: vm.nr_hugepages = 4098

 

Oracle 1

 

 

Step
5:在/etc/sysctl.conf文件中安vm.nr_hugepages参数

 

[root@mylnx02
~]# vi /etc/sysctl.conf

 

vm.nr_hugepages=4098

 

 

Step
6:
关闭所有的数据库实例并再次开服务器。

 

Step
7:
验证配置是否正确,如下所示:

 

[oracle@mylnx02
~]$ grep HugePages /proc/meminfo

HugePages_Total:    4098

HugePages_Free:     3439

HugePages_Rsvd:     3438

HugePages_Surp:        0

 

以保证HugePages配置的行,HugePages_Free值应该小于HugePages_Total
的价,并且有早晚之HugePages_Rsvd的值。

 

The
values in the output will vary. To make sure that the configuration is
valid, the HugePages_Free value should be smaller than
HugePages_Total and there should be some HugePages_Rsvd.
HugePages_Rsvd counts free pages that are reserved for use (requested
for an SGA, but not touched/mapped yet).

The
sum of Hugepages_Free and HugePages_Rsvd may be smaller than your
total combined SGA as instances allocate pages dynamically and
proactively as needed.

 

Oracle
11.2.0.3及后来版本
,可以经检查警报日志来验证是否对准数据库实例启用了好页面。启动实例时,您应于警报日志被参数列表前面看到如下内容:

 

******************
Large Pages Information *****************

 

 Total Shared
Global Region in Large Pages = 28 GB (100%)

 

 Large Pages used
by this instance: 14497 (28 GB)

Large
Pages unused system wide = 1015 (2030 MB) (alloc incr 64 MB)

Large
Pages configured system wide = 19680 (38 GB)

Large
Page size = 2048 KB

 

另外,可以经过以下参数控制数据库对HugePage的动办法(11gr2之后):

use_large_pages
= {true/only/false/auto}

默认值是true,如果系统安装Hugepages的讲话,SGA会优先利用hugepages,有略用微。如果安也false, SGA就不见面采用hugepages。如果安也only 如果hugepages大小不够的话,数据库实例是无法启动的。设置为auto,这个选项会触发oradism进程重新配置linux内核,以多hugepages的多寡。一般设置也true。

 

SQL>
alter system set use_large_pages=true scope=spfile sid=’*’;

 

 

启用透明大页

 

启用透明大页非常简单,可以参考这首博客Linux
关于Transparent
Hugepages的介绍,
这里不开赘述。

 

 

 

参考资料:

 

https://help.marklogic.com/Knowledgebase/Article/View/16/0/linux-huge-pages-and-transparent-huge-pages

https://support.oracle.com/epmos/faces/DocumentDisplay?parent=DOCUMENT&sourceId=361468.1&id=401749.1

http://www.oracle.com/technetwork/cn/articles/servers-storage-dev/hugepages-2099009-zhs.html

https://support.oracle.com/epmos/faces/DocumentDisplay?\_afrLoop=500381499574891&id=361323.1&\_afrWindowMode=0&\_adf.ctrl-state=lxb6cxp3\_100

Examining Huge Pages or Transparent Huge Pages performance

https://oracle-base.com/articles/linux/configuring-huge-pages-for-oracle-on-linux-64

 

https://access.redhat.com/documentation/zh-CN/Red\_Hat\_Enterprise\_Linux/6/html/Performance\_Tuning\_Guide/s-memory-transhuge.html

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/sect-Oracle_9i_and_10g_Tuning_Guide-Large_Memory_Optimization_Big_Pages_and_Huge_Pages-Configuring_Huge_Pages_in_Red_Hat_Enterprise_Linux_4_or_5.html

https://blogs.oracle.com/database4cn/linux-64hugepage

https://docs.oracle.com/cd/E11882\_01/install.112/e41961/memry.htm\#CBAFIFGJ

相关文章