Oracle数据库内存耗尽,大页惹的祸?

2024年 3月 8日 119.5k 0

目录:

    一:启用大页导致内存耗尽场景
    1.如何正确开启大页
    二:use_large_pages参数影响
    三:HugePages说明
    四:何时启用HugePages
    五:使用HugePages性能提升多大
    六:配置HugePages存在哪些限制
    七:参考链接
    八:hugepages_settings.sh脚本内容

    一:内存耗尽场景

    问题现象:

    Oracle数据库服务器内存资源耗尽,数据库无响应。

    问题原因:

    原linux环境没有启用HugePages,启用HugePages后,内存使用率直线上涨,最终内存资源耗尽。

    启用HugePages明明是提高性能,为什么会导致内存资源耗尽呢?这和HugePages内存分配机制有关:

    例如当前配置信息如下:

    数据库服务器总内存128GB,SGA分配75GB,PGA分配30GB,SGA+PGA占总内存82%。

    通常启用HugePages大页时,会将HugePages设置为偏大于SGA值,例如76G。

    但如果设置HugePages比SGA值小,会出现什么情况?

    例如:将HugePages设置为70GB。

    此时服务器内存最大会分出70GB给HugePages使用,但是由于HugePages show parameter spfile
    SQL> ho cp oracle/app/oracle/product/11.2/db/dbs/spfilecjc.ora home/oracle/spfilecjc.ora.bak

    将AMM转换为ASMM

      alter system reset memory_target scope=spfile;
      ---alter system reset memory_max_target scope=spfile;
      alter system set sga_max_size=1970M scope=spfile;
      alter system set sga_target=1970M scope=spfile;
      alter system set pga_aggregate_target=980M scope=spfile;

      重启数据库

        SQL> shutdown immediate
        SQL> startup

        1.1正确启用HugePages方法:

        1 启动前,检查基本信息

          [root@cjc-db-01 ~]# grep Huge proc/meminfo
          AnonHugePages: 100352 kB
          HugePages_Total: 0
          HugePages_Free: 0
          HugePages_Rsvd: 0
          HugePages_Surp: 0
          Hugepagesize: 2048 kB

            [root@cjc-db-01 ~]# uname -sr
            Linux 4.1.12-112.16.4.el7uek.x86_64

              [root@cjc-db-01 ~]# cat proc/meminfo|grep PageTables


              PageTables: 38084 kB

                [root@cjc-db-01 ~]# free -h
                total used free shared buff/cache available
                Mem: 3.6G 490M 2.2G 289M 918M 1.9G
                Swap: 2.0G 0B 2.0G

                2 配置memlock

                在/etc/security/limits.conf文件中设置memlock值,memlock设置以KB为单位。

                当启用HugePages内存时,最大锁定内存限制应至少设置为当前服务器内存的90%。

                禁用HugePages内存时,最大锁定内存限制应设置为至少3145728 KB(3 GB)。

                例如,如果安装了64 GB RAM,则添加以下条目以增加最大锁定内存地址空间:

                  * soft memlock 60397977
                  * hard memlock 60397977

                  也可以将memlock值设置为高于SGA要求的值,或者设置为unlimited

                    oracle soft memlock unlimited
                    oracle hard memlock unlimited

                    再次以oracle用户身份登录并运行ulimit-l命令以验证新的memlock设置

                      [oracle@cjc-db-01 ~]$ ulimit -l
                      Unlimited

                      3 检查并启动实例

                      RAC:

                      检查实例是启动状态

                        srvctl status instance -d dbname

                        如果没启动,手动启动实例

                          srvctl start instance -d dbname -i instance_name -o open

                          单机:

                            SQL> select status from v$instance;

                            4 使用脚本为当前共享内存段计算hugepages配置的建议值:

                            root用户下执行

                              chmod +x hugepages_settings.sh
                              ./hugepages_settings.sh

                              备注:脚本内容见末尾

                              脚本来自My Oracle Support note 401749.1 

                              例如:

                                [root@cjc-db-01 oracle]# ./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 the overall 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 = 996

                                  最终计算出的vm.nr_hugepages建议值为996,tmd数字不吉利。

                                  其中996乘以2MB=1992MB > sga_target(1970MB)

                                  执行脚本除了看vm.nr_hugepages,也要关注下其他内容:

                                  在执行之前,请注意以下事项:

                                    (1)对于ASM实例,需要配置ASMM而不是AMM。
                                    (2)“pga_gaggregate_target”位于SGA之外,在计算总体大小时应考虑到这一点。
                                    (3)如果更改了DB SGA的大小,因为新的SGA将不适合以前的HugePage配置,因此最好禁用整个HugePage,用新SGA大小启动DB,然后再次运行脚本。
                                    并确保:
                                    (1)数据库实例是启动运行的;
                                    (2)HugePages and Oracle Database Automatic Memory Management (AMM) on Linux (Doc ID 749851.1)
                                    (3)共享内存段可以通过以下命令列出:
                                    # ipcs -m

                                    5 停止数据库实例

                                      RAC:
                                      srvctl stop instance -d dbname -i instance_name -o immediate
                                      单机:
                                      SQL> shutdown immediate

                                      6 设置vm.nr_hugepages内核参数

                                      写入配置文件,永久生效

                                        vi etc/sysctl.conf
                                        vm.nr_hugepages=996
                                        wq

                                        # sysctl -w vm.nr_hugepages= 临时改变,重启失效

                                        本次示例:996

                                          sysctl -p

                                          查询

                                            [root@cjc-db-01 ~]# grep Huge proc/meminfo
                                            AnonHugePages: 98304 kB
                                            HugePages_Total: 996
                                            HugePages_Free: 996
                                            HugePages_Rsvd: 0
                                            HugePages_Surp: 0
                                            Hugepagesize: 2048 kB

                                            7 启动实例

                                              RAC:
                                              srvctl start instance -d dbname -i instance_name -o open
                                              单机:
                                              SQL> startup

                                              查看alert_cjc.log日志信息:

                                                Starting ORACLE instance (normal)
                                                ************************ Large Pages Information *******************
                                                Per process system memlock (soft) limit = UNLIMITED
                                                Total Shared Global Region in Large Pages = 1986 MB (100%)
                                                Large Pages used by this instance: 993 (1986 MB)
                                                Large Pages unused system wide = 3 (6144 KB)
                                                Large Pages configured system wide = 996 (1992 MB)
                                                Large Page size = 2048 KB
                                                ********************************************************************

                                                8 检查可用的hugepages

                                                如果配置没生效,需要重启服务器

                                                  [root@cjc-db-01 ~]# grep Huge proc/meminfo
                                                  AnonHugePages: 94208 kB
                                                  HugePages_Total: 996
                                                  HugePages_Free: 787
                                                  HugePages_Rsvd: 784
                                                  HugePages_Surp: 0
                                                  Hugepagesize: 2048 kB

                                                  PageTables变小了

                                                    [root@cjc-db-01 ~]# cat proc/meminfo|grep PageTables
                                                    PageTables: 30368 kB

                                                    查看内存使用

                                                      [root@cjc-db-01 ~]# free -h
                                                      total used free shared buff/cache available
                                                      Mem: 3.6G 2.4G 765M 9.4M 477M 343M
                                                      Swap: 2.0G 20K 2.0G

                                                      1.2错误启用HugePages方法:

                                                      如果将HugePages设置低于sga_target,例如1000MB,小于 sga_target(1970MB)。

                                                      vm.nr_hugepages值从996改为1000/2=500

                                                      停库:

                                                        SQL> shutdown immediate

                                                        修改参数

                                                          vi etc/sysctl.conf
                                                          #vm.nr_hugepages=996
                                                          vm.nr_hugepages=500
                                                          wq
                                                          [root@cjc-db-01 ~]# sysctl -p

                                                          启库:

                                                            SQL>startup

                                                            查看alert_cjc.log日志信息:

                                                              Starting ORACLE instance (normal)
                                                              ************************ Large Pages Information *******************
                                                              Per process system memlock (soft) limit = UNLIMITED
                                                              Total Shared Global Region in Large Pages = 994 MB (50%)
                                                              Large Pages used by this instance: 497 (994 MB)
                                                              Large Pages unused system wide = 3 (6144 KB)
                                                              Large Pages configured system wide = 500 (1000 MB)
                                                              Large Page size = 2048 KB
                                                              RECOMMENDATION:
                                                              Total System Global Area size is 1986 MB. For optimal performance,
                                                              prior to the next instance restart:
                                                              1. Increase the number of unused large pages by
                                                              at least 493 (page size 2048 KB, total size 986 MB) system wide to
                                                              get 100% of the System Global Area allocated with large pages
                                                              ********************************************************************

                                                              告警日志有如下建议:

                                                              系统全局区域的总大小为1986 MB。为了获得最佳性能,在下一次实例重新启动之前:

                                                              1.在系统范围内将未使用的大页面数量增加至少493个(页面大小2048 KB,总大小986 MB),以获得100%的系统全局区域分配有大页面。

                                                              查看:

                                                              页表比正确配置的偏大

                                                                [root@cjc-db-01 ~]# cat proc/meminfo|grep PageTables
                                                                PageTables: 34900 kB

                                                                使用了少量的HugePages

                                                                  [root@cjc-db-01 ~]# grep Huge proc/meminfo
                                                                  AnonHugePages: 43008 kB
                                                                  HugePages_Total: 500
                                                                  HugePages_Free: 431
                                                                  HugePages_Rsvd: 428
                                                                  HugePages_Surp: 0
                                                                  Hugepagesize: 2048 kB

                                                                    [root@cjc-db-01 ~]# free -h
                                                                    total used free shared buff/cache available
                                                                    Mem: 3.6G 1.4G 1.3G 237M 859M 1.0G
                                                                    Swap: 2.0G 0B 2.0G

                                                                    二:use_large_pages参数说明:

                                                                    默认参数:TRUE

                                                                    当系统的HugePage被使用尽,只有small pages的情况下,SGA也会继续运行。此时,Oracle实例就运行在内存使用混合模式(Mixed Mode)下。

                                                                      SQL> show parameter use_large_pages
                                                                      NAME TYPE VALUE
                                                                      ------------------------------------ ----------- ------------------------------
                                                                      use_large_pages string TRUE

                                                                      除了TURE,还支持ONLY和AUTO。

                                                                      其中ONLY表示:Oracle实例只会使用HugePage作为内存使用,如果系统在AMM模式或者HugePage用尽的时候,数据库就不能启动。

                                                                      测试ONLY值:

                                                                      先备份参数文件

                                                                        [oracle@cjc-db-01 ~]$ cd $ORACLE_HOME/dbs
                                                                        [oracle@cjc-db-01 dbs]$ cp spfilecjc.ora spfilecjc.ora.bak

                                                                        修改参数:

                                                                          SQL> alter system set use_large_pages=only scope=spfile;

                                                                          重启数据库:

                                                                            SQL> shutdown immediate
                                                                            SQL> startup

                                                                            报错如下:

                                                                              ORA-27137: unable to allocate large pages to create a shared memory segment
                                                                              Linux-x86_64 Error: 12: Cannot allocate memory
                                                                              Additional information: 2063597568
                                                                              Additional information: 1

                                                                              告警信息如下:

                                                                                Starting ORACLE instance (normal)
                                                                                ************************ Large Pages Information *******************
                                                                                Parameter use_large_pages = ONLY
                                                                                Per process system memlock (soft) limit = UNLIMITED
                                                                                Large Pages unused system wide = 500 (1000 MB)
                                                                                Large Pages configured system wide = 500 (1000 MB)
                                                                                Large Page size = 2048 KB


                                                                                ERROR:
                                                                                Failed to allocate shared global region with large pages, unix errno = 12.
                                                                                Aborting Instance startup.
                                                                                ORA-27137: unable to allocate Large Pages to create a shared memory segment
                                                                                ACTION:
                                                                                Total System Global Area size is 1992 MB. Prior to next instance restart:
                                                                                1. Increase the number of unused large pages (page size 2048 KB)
                                                                                to at least 996 (1992 MB) to allocate 100% System Global Area
                                                                                with large pages.
                                                                                ********************************************************************

                                                                                恢复备份参数文件

                                                                                  [oracle@cjc-db-01 dbs]$ mv spfilecjc.ora spfilecjc.ora.bak.1
                                                                                  [oracle@cjc-db-01 dbs]$ mv spfilecjc.ora.bak spfilecjc.ora

                                                                                  重新启动数据库

                                                                                    SQL> shutdown immediate
                                                                                    SQL> startup

                                                                                    三:HugePages说明:

                                                                                    HugePages是Linux内核2.6中集成的一个特性。

                                                                                    启用HugePages可以使操作系统支持大于默认值(通常为4KB)的内存页。

                                                                                    使用HugePages时,操作系统页表(虚拟内存到物理内存的映射)变小,可以减少访问页表条目所需的系统资源量,从而提高系统性能。

                                                                                    HugePage的大小从2MB到256MB不等,这取决于内核版本和硬件体系结构。

                                                                                    对于Oracle数据库,使用HugePages可以减少操作系统页表状态的维护,并提高Translation Lookaside Buffer(TLB)命中率。

                                                                                    四:何时启用HugePages:

                                                                                    适用于:具有大型SGA和或会话较多的数据库。

                                                                                    许多文档将HugePages在Linux上的使用描述为一种可能性,但没有充分强调HugePage在某些数据库配置中成为一种要求。

                                                                                    对于一个SGA较小或连接用户数量较少的数据库(较小的“会话”),配置HugePages不会有任何改进。

                                                                                    但是,对于具有大SGA(2Gb以上)和许多连接用户(会话>500)的数据库,为了减少操作系统级别的内存使用并提高数据库的整体性能,必须配置HugePages。

                                                                                    每个会话的前台进程将具有一个称为PageTable的内存结构,该进程通过该内存结构访问SGA。

                                                                                    简而言之,由于Linux上的默认页面大小很小(这是英特尔的限制),应用程序使用的内存非常大,因此页面表变得太大,无法管理。

                                                                                    HugePages是为克服这一问题而开发的解决方案。它绝对不是内核错误。

                                                                                    对于使用大量SGA区域的Oracle数据库,如果不是必要的要求,则使用HugePages是最佳实践。

                                                                                    SGA越大,每个进程的PageTable就越大。每个进程都有这个PageTable,所以对于许多连接的会话,所有PageTable的总和将变得更大。

                                                                                    内存结构PageTables的总大小可以通过以下内容查看:

                                                                                      grep PageTables proc/meminfo

                                                                                      “free”实用程序不会显式显示这种类型的内存,但会将其包含在“cache”或“buff/cache”下的文件系统缓存中。

                                                                                      具有大型SGA和或许多会话的数据库必须配置HugePages。

                                                                                      对于性能和较小的内存占用空间,建议使用它。

                                                                                      它可以是具有相对低的sga_starget=2-5Gb但具有许多会话=1000-2000的数据库,或者具有巨大的sga_tharget=200Gb且很少会话=500的数据库。

                                                                                      在这些特定的数据库配置中,PageTables可能会消耗机器上的额外内存,该内存可能等于或大于SGA的总大小。

                                                                                      PageTables内存被添加到该机器上数据库消耗的SGA和总PGA内存中。

                                                                                      例如:

                                                                                      (1)数据库配置如下:

                                                                                        sga_target=25 GB
                                                                                        sessions= 500

                                                                                        在高峰时间(连接了近500个会话)PageTables消耗机器物理内存中的20Gb

                                                                                        at peak time (near 500 sessions connected) PageTables consumes 20Gb from the physical memory of the machine

                                                                                          grep PageTables proc/meminfo
                                                                                          PageTables: 26365324 kB

                                                                                          因此,该数据库在高峰时段将使用25Gb(sga)+20Gb(PageTables)+10Gb(总PGA)=55Gb。

                                                                                          So this database at peak times would use 25Gb (sga) + 20Gb (PageTables) + 10Gb (total PGA) = 55Gb .

                                                                                          一台具有45Gb物理RAM的机器,我们通常认为它可以很容易地容纳具有25Gb SGA和10Gb总PGA的数据库,

                                                                                          将开始使用10Gb交换。性能下降,如果更多的用户连接到数据库,我们最终将没有内存。

                                                                                          A machine with 45Gb physical RAM, which we normally think would accommodate easily a database with 25Gb SGA and 10Gb total PGA, will start swapping using 10Gb of swap.

                                                                                          Performance goes down and if more users connect to the database, we would end up without memory.

                                                                                          (2)数据库配置如下:

                                                                                            sga_target = 250G
                                                                                            sessions= 5000

                                                                                            a.在配置HugePages之前,我们看到209Gb的巨大“buff/cache”几乎等于SGA

                                                                                            a. before configuring HugePages we see a huge 'buff/cache' of 209Gb almost equal to the SGA

                                                                                              free -g
                                                                                              total used free shared buff/cache available
                                                                                              Mem: 503 118 175 201 209 181
                                                                                              Swap: 19 1 18

                                                                                              b.配置HugePages后,“buff/cache”下降95%,“空闲”内存显著增加

                                                                                              b. after configuring HugePages, 'buff/cache' drops by 95% and 'free' memory increase considerably

                                                                                                free -g
                                                                                                total used free shared buff/cache available
                                                                                                Mem: 503 210 283 0 10 291
                                                                                                Swap: 19 1 18

                                                                                                (3)数据库配置如下:

                                                                                                  sga_target=2Gb
                                                                                                  sessions=500

                                                                                                  a.如果没有HugePages,在500个连接会话的情况下,PageTables会消耗机器物理内存中的2.5Gb

                                                                                                  a. without HugePages, with 500 connected sessions, PageTables consumes 2.5Gb from the physical memory of the machine

                                                                                                    grep PageTables proc/meminfo
                                                                                                    PageTables: 2617248 kB

                                                                                                    b.配置HugePages后,在500个连接会话的情况下,PageTables仅消耗机器物理内存中的200Mb

                                                                                                    b. after configuring HugePages, with 500 connected sessions, PageTables consumes only 200Mb from the physical memory of the machine

                                                                                                      grep PageTables proc/meminfo
                                                                                                      PageTables: 226364 kB

                                                                                                      启用HugePages后,系统使用更少的PageTables,从而减少了维护和访问它们的开销。

                                                                                                      Huge pages仍然固定在内存中,不会被替换,因此内核交换守护进程在管理它们时没有任何工作要做,内核也不需要为它们执行页面表查找。

                                                                                                      较少的页面数量减少了执行内存操作所涉及的开销,也降低了访问页面表时出现瓶颈的可能性。

                                                                                                      如果没有HugePages,操作系统会将每个4KB(通常为默认页面大小)的内存作为一个页面,当它被分配给SGA时,该页面的生命周期(dirty, free、映射到进程等)会由操作系统内核保持最新,因此会产生性能问题。

                                                                                                      所以:

                                                                                                        IF
                                                                                                        SGA >= 2GB AND sessions >= 500
                                                                                                        THEN
                                                                                                        enabling HugePages becomes a requirement on Linux 64-bit system.

                                                                                                        五:使用HugePages性能提升多大:

                                                                                                        下面的性能测试来自大佬"徐sir的IT之路"公众号的《如何正确的在AIX 7.x系统中开启LargePage for Oracle》文章,原文链接如下:

                                                                                                        如何正确的在AIX 7.x系统中开启LargePage for Oracle

                                                                                                        徐sir,公众号:徐sir的IT之路如何正确的在AIX 7.x系统中开启LargePage for Oracle

                                                                                                          数据库版本:oracle 11.2.0.4
                                                                                                          操作系统:AIX 7.2
                                                                                                          服务器配置:POWER S914,1CPU,128G内存
                                                                                                          内存储配置:SGA65G+PGA20G
                                                                                                          磁盘:华为S5500V5 双活,128G缓存,每个存储上24块SAS 1.8T盘,RAID10阵列,划分了3块600G磁盘,使用了华为的多路径软件。

                                                                                                          (一)未开启16M大页时,500用户swingbench OE v1模型测试结果

                                                                                                          (二)开启16M大页后,500用户swingbenchOE v1模型测试结果

                                                                                                          比较下TPS由3386提升到4444,总体提升约31%左右,测试仅供参考。

                                                                                                          六:HugePages配置的限制:

                                                                                                          Restrictions for HugePages Configurations

                                                                                                          HugePages有以下限制:

                                                                                                          HugePages has the following limitations:

                                                                                                          1.必须取消设置MEMORY_TARGET和MEMORY_MAX_TARGET初始化参数。

                                                                                                          例如,要取消设置数据库实例的参数,请使用命令ALTER SYSTEM RESET。

                                                                                                            You must unset both the MEMORY_TARGET and MEMORY_MAX_TARGET initialization parameters.
                                                                                                            For example, to unset the parameters for the database instance, use the command ALTER SYSTEM RESET.

                                                                                                            2.自动内存管理(AMM)和HugePages不兼容。

                                                                                                              Automatic Memory Management (AMM) and HugePages are not compatible.

                                                                                                              使用AMM时,通过在/dev/shm下创建文件来分配整个SGA内存。

                                                                                                              当Oracle数据库使用AMM分配SGA时,不保留HugePage。

                                                                                                              Oracle 19C使用HugePages,必须禁用AMM(11g也需要禁用AMM)。

                                                                                                                When you use AMM, the entire SGA memory is allocated by creating files under /dev/shm.
                                                                                                                When Oracle Database allocates SGA with AMM, HugePages are not reserved.
                                                                                                                To use HugePages on Oracle Database 19c, You must disable AMM.

                                                                                                                3.如果在32位环境中使用VLM,则不能将HugePages用于Database Buffer cache。

                                                                                                                您可以将HugePage用于SGA的其他部分,如shared_pool、large_pool等。

                                                                                                                VLM(buffer cache)的内存分配是使用共享内存文件系统(ramfs/tmpfs/shmfs)完成的。

                                                                                                                内存文件系统不保留或使用HugePages。

                                                                                                                  If you are using VLM in a 32-bit environment, then you cannot use HugePages for the Database Buffer cache.
                                                                                                                  You can use HugePages for other parts of the SGA, such as shared_pool, large_pool, and so on.
                                                                                                                  Memory allocation for VLM (buffer cache) is done using shared memory file systems (ramfs/tmpfs/shmfs).
                                                                                                                  Memory file systems do not reserve or use HugePages.

                                                                                                                  4.除非系统管理员通过修改可用页面数或修改池大小来更改HugePages配置,否则系统启动后不会分配或释放HugePages。

                                                                                                                  如果在系统启动期间内存中没有保留所需的空间,则HugePages分配失败。

                                                                                                                    HugePages are not subject to allocation or release after system startup, unless a system administrator changes the HugePages configuration, either by modifying the number of pages available, or by modifying the pool size.
                                                                                                                    If the space required is not reserved in memory during system startup, then HugePages allocation fails.

                                                                                                                    5.确保HugePages配置正确,因为如果应用程序未使用过多的HugePage,系统可能会耗尽内存。

                                                                                                                      Ensure that HugePages is configured properly as the system may run out of memory if excess HugePages is not used by the application.

                                                                                                                      6.如果实例启动时HugePages不足,并且初始化参数use_large_pages设置为only,则数据库无法启动,并且会显示一条警报日志消息,提供有关HugePages的必要信息。

                                                                                                                        If there is insufficient HugePages when an instance starts and the initialization parameter use_large_pages is set to only, then the database fails to start and an alert log message provides the necessary information on Hugepages.

                                                                                                                        七:参考链接:

                                                                                                                        官方文档位置:

                                                                                                                        Home / Database / Oracle Database Online Documentation 11g, Release 2 (11.2) / Database Administration / Database Administrator's Reference / G.2 Overview of HugePages

                                                                                                                        11g版本:

                                                                                                                          https://docs.oracle.com/cd/E11882_01/server.112/e10839/appi_vlm.htm#UNXAR385

                                                                                                                          19C版本:

                                                                                                                            https://docs.oracle.com/en/database/oracle/oracle-database/19/unxar/administering-oracle-database-on-linux.html#GUID-95CAEFDE-489B-453A-B5D5-4461DABBEEAD

                                                                                                                            其他:

                                                                                                                              Oracle Linux: Shell Script to Calculate Values Recommended Linux HugePages / HugeTLB Configuration(Doc ID 401749.1)
                                                                                                                              Oracle Linux: HugePages What It Is... and What It Is Not... (Doc ID 361323.1)
                                                                                                                              When And Why To Use HugePages on Linux x86-64? (Doc ID 2314903.1)
                                                                                                                              https://mp.weixin.qq.com/s?__biz=MzU0NTU1MzI5MQ==&mid=2247487446&idx=1&sn=0f1824462605f8c32ca711a68dcfd0ab&chksm=fb6a6132cc1de824a17cdd5e5c4a6596f6e0bb5a59fd955415123b188170fd1efd87b0a06891&mpshare=1&scene=24&srcid=0306G78oREb2qf1UN3etAF2V&sharer_shareinfo=636c40a2be34d2f77a73a414678736fa&sharer_shareinfo_first=da8e314bc06332f4854601ead7b59776#rd

                                                                                                                              八:hugepages_settings.sh脚本内容如下

                                                                                                                                #!/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 the overall 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.%dn",$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.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" ;;
                                                                                                                                '4.14') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
                                                                                                                                '5.4') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
                                                                                                                                *) echo "Kernel version $KERN is not supported by this script (yet). Exiting." ;;
                                                                                                                                esac


                                                                                                                                # End

                                                                                                                                ###chenjuchao 20240307###

                                                                                                                                相关文章

                                                                                                                                Oracle如何使用授予和撤销权限的语法和示例
                                                                                                                                Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
                                                                                                                                下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
                                                                                                                                社区版oceanbase安装
                                                                                                                                Oracle 导出CSV工具-sqluldr2
                                                                                                                                ETL数据集成丨快速将MySQL数据迁移至Doris数据库

                                                                                                                                发布评论