• 售前

  • 售后

热门帖子
入门百科

Linux系统下快速设置HugePages的完整步调

[复制链接]
李焕发 显示全部楼层 发表于 2021-10-25 19:57:53 |阅读模式 打印 上一主题 下一主题
媒介
关于Linux体系的HugePages与Oracle数据库优化,可以参考熊爷之前的文章,干系概念介绍的非常清楚:
Linux大内存页Oracle数据库优化

本文旨在Linux体系上快速配置HugePages

测试环境:RHEL6.8 + 512G物理内存;Oracle 11.2.0.4 SGA=400G.
1.设置memlock无穷制

在/etc/security/limits.conf配置文件中,设置oracle用户memlock无穷制:

vi /etc/security/limits.conf
  1. oracle soft memlock unlimited
  2. oracle hard memlock unlimited
复制代码
2.设置公道的vm.nr_hugepages

在/etc/sysctl.conf配置文件中,设置公道的vm.nr_hugepages值。

运行MOS 401749.1提供的hugepages_settings.sh脚本,直接可以得到发起值。

hugepages_settings.sh脚本内容:
  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 SGA 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 11g 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 11g Automatic Memory Management (AMM) is not configured"
  68. exit 1
  69. fi
  70. # Finish with results
  71. case $KERN in
  72. '2.2') echo "Kernel version $KERN is not supported. Exiting." ;;
  73. '2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
  74. echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;
  75. '2.6') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
  76. '3.8') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
  77. '3.10') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
  78. '4.1') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
  79. esac
  80. # End
复制代码
直接运行脚本即可得到对应的发起:
  1. --当启动的实例设置SGA_MAX_SIZE=12G,给出建议:
  2. Recommended setting: vm.nr_hugepages = 6148
  3. --当启动的实例设置SGA_MAX_SIZE=400G,给出建议:
  4. Recommended setting: vm.nr_hugepages = 204805
  5. --当没有启动实例时,会报错提示:
  6. ***********
  7. ** ERROR **
  8. ***********
  9. Sorry! There are not enough total of shared memory segments allocated for
  10. HugePages configuration. HugePages can only be used for shared memory segments
  11. that you can list by command:
  12. # ipcs -m
  13. of a size that can match an Oracle Database SGA. Please make sure that:
  14. * Oracle Database instance is up and running
  15. * Oracle Database 11g Automatic Memory Management (AMM) is not configured
复制代码
我这里将发起值vm.nr_hugepages = 204805追加到/etc/sysctl.conf配置文件中,然后实行sysctl -p见效配置。
3.确认HugePages设置乐成

检察关于HugePages的信息,注意HugePages_Total值是之前设置的204805:

grep Huge /proc/meminfo
  1. # grep Huge /proc/meminfo
  2. AnonHugePages: 0 kB
  3. HugePages_Total: 204805
  4. HugePages_Free: 168475
  5. HugePages_Rsvd: 168471
  6. HugePages_Surp: 0
  7. Hugepagesize: 2048 kB
复制代码
数据库在启动时,对应alert日志中会有“Large Pages Information”内容:
  1. Wed Nov 14 14:38:12 2018
  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 = 400 GB (100%)
  6. Large Pages used by this instance: 204801 (400 GB)
  7. Large Pages unused system wide = 4 (8192 KB)
  8. Large Pages configured system wide = 204805 (400 GB)
  9. Large Page size = 2048 KB
  10. ********************************************************************
复制代码
至此可以确认HugePages设置乐成。
总结
以上就是这篇文章的全部内容了,盼望本文的内容对各人的学习或者工作具有肯定的参考学习价值,如果有疑问各人可以留言交流,谢谢各人对脚本之家的支持。

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作