2018-11-15 01:04 by AlfredZhao, 阅读, 评论, 收藏, 编辑

关于Linux系统的HugePages与Oracle数据库优化,可以参考熊爷之前的文章,相关概念介绍的非常清晰:

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

测试环境:RHEL6.8 + 512G物理内存;Oracle 11.2.0.4 SGA=400G.

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

  1. oracle soft memlock unlimited
  2. oracle hard memlock unlimited

在/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生效配置。

查看关于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设置成功。

版权声明:本文为jyzhao原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/jyzhao/p/9961336.html