95992828九五至尊2

Pages再度学习计算

二月 13th, 2019  |  882828九五至尊手机版

 

Linux古板Huge Pages与Transparent Huge Pages再次学习计算,hugetransparent

 

Linux下的大页分为两类别型:标准大页(Huge Pages)和透明大页(Transparent Huge Pages)。Huge
Pages有时候也翻译成大页/标准大页/传统大页,它们都是Huge
Pages的两样中文翻译名而已,顺带提一下以此,免得有人被那几个名词给混淆、误导了。Huge Pages是从Linux Kernel
2.6后被引入的。目的是利用更大的内存页面(memory page size)
以适应越来越大的系列内存,让操作系统可以支撑现代硬件架构的大页面体积功效。透明大页(Transparent Huge Pages)缩写为THP,那几个是RAV4HEL
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.

 

 

奇骏HEL的官方文档对价值观大页(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_TASportageGET为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的性状等等。半数以上皆以逍客HEL官网或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)的页面大小:

 

[[email protected] ~]$ grep Hugepagesize /proc/meminfo

Hugepagesize:     2048 kB

 

肯定标准大页(古板大页/大页/HuagePage)是或不是配备、并在应用的法子:

 

[[email protected] ~]$ cat /proc/sys/vm/nr_hugepages 

0

[[email protected] ~]$ grep -i HugePages_Total /proc/meminfo 

HugePages_Total:     0

 

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

 

规范大页的有些基石参数。如下所示:

 

[[email protected] ~]$ more /etc/issue

Red Hat Enterprise Linux Server release 5.7 (Tikanga)

Kernel \r on an \m

 

[[email protected] ~]$ grep Huge /proc/meminfo

HugePages_Total:     0

HugePages_Free:      0

HugePages_Rsvd:      0

Hugepagesize:     2048 kB

 

[[email protected] ~]# more /etc/issue

Red Hat Enterprise Linux Server release 6.6 (Santiago)

Kernel \r on an \m

 

[[email protected] ~]#  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_奥迪Q3svd:       
已经被分配预留不过还从未选择的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_奥迪Q3svd
那部分是尚未被接纳到的内存,如若没有其他的oracle
instance,那有的内存大概永远都不会被应用到,相当于被荒废了。HugePages_Total-HugePages_Free+HugePages_ENVISIONsvd
就是方今实例须求的页面数量.

 

  

何以设置标准大页(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

 

[[email protected] ~]# 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

 

[[email protected]
~]$ ulimit -l

16384000

 

 

步骤3:
11g中禁用AMM  固然ORACLE 11g要利用规范大页,就非得禁用AMM(Automatic Memory
Management),如果是ORACLE 10g则可以忽略该手续。

 

 

[[email protected] ~]$ 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。设置开始化参数MEMO福特ExplorerY_TARGET 和MEMORY_MAX_TARGET 为0即可。

 

拔取AMM的意况下,所有的SGA 内存都以在/dev/shm
下分配的,因而在分配SGA时不会利用HugePage。那也是AMM
与HugePage不包容的原由。

 

别的:暗中认可意况下ASM instance 也是使用AMM的,但因为ASM
实例不需求徐熙媛(英文名:Barbie Hsu)女士GA,所以对ASM 实例使用HugePages意义不大。

 

即使大家要使用HugePage,那么就务须先确保没有设置MEMO昂科拉Y_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

 

 

[[email protected] ~]# ./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

 

 

 

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

 

[[email protected]
~]# vi /etc/sysctl.conf

 

882828九五至尊手机版,vm.nr_hugepages=4098

 

 

Step 6:
关闭所有的数据库实例比量齐观启服务器。

 

Step 7: 验证配置是还是不是科学,如下所示:

 

[[email protected]
~]$ 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

https://developers.redhat.com/blog/2014/03/10/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

http://www.bkjia.com/Linuxjc/1231396.htmlwww.bkjia.comtruehttp://www.bkjia.com/Linuxjc/1231396.htmlTechArticleLinux传统Huge Pages与Transparent Huge
Pages再度学习总计,hugetransparent Linux
下的大页分为二种档次:标准大页( Huge Pages )和晶莹剔透大页(
Transpare…

Linux下的大页分为两连串型:标准大页(Huge
Pages)和晶莹剔透大页(Transparent Huge Pages)。Huge
Pages有时候也翻译成大页/标准大页/古板大页,它们都是Huge
Pages的两样汉语翻译名而已,顺带提一下以此,免得有人被那一个名词给混淆、误导了。Huge Pages是从Linux Kernel
2.6后被引入的。目的是使用更大的内存页面(memory page size)
以适应越来越大的系统内存,让操作系统可以支撑现代硬件架构的大页面容量功能。透明大页(Transparent Huge
Pages)缩写为THP,这些是途乐HEL 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.

 

 

TiggoHEL的合法文档对价值观大页(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_TA卡宴GET为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的特征等等。大多数都是中华VHEL官网或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_Havalsvd:        已经被分配预留可是还并未动用的page数目。在Oracle刚刚启动时,半数以上内存应该都以Reserved并且Free的,随着ORACLE SGA的使用,Reserved和Free都会没完没了的狂跌

HugePages_Surp:        “surplus”的缩写形式,表示池Chinese Football Association Super League越/proc/sys/vm/nr_hugepages 中值的 HugePages
数量。剩余
HugePages 的最大数额由 /proc/sys/vm/nr_overcommit_hugepages 控制。此值为0的情景很普遍

Hugepagesize:         
页面大小

 

HugePages_Free

HugePages_讴歌MDXsvd 那有的是不曾被利用到的内存,假诺没有任何的oracle
instance,那部分内存或然永远都不会被选取到,约等于被荒废了。HugePages_Total-HugePages_Free+HugePages_Havalsvd
就是现阶段实例要求的页面数量.

 

  

什么设置专业大页(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。设置初叶化参数MEMORAV4Y_TARGET 和MEMORY_MAX_TARGET
为0即可。

 

行使AMM的气象下,所有的SGA 内存都以在/dev/shm
下分配的,由此在分配SGA时不会选择HugePage。那也是AMM 与HugePage不兼容的原委。

 

除此以外:暗中同意景况下ASM instance
也是选用AMM的,但因为ASM 实例不需求徐熙媛女士(英文名:Barbie Hsu)GA,所以对ASM 实例使用HugePages意义不大。

 

若是我们要选用HugePage,那么就务须先保障没有设置MEMO卡宴Y_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

 

882828九五至尊手机版 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

https://developers.redhat.com/blog/2014/03/10/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

相关文章

Your Comments

近期评论

    功能


    网站地图xml地图