• 记一次Oracle未全部使用大页内存的处理案例
  • 发布于 4小时前
  • 14 热度
    0 评论
  • 王晶
  • 0 粉丝 58 篇博客
  •   
正文开始
1、关于配置大页
大页是啥我就不具体介绍了,网上介绍的文章很多,大多安装数据库的文章都有这么一步告诉大家配置大页,我只想说说错误的使用情况:那就是大页内存配置成功了,但是数据库却有正确使用大页,等数据库启动后就只能用少得可怜的普通内存,导致内存不足影响性能,如果数据库服务器上再跑个ETL进程或者其它应用,那么可能会导致数据库性能严重下降。

在数据库交流群里也遇到过好几次这类的问题,非常的典型,配置完大页记得检查下有没有使用,避免此类问题。我之前也写过一篇关于如何在aix 系统上开启大页内存的文章,测试效果还不错。然而,大多数环境即使你不配置大页也没啥问题,因为大多数系统虽然用了oracle,但并不是说满负荷运行且硬件没有上升空间了。以前刚入行的时候也犯过这个错误,比如最近在给同事检查7年前我安装的数据库服务器,我就发现了我配置了大页却没有使用。。。虽说是个不太繁忙的业务系统,但还是经验不足当时,只是照着别人写的文档来装就完了,啥也不懂。

下面说个最近遇到的场景,大页没有完全使用:操作系统是oracle linux 7.9  数据库是11.2.0.4 rac。当然这个问题仅限于11G,因为之后的版本己经没有这个参数了。多说一句:在11gR2版本的数据库,use_large_pages的默认值是TRUE。通常不用再修改

2、问题场景
给oracle 11g配置了大页,但是查看告警日志启动时有个报错说是有个参数被disable了
Starting ORACLE instance (normal)
************************ Large Pages Information *******************
Per process system memlock (soft) limit = UNLIMITED

Large page usage restricted to processor group "user.slice"

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

WARNING:
  The parameter _linux_prepage_large_pages is explicitly disabled.
  Oracle strongly recommends setting the _linux_prepage_large_pages
  parameter since the instance  is running in a Processor Group. If there is
  insufficient large page memory, instance may encounter SIGBUS error
  and may terminate abnormally.

Large Pages used by this instance: 51201 (100 GB)
Large Pages unused in Processor Group user.slice = 82444 (161 GB)
Large Pages configured in Processor Group user.slice = 82445 (161 GB)
Large Page size = 2048 KB

********************************************************************
于是检查了一下大页的使用情况,发现大页确实没有被完全使用,只是用了一部分,使用的部分:
82445-74789=7656*2MB=15312MB,一共才不到15G

[root@dbnode2 ~]# cat /proc/meminfo |grep Hug
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
FileHugePages:         0 kB
HugePages_Total:   82445
HugePages_Free:    74789
HugePages_Rsvd:    43545
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:        168847360 kB
检查下配置文件,我这里大页配置的有点大161G,实际内存SGA只配置了100G。
[oracle@dbnode2:/u01/app/oracle/diag/rdbms/dbm/dbm2/trace]$ grep -v '^#' /etc/sysctl.conf
kernel.shmmni = 4096
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
vm.swappiness = 10
kernel.shmmax= 229633380966
kernel.shmall = 56062837
vm.nr_hugepages = 82445

[oracle@dbnode2:/u01/app/oracle/diag/rdbms/dbm/dbm2/trace]$  grep -v '^#' /etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
oracle soft nproc 2047
oracle hard nproc 16384
oracle hard memlock 134217728
oracle soft memlock 134217728
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 10240
grid hard stack 32768
grid soft nproc 2047
grid hard nproc 16384
3、问题修复
接下来尝试修改数据库参数并重新调整大页大小。
alter system set "_linux_prepage_large_pages"=TRUE scope=spfile;
修改sysctl.conf,配置大页100G
vm.nr_hugepages = 51210
配置完后为确保内存释放最好是重启下服务器。之后再次启动数据库查看报警没有了
Starting ORACLE instance (normal)
Tue Sep 16 23:51:33 2025
************************ Large Pages Information *******************
Per process system memlock (soft) limit = UNLIMITED
Large page usage restricted to processor group "user.slice"
Total Shared Global Region in Large Pages = 100 GB (100%)
Large Pages in Shared Memory Region are prepaged
Large Pages used by this instance: 51201 (100 GB)
Large Pages unused in Processor Group user.slice = 31244 (61 GB)
Large Pages configured in Processor Group user.slice = 82445 (161 GB)
Large Page size = 2048 KB

********************************************************************
再确认下大页使用情况,这次全部使用了(配置的时候我多写了9个,这里显示剩余正常)
[root@dbnode2 ~]# cat /proc/meminfo |grep Hug
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
FileHugePages:         0 kB
HugePages_Total:   51210
HugePages_Free:        9
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:        104878080 kB
4、附录
大页计算官方脚本,记得chmod+x后使用
!/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 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 Automatic Memory Management (AMM) is not configured"
    exit 1
fi

# Finish with results
    echo"Recommended setting: vm.nr_hugepages = $NUM_PG";


# End
用户评论