马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在 Oracle 数据库管理中,HugePages(大页) 是优化大内存场景下性能的关键配置。通过淘汰页表条目和内存碎片,HugePages 能显著提升 SGA(系统全局区)的访问服从。本文结合 Oracle 官方文档,具体讲解 HugePages 的配置步调、验证方法及常见问题解决方案。
一、为什么必要配置 HugePages?
- 性能优化
- 默认内存页巨细为 4KB,当 SGA 较大时(如超过 8GB),页表条目数量激增,导致 CPU 频繁查询页表,增加开销。
- HugePages(通常 2MB)淘汰页表条目,降低 TLB(Translation Lookaside Buffer)未命中率。
- 避免内存交换(Swap)
- HugePages 锁定在物理内存中,不会被交换到磁盘,避免因内存交换导致的性能下降。
- 淘汰内核开销
- 大页淘汰 kswapd 历程的 CPU 斲丧,避免内存碎片化。
二、配置 HugePages 的步调
1. 禁用 AMM(自动内存管理)
HugePages 与 AMM(MEMORY_TARGET)不兼容,需先禁用:
- show parameter memory
- -- 修改参数文件
- ALTER SYSTEM SET MEMORY_TARGET=0 SCOPE=SPFILE;
- ALTER SYSTEM SET MEMORY_MAX_TARGET=0 SCOPE=SPFILE;
- -- 重启数据库
- SHUTDOWN IMMEDIATE;
- STARTUP;
复制代码 2. 配置 memlock 限定
编辑 /etc/security/limits.conf,设置 Oracle 用户的内存锁定限定:
- # 添加以下内容
- * soft memlock unlimited
- * hard memlock unlimited
复制代码 验证设置见效:
- su - oracle
- ulimit -l # 应输出 unlimited
复制代码 3. 盘算 HugePages 数量
利用 Oracle 提供的脚本 hugepages_settings.sh((Doc ID 401749.1):
- #!/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
复制代码- chmod 775 hugepages_settings.sh
- ./hugepages_settings.sh
- # 输出示例:Recommended setting: vm.nr_hugepages = 1496
复制代码 或手动盘算:
- vm.nr_hugepages >= SGA_Target/Hugepagesize(2M) + 冗余(建议 10%)
复制代码 4. 修改内核参数
编辑 /etc/sysctl.conf,添加:
- vm.nr_hugepages = 1496
- vm.hugetlb_shm_group = dba # Oracle 用户组
复制代码 应用配置:
5. 禁用透明大页(Transparent HugePages)
透明大页可能导致性能抖动,需禁用:
- # 修改 GRUB 配置
- sed -i 's/GRUB_CMDLINE_LINUX="/GRUB_CMDLINE_LINUX="transparent_hugepage=never /g' /etc/default/grub
- # 判断操作系统是否使用UEFI方式启动
- ls -ld /sys/firmware/efi
-
- # 如果上面查询目录存在使用如下方式重建grub配置文件(针对EFI方式)
- grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
-
- # 否则使用如下方式重建grub配置文件(针对BIOS方式)
- grub2-mkconfig -o /boot/grub2/grub.cfg
- # 重启生效
- reboot
- # 验证禁用状态
- cat /sys/kernel/mm/transparent_hugepage/enabled # 输出应为 [never]
复制代码 6. 设置 USE_LARGE_PAGES 参数
Oracle 11.2.0.2+ 引入此参数,控制 HugePages 利用策略:
- TRUE:尝试利用 HugePages,若不敷则回退到平常页(默认)。
- ONLY:强制仅利用 HugePages,不敷则数据库无法启动。
- FALSE:禁用 HugePages。
- SYS@db11g> show parameter use_large_pages
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- use_large_pages string TRUE
复制代码 7. 重启服务器并验证
三、验证 HugePages 配置
1. 操作系统验证
- grep HugePages /proc/meminfo
- # 期望输出:
- HugePages_Total: 1496 # 配置的总大页数
- HugePages_Free: 100 # 剩余大页(数据库启动后应大部分被占用)
- HugePages_Rsvd: 100 # 预留大页(若 PRE_PAGE_SGA=false)
复制代码 2. 日志验证
检查 alert.log,确认以下内容:
- Mon Mar 17 14:29:20 2025
- Starting ORACLE instance (normal)
- ************************ Large Pages Information *******************
- Per process system memlock (soft) limit = UNLIMITED
-
- `Total Shared Global Region in Large Pages = 898 MB (100%) `
-
- Large Pages used by this instance: 449 (898 MB)
- Large Pages unused system wide = 1611 (3222 MB)
- Large Pages configured system wide = 2060 (4120 MB)
- Large Page size = 2048 KB
- ********************************************************************
复制代码 四、常见问题及解决
问题缘故原由解决方案ORA-27137: 无法分配大页HugePages 不敷或 memlock 限定过小增加 vm.nr_hugepages 并检查 memlock数据库性能未提升HugePages 未见效,SGA 利用平常页检查 USE_LARGE_PAGES 是否设置为 ONLYHugePages_Total = HugePages_Free数据库未利用 HugePages确认 AMM 已禁用,数据库实例已启动透明大页未禁用未更新 GRUB 或未重启执行 grubby 命令并重启服务器 五、总结
- 核心配置:禁用 AMM → 设置 memlock → 盘算 HugePages → 修改 sysctl.conf → 禁用透明大页 → 设置 USE_LARGE_PAGES=TRUE。
- 验证关键:通过 /proc/meminfo、v$sgainfo 和 alert.log 确认配置见效。
- 性能收益:淘汰页表开销、避免内存交换,显著提升大内存数据库性能。
通过以上步调,可确保 Oracle 数据库高效利用 HugePages,实用于 OLTP、数据仓库等高并发场景。配置时需注意版本差异(如 11g 与 12c+ 的默认举动),并定期复查内存配置变革。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
|