Oracle 数据库 HugePages 配置详解:提升性能的关键步调

打印 上一主题 下一主题

主题 1680|帖子 1680|积分 5040

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

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)不兼容,需先禁用:
  1. show parameter memory
  2. -- 修改参数文件
  3. ALTER SYSTEM SET MEMORY_TARGET=0 SCOPE=SPFILE;
  4. ALTER SYSTEM SET MEMORY_MAX_TARGET=0 SCOPE=SPFILE;
  5. -- 重启数据库
  6. SHUTDOWN IMMEDIATE;
  7. STARTUP;
复制代码
2. 配置 memlock 限定

编辑 /etc/security/limits.conf,设置 Oracle 用户的内存锁定限定:
  1. # 添加以下内容
  2. * soft memlock unlimited   
  3. * hard memlock unlimited  
复制代码
验证设置见效
  1. su - oracle
  2. ulimit -l  # 应输出 unlimited
复制代码
3. 盘算 HugePages 数量

利用 Oracle 提供的脚本 hugepages_settings.sh((Doc ID 401749.1):
  1. #!/bin/bash
  2. #
  3. # hugepages_settings.sh
  4. #
  5. # Linux bash script to compute values for the
  6. # recommended HugePages/HugeTLB configuration
  7. # on Oracle Linux
  8. #
  9. # Note: This script does calculation for all shared memory
  10. # segments available when the script is run, no matter it
  11. # is an Oracle RDBMS shared memory segment or not.
  12. #
  13. # This script is provided by Doc ID 401749.1 from My Oracle Support
  14. # http://support.oracle.com
  15. # Welcome text
  16. echo "
  17. This script is provided by Doc ID 401749.1 from My Oracle Support
  18. (http://support.oracle.com) where it is intended to compute values for
  19. the recommended HugePages/HugeTLB configuration for the current shared
  20. memory segments on Oracle Linux. Before proceeding with the execution please note following:
  21. * For ASM instance, it needs to configure ASMM instead of AMM.
  22. * The 'pga_aggregate_target' is outside the SGA and
  23.    you should accommodate this while calculating the overall size.
  24. * In case you changes the DB SGA size,
  25.    as the new SGA will not fit in the previous HugePages configuration,
  26.    it had better disable the whole HugePages,
  27.    start the DB with new SGA size and run the script again.
  28. And make sure that:
  29. * Oracle Database instance(s) are up and running
  30. * Oracle Database Automatic Memory Management (AMM) is not setup
  31.    (See Doc ID 749851.1)
  32. * The shared memory segments can be listed by command:
  33.      # ipcs -m
  34. Press Enter to proceed..."
  35. read
  36. # Check for the kernel version
  37. KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`
  38. # Find out the HugePage size
  39. HPG_SZ=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`
  40. if [ -z "$HPG_SZ" ];then
  41.     echo "The hugepages may not be supported in the system where the script is being executed."
  42.     exit 1
  43. fi
  44. # Initialize the counter
  45. NUM_PG=0
  46. # Cumulative number of pages required to handle the running shared memory segments
  47. for SEG_BYTES in `ipcs -m | cut -c44-300 | awk '{print $1}' | grep "[0-9][0-9]*"`
  48. do
  49.     MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
  50.     if [ $MIN_PG -gt 0 ]; then
  51.         NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
  52.     fi
  53. done
  54. RES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" | bc -q`
  55. # An SGA less than 100MB does not make sense
  56. # Bail out if that is the case
  57. if [ $RES_BYTES -lt 100000000 ]; then
  58.     echo "***********"
  59.     echo "** ERROR **"
  60.     echo "***********"
  61.     echo "Sorry! There are not enough total of shared memory segments allocated for
  62. HugePages configuration. HugePages can only be used for shared memory segments
  63. that you can list by command:
  64.     # ipcs -m
  65. of a size that can match an Oracle Database SGA. Please make sure that:
  66. * Oracle Database instance is up and running
  67. * Oracle Database Automatic Memory Management (AMM) is not configured"
  68.     exit 1
  69. fi
  70. # Finish with results
  71.     echo "Recommended setting: vm.nr_hugepages = $NUM_PG";
  72. # End
复制代码
  1. chmod 775 hugepages_settings.sh
  2. ./hugepages_settings.sh
  3. # 输出示例:Recommended setting: vm.nr_hugepages = 1496
复制代码
或手动盘算:
  1. vm.nr_hugepages >= SGA_Target/Hugepagesize(2M) + 冗余(建议 10%)
复制代码
4. 修改内核参数

编辑 /etc/sysctl.conf,添加:
  1. vm.nr_hugepages = 1496
  2. vm.hugetlb_shm_group = dba  # Oracle 用户组
复制代码
应用配置:
  1. sysctl -p
复制代码
5. 禁用透明大页(Transparent HugePages)

透明大页可能导致性能抖动,需禁用:
  1. # 修改 GRUB 配置
  2. sed -i 's/GRUB_CMDLINE_LINUX="/GRUB_CMDLINE_LINUX="transparent_hugepage=never /g' /etc/default/grub
  3. # 判断操作系统是否使用UEFI方式启动
  4. ls -ld /sys/firmware/efi
  5. # 如果上面查询目录存在使用如下方式重建grub配置文件(针对EFI方式)
  6. grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
  7. # 否则使用如下方式重建grub配置文件(针对BIOS方式)
  8. grub2-mkconfig -o /boot/grub2/grub.cfg
  9. # 重启生效
  10. reboot
  11. # 验证禁用状态
  12. cat /sys/kernel/mm/transparent_hugepage/enabled  # 输出应为 [never]
复制代码
6. 设置 USE_LARGE_PAGES 参数

Oracle 11.2.0.2+ 引入此参数,控制 HugePages 利用策略:


  • TRUE:尝试利用 HugePages,若不敷则回退到平常页(默认)。
  • ONLY:强制仅利用 HugePages,不敷则数据库无法启动。
  • FALSE:禁用 HugePages。
  1. SYS@db11g> show parameter use_large_pages
  2. NAME                                 TYPE        VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. use_large_pages                      string      TRUE
复制代码
7. 重启服务器并验证

  1. reboot
复制代码

三、验证 HugePages 配置

1. 操作系统验证

  1. grep HugePages /proc/meminfo
  2. # 期望输出:
  3. HugePages_Total: 1496     # 配置的总大页数
  4. HugePages_Free: 100       # 剩余大页(数据库启动后应大部分被占用)
  5. HugePages_Rsvd: 100       # 预留大页(若 PRE_PAGE_SGA=false)
复制代码
2. 日志验证

检查 alert.log,确认以下内容:
  1. Mon Mar 17 14:29:20 2025
  2. Starting ORACLE instance (normal)
  3. ************************ Large Pages Information *******************
  4. Per process system memlock (soft) limit = UNLIMITED
  5. `Total Shared Global Region in Large Pages = 898 MB (100%) `
  6. Large Pages used by this instance: 449 (898 MB)
  7. Large Pages unused system wide = 1611 (3222 MB)
  8. Large Pages configured system wide = 2060 (4120 MB)
  9. Large Page size = 2048 KB
  10. ********************************************************************
复制代码

四、常见问题及解决

问题缘故原由解决方案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企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

涛声依旧在

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表