[转帖]内存优化(开启内存大页vm.nr_hugepages)

内存,优化,开启,vm,nr,hugepages · 浏览次数 : 0

小编点评

**内容生成指令:** ```bash # 配置memlock(可选) vi /etc/security/limits.conforacle hard memlock xxxxxoracle soft memlock xxxxx 运行脚本hugepages_settings.sh计算推荐页大小 ./hugepages_settings.sh1 # 根据值设置/etc/sysctl.conf文件末尾添加 vi /etc/sysctl.confvm.nr_hugepages=xxxxxx#退出后sysctl -p #生效 禁用AMM(Oracledb需设置) ``` **内容:** * 配置memlock(可选) * 定义MEMORY_TARGET/MEMORY_MAX_TARGET设置为0 * 定义SGA_TARGET/SGA_MAX_SIZE/PGA_AGGREGATE_TARGET的值 * 根据值设置/etc/sysctl.conf文件末尾添加 * 禁用AMM(Oracledb需设置) * 运行脚本hugepages_settings.sh计算推荐页大小 * 计算推荐页大小 * 根据值设置/etc/sysctl.conf文件末尾添加 * 添加SGA_TARGET/SGA_MAX_SIZE/PGA_AGGREGATE_TARGET的值 * 重启数据库生效(Oracledb需重启)

正文

大页内存(hugepages)

为优化内存管理引入了hugepages 可以自定义设置、将原来标准内存也4k设置为更大。
hugepages 优点:
使得Oracle SGA 不可交换;
减轻 TLB 的压力;
减少页表的开销;
减少页表查询的开销;
提升内存访问的整体性能;

oracle建议设置hugepages脚本

#!/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 11g 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=</span><span class="token function">uname</span> -r <span class="token operator">|</span> <span class="token function">awk</span> -F. <span class="token string">'{ printf("%d.%d\n",$1,$2); }'</span><span class="token variable">

# Find out the HugePage size
HPG_SZ=</span><span class="token function">grep</span> Hugepagesize /proc/meminfo <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{print $2}'</span><span class="token variable">
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 </span>ipcs -m <span class="token operator">|</span> <span class="token function">cut</span> -c44-300 <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{print $1}'</span> <span class="token operator">|</span> <span class="token function">grep</span> <span class="token string">"[0-9][0-9]*"</span><span class="token variable">
do
MIN_PG=</span><span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">$SEG_BYTES</span>/(<span class="token variable">$HPG_SZ</span>*1024)"</span> <span class="token operator">|</span> <span class="token function">bc</span> -q<span class="token variable">
if [ \(MIN_PG</span> -gt <span class="token number">0</span> <span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token keyword">then</span> <span class="token assign-left variable">NUM_PG</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">\)NUM_PG+$MIN_PG+1" | bc -q`
fi
done

RES_BYTES=</span><span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">$NUM_PG</span> * <span class="token variable">$HPG_SZ</span> * 1024"</span> <span class="token operator">|</span> <span class="token function">bc</span> -q<span class="token variable">

# 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 11g Automatic Memory Management (AMM) is not configured"
    exit 1
    fi

# Finish with results
case \(KERN</span> <span class="token keyword">in</span> <span class="token string">'2.4'</span><span class="token punctuation">)</span> <span class="token assign-left variable">HUGETLB_POOL</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">echo</span> <span class="token string">"<span class="token variable">\)NUM_PG*\(HPG_SZ</span>/1024"</span> <span class="token operator">|</span> <span class="token function">bc</span> -q<span class="token variable">`</span></span><span class="token punctuation">;</span> <span class="token builtin class-name">echo</span> <span class="token string">"Recommended setting: vm.hugetlb_pool = <span class="token variable">\)HUGETLB_POOL" ;;
'2.6') echo "Recommended setting: vm.nr_hugepages = \(NUM_PG</span>"</span> <span class="token punctuation">;</span><span class="token punctuation">;</span> <span class="token string">'3.8'</span><span class="token punctuation">)</span> <span class="token builtin class-name">echo</span> <span class="token string">"Recommended setting: vm.nr_hugepages = <span class="token variable">\)NUM_PG" ;;
'3.10') echo "Recommended setting: vm.nr_hugepages = \(NUM_PG</span>"</span> <span class="token punctuation">;</span><span class="token punctuation">;</span> <span class="token string">'4.1'</span><span class="token punctuation">)</span> <span class="token builtin class-name">echo</span> <span class="token string">"Recommended setting: vm.nr_hugepages = <span class="token variable">\)NUM_PG" ;;
'4.14') echo "Recommended setting: vm.nr_hugepages = \(NUM_PG</span>"</span> <span class="token punctuation">;</span><span class="token punctuation">;</span> *<span class="token punctuation">)</span> <span class="token builtin class-name">echo</span> <span class="token string">"Kernel version <span class="token variable">\)KERN is not supported by this script (yet). Exiting." ;;
esac

# End

    配置 memlock(可选)

    限制用户内存使用值(可以比SGA略大)

    vi   /etc/security/limits.conf
    

    oracle hard memlock xxxxx
    oracle soft memlock xxxxx

      运行脚本hugepages_settings.sh计算推荐页大小

      ./hugepages_settings.sh
      
      • 1

      根据值设置/etc/sysctl.conf文件末尾添加

      vi  /etc/sysctl.conf
      

      vm.nr_hugepages=xxxxxx

      #退出后
      sysctl -p #生效

        禁用AMM(Oracledb需设置)

        因为Oracle自动内存管理的AMM特性与hugetlbfs不兼容、所以需要禁用这个特性,但是可以使用SGA自动管理。
        具体做法将MEMORY_TARGET/MEMORY_MAX_TARGET设置为0,并且手工指定SGA_TARGET/SGA_MAX_SIZE/PGA_AGGREGATE_TARGET的值。

        重启数据库生效(Oracledb需重启)

        lsnrctl stop
        shutdow immediate
        startup
        lsnrctl start
        

          与[转帖]内存优化(开启内存大页vm.nr_hugepages)相似的内容:

          [转帖]内存优化(开启内存大页vm.nr_hugepages)

          大页内存(hugepages) 为优化内存管理引入了hugepages 可以自定义设置、将原来标准内存也4k设置为更大。 hugepages 优点: 使得Oracle SGA 不可交换; 减轻 TLB 的压力; 减少页表的开销; 减少页表查询的开销; 提升内存访问的整体性能; oracle建议设置h

          [转帖]tidb-系统内核调优及对比

          一、背景 验证系统调优对性能的影响,用sysbench做了一些简单的测试,具体调整方法可见官方文档 二、特殊说明 1.透明大页查看 # 查看透明大页是否开启,[]在always处表示开启,[]在never处表示关闭 cat /sys/kernel/mm/transparent_hugepage/en

          [转帖]JVM优化之调整大内存分页(LargePage)

          转自:http://cjjwzs.iteye.com/blog/1059381 本文将从内存分页的原理,如何调整分页大小两节内容,向你阐述LargePage对JVM的性能有何提升作用,并在文末点明了大内分页的副作用。OK,让我们开始吧! 内存分页大小对性能的提升原理 首先,我们需要回顾一小部分计算机

          [转帖]面试官:Redis 性能优化都有哪些方法?

          https://cloud.tencent.com/developer/article/2168105?areaSource=104001.13&traceId=zcVNsKTUApF9rNJSkcCbB 前言 Redis作为高性能的内存数据库,在大数据量的情况下也会遇到性能瓶颈,日常开发中只有时刻

          [转帖]面试官:Redis 性能优化都有哪些方法?

          https://cloud.tencent.com/developer/article/2168105?areaSource=105001.13&traceId=iLuwwg5L5-kYlGSYRZNBH 前言 Redis作为高性能的内存数据库,在大数据量的情况下也会遇到性能瓶颈,日常开发中只有时刻

          [转帖]面试官:Redis 性能优化都有哪些方法?

          https://cloud.tencent.com/developer/article/2168105?areaSource=&traceId= 前言 Redis作为高性能的内存数据库,在大数据量的情况下也会遇到性能瓶颈,日常开发中只有时刻谨记优化铁则,才能使得Redis性能发挥到极致。 本文将会介

          【转帖】linux 调优篇 :硬件调优(BIOS配置)* 壹

          一. 设置内存刷新频率为Auto二. 开启NUMA三. 设置Stream Write Mode四. 开启CPU预取配置五. 开启SRIOV六. 开启SMMU 通过在BIOS中设置一些高级选项,可以有效提升虚拟化平台性能。表1列出了TaiShan服务器和性能相关的BIOS推荐配置项。 表1 BIOS性

          [转帖]Redis 4.0 自动内存碎片整理(Active Defrag)源码分析

          阅读本文前建议先阅读此篇博客: Redis源码从哪里读起 Redis 4.0 版本增加了许多不错的新功能,其中自动内存碎片整理功能 activedefrag 肯定是非常诱人的一个,这让 Redis 集群回收内存碎片相比 Redis 3.0 更加优雅,便利。我们升级 Redis 4.0 后直接开启了a

          [转帖]linux 调优篇 :硬件调优(BIOS配置)* 壹

          https://blog.csdn.net/tony_vip?type=blog 一. 设置内存刷新频率为Auto二. 开启NUMA三. 设置Stream Write Mode四. 开启CPU预取配置五. 开启SRIOV六. 开启SMMU 通过在BIOS中设置一些高级选项,可以有效提升虚拟化平台性能

          [转帖]A-Ops性能火焰图——适用于云原生的全栈持续性能监测工具

          https://www.modb.pro/db/610990 对于开发及运维人员来讲,火焰图是一个经典的定位性能问题的方法。利用火焰图可以可视化系统资源(cpu占用、内存占用、调度、IO等)的占用情况,从而帮助技术人员快速定位资源异常使用的代码级根因,或者观察潜在性能劣化趋势,进而优化系统和应用的性