Oracle数据库配置大页

0    1601    10

Tags:

👉 本文共约4865个字,系统预计阅读时间或需19分钟。

简介

有关大页和透明大页的介绍:https://www.dbaup.com/linux-biaozhundayehetoumingdaye.html

在Linux中配置hugepage可以提高oracle的性能,减少oracle sga的页交换,类似于aix中的lagepage。
当你主机的物理内存为64G,设SGA>=32G时,建议开启大页。

要查看是否存在大页表的问题,可以使用如下的命令来检查页表的大小:

如果发现页表的大小不是几十兆,而是达到了1GB以上,就说明数据库存在此问题。基于共享内存的多进程架构的程序都会存在此问题。

Oracle 官方是推荐我们使用 Huge pages 的,它拥有以下的好处:

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

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

  • Less Overhead for MemoryOperations: On virtual memory systems (any modern OS) each memory operation isactually two abstract memory operations. With HugePages, since there are lessnumber of pages to work on, the possible bottleneck on page table access isclearly avoided.

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

  • No Swapping: We must avoidswapping to happen on Linux OS at all Document 1295478.1. HugePages are notswappable (whereas regular pages are). Therefore there is no page replacementmechanism overhead. HugePages are universally regarded as pinned.

  • No 'kswapd' Operations: kswapdwill get very busy if there is a very large area to be paged (i.e. 13 millionpage table entries for 50GB memory) and will use an incredible amount of CPUresource. When HugePages are used, kswapd is not involved in managing them. Seealso Document 361670.1

Huge pages 和 Oracle 11g新 特性 AMM ( Automatic Memory Management )是相互冲突的,但是 ASMM ( Automatic Shared Memory Management )仍然可以继续使用。

Oracle 官方推荐我们使用 标准大页(Huge pages ),但是却建议我们关闭 透明大页(Transparent Huge pages) ,因为透明大页存在一些问题:

  1. 在 RAC 环境下 透明大页( TransparentHugePages )会导致异常节点重启,和性能问题;
  2. 在单机环境中,透明大页( TransparentHugePages ) 也会导致一些异常的性能问题;

    如何关闭透明大页请参考:https://www.dbaup.com/linux-biaozhundayehetoumingdaye.html

如何配置开启大页

参考:HugePages on Oracle Linux 64-bit (Doc ID 361468.1)

  1. 在 /etc/security/limits.conf 加入以下参数,单位为KB,值比内存稍微少一点即可,例如内存为16GB,那么可以如下设置:

memlock 参数的值只需略小于内存的值即可,但是必须大于sga_max_size的值。

也可以直接配置-1,表示不限制:

注意:这里需要仔细查看文件/etc/security/limits.conf的内容,若文件有如下内容,则需要手动注释,或删除如下内容:

  1. 重新以oracle用户登录服务器验证设置

  1. 在 Oracle 11g 中禁用 AutomaticMemory Management (AMM) 特性,即 设置MEMORY_TARGET和MEMORY_MAX_TARGET 值为0 。因为AMM和大页特性不兼容。注意:若有ASM实例,那么ASM实例也应该使用ASMM。

    在Linux操作系统推荐配置HugePages,以至于ASM和数据库实例的SGA都能使用HugePage来提高性能。ASM实例的SGA同样有必要使用HugePage来提高性能。

这里的环境并没有启用 AMM 特性,如果启用了AMM,那么请使用以下语句关闭,并从spfile中删除该参数:

重启实例后生效。

Note: Starting in 11.2.0.3, AMM is no longer configured by default if DBCA detects that the machine has more than 4GB of RAM. See Document 1453227.1 for details.

  1. 确认所有需要使用 Hugepage 的数据库实例都是开启的 ( 包括 ASM 实例 ) ,然后运行脚本 hugepages_settings.sh(具体脚本参考文档 Document 401749.1)来计算*vm.nr_hugepages*kernel的值。

实际上hugepages与参数sga_max_size有关,比sga_max_size的值稍微大一点点(比SGA_MAX_SIZE最少要多加一页,2M的页不要分配超过sga_max_size太多,会造成内存的浪费)。

本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信dbaup66,谢谢!

注意:使用Hugepage内存是共享内存,它会一直keep在内存中的,不会被交换出去,也就是说使用hurgepage的内存不能被其他的进程使用,所以,一定要合理设置这个值,避免造成浪费。对于只使用Oracle的服务器来说,把Hugepage_pool设置成大于SGA大小才能被Oracle使用。

  1. 在 /etc/sysctl.conf 文件中添加 vm.nr_hugepages 参数,使用sysctl -p立即生效:

使用命令grep -i HugePage /proc/meminfo查看,如果HugePages_Free未到设定的值,那么可以多执行几次sysctl -p,或者重启OS。

  1. 关闭所有数据库实例重启服务器

    关闭数据库实例后,再重启数据库服务器!!

    重启数据库过程中不断执行cat /proc/meminfo |grep Huge,能看到HugePages_Free的数量不断减少,说明大页正在被使用。

  2. 验证配置是否正确,页表不能大页1GB,used的值很高,如下所示:

为了确保 HugePages 配置的有效性, HugePages_Free 值应该小于 HugePages_Total 的值,并且有一定的HugePages_Rsvd 的值。

  • AnonHugePages:0KB //统计的是Transparent HugePages (THP)
  • HugePages_Total: 5122 //预留HugePages的总个数
  • HugePages_Free: 16 //池中尚未分配的 HugePages 数量,真正空闲的页数等于HugePages_Free - HugePages_Rsvd
  • HugePages_Rsvd: 0 //表示池中已经被应用程序分配但尚未使用的 HugePages 数量
  • HugePages_Surp: 0 //这个值得意思是当开始配置了20个大页,现在修改配置为16,那么这个参数就会显示为4,一般不修改配置,这个值都是0
  • Hugepagesize: 2048 kB //每个大页的大小

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.

Also there should be some HugePages_Rsvd if PRE_PAGE_SGA is 'false' for all the Oracle database instances.. HugePages_Rsvd counts free pages that are reserved for use (requested for an SGA, but not touched/mapped yet). PRE_PAGE_SGA determines if the all SGA pages are read-in when the instance starts up. If parameter is set to 'true' then the OS page table entries are prebuilt for each page of the SGA, leading to HugePages reservation of those pages. For Oracle database versions before 12.1 the default value for PRE_PAGE_SGA is 'false'. So the HugePages_Rsvd would be higher than 0. But since 12c the PRE_PAGE_SGA defaults to 'true' which would cause the HugePages_Rsvd to be 0.

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.

  1. 若有必要,请修改sga_max_size参数,如下所示:

若增大sga_max_size参数,请注意/etc/security/limits.conf/etc/sysctl.conf中有关内存限制的参数。

至此,在Oracle中的 HugePages 已经配置完成。

数据库参数use_large_pages

在11.2.0.2的时候,Oracle新添加入一个参数USE_LARGE_PAGES来使用大页。USE_LARGE_PAGES最初是为了应对Bug 9195408而引入的,这个Bug的起因是当HugePage不足时候,Oracle一些的行为方式问题。在11.2.0.2版本上,如果数据库服务器上没有空闲的HugePage使用,只有一些small pages使用的时候,会导致ORA-4030错误。

在11.2.0.3的时候,这个参数让Oracle的行为更加灵活。如果出现HugePage分配不足的情况,SGA是可以使用那些small pages的。这就保证了极端情况下数据库是可以正常运行的。

USE_LARGE_PAGES参数取值有5个,分别为AUTO_ONLY, FALSE, ONLY, AUTO, TRUE,默认为true。

  • 当该参数取值为True的时候,即使数据库是AMM情况,系统启动是没有问题的。但是,在Linux HugePage功能启用的情况下,Oracle并没有使用大页的功能。当系统的HugePage被使用完后,在只有small pages的情况下,SGA也会继续运行。此时,Oracle实例就运行在内存使用混合模式(Mixed Mode)下。

  • 当该参数取值为only的时候,表示Oracle实例只会使用HugePage作为内存使用。如果系统在AMM模式或者HugePage用尽的时候,数据库就不能启动或者报错。

  • 当该参数取值为auto的时候,若HugePage不够的时候,会自动进行扩展,但是需要安装组件。

脚本hugepages_settings.sh

故障解决

Some of the common problems and how to troubleshoot them are listed in the following table:

SymptomPossible CauseTroubleshooting Action
System is running out of memory or swappingNot enough HugePages to cover the SGA(s) and therefore the area reserved for HugePages are wasted where SGAs are allocated through regular pages.Review your HugePages configuration to make sure that all SGA(s) are covered.
Databases fail to startmemlock limits are not set properlyMake sure the settings in limits.conf apply to database owner account.
One of the database fail to start while another is upThe SGA of the specific database could not find available HugePages and remaining RAM is not enough.Make sure that the RAM and HugePages are enough to cover all your database SGAs
Cluster Ready Services (CRS) fail to startHugePages configured too large (maybe larger than installed RAM)Make sure the total SGA is less than the installed RAM and re-calculate HugePages.
HugePages_Total = HugePages_FreeHugePages are not used at all. No database instances are up or using AMM.Disable AMM and make sure that the database instances are up. See Doc ID 1373255.1
Database started successfully and the performance is slowThe SGA of the specific database could not find available HugePages and therefore the SGA is handled by regular pages, which leads to slow performanceMake sure that the HugePages are many enough to cover all your database SGAs

大页配置错误导致内存耗尽进而导致PMON (ospid: 12917): terminating the instance due to error 471

参考:https://www.dbaup.com/dayepeizhicuowudaozhineicunhaojinjinerdaozhipmon-ospid-12917-terminating-the-instance-due-to.html

ORA-27102 out of memory和Linux-x86_64 Error: 28: No space left on device

参数kernel.shmall配置太小导致,解决如下:

重启数据库即可。

参考:https://www.dbaup.com/neihecanshukernel-shmallpeizhitaixiaodaozhiora-27102-out-of-memoryhelinux-x86_64-error-28-no-spa.html

总结

1、对于rac系统来说,可以2个节点依次来配置大页,从而减少影响业务停机时间。

参考

HugePages on Oracle Linux 64-bit (Doc ID 361468.1)

Oracle Linux: Shell Script to Calculate Values Recommended Linux HugePages / HugeTLB Configuration (Doc ID 401749.1)

HugePages on Linux: What It Is... and What It Is Not... (Doc ID 361323.1)

https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复