Oracle 之 配置HugePages内存

简介:

HugePages是通过使用大页内存来取代传统的4kb内存页面,使得管理虚拟地址数变少,加快了从虚拟地址到物理地址的映射以及通过摒弃内存页面的换入换出以提高内存的整体性能。尤其是对于8GB以上的内存以及较大的Oracle SGA size,建议配值并使用HugePage特性。本文基于x86_64 Linux下来描述如何配值 HugePages。

一、 为oracle服务器配置Hugepages

1.1、查看当前系统是否配值HugePages
下面的查询中HugePages相关的几个值都为0,表明当前未配值HugePages,其次可以看到Hugepagesize为2MB。
$ grep Huge /proc/meminfo
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB

1.2、修改用户的memlock限制
通过修改/etc/security/limits.conf 配值文件来实现
该参数的值通常配值位略小于当前的已安装系统内存,如当前你的系统内存为64GB,可以做如下设置
* soft memlock 60397977
* hard memlock 60397977
上述的设置单位为kb,不会降低系统性能。至少也要配值为略大于系统上所有SGA的总和。
使用ulimit -l 来校验该设置

1.3、禁用AMM(Oracle 11g)
如果当前的Oracle 版本为10g,可以跳过此步骤。
如果当前的Oracle 版本为11g,由于AMM(Automatic Memory Management)特性与Hugepages不兼容,需要禁用AMM。
ALTER SYSTEM RESET memory_target SCOPE=SPFILE;
ALTER SYSTEM RESET memory_max_target SCOPE=SPFILE;
ALTER SYSTEM SET sga_target=<n>g SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target=<n>g SCOPE=SPFILE;
SHUTDOWN IMMEDIATE; 
STARTUP;

-----------------------------------------------------------------
禁用memory_max_target和memory_target参数方法
这里注意,官方文档说的是“unset” ,直接alter system set memory_target=0 scope=spfile;是更改不成功的。直接设置为‘0’,就抱如下的错误
ORA-00843: Parameter not taking MEMORY_MAX_TARGET into account 
ORA-00849: SGA_TARGET 35433480192 cannot be set to more than MEMORY_MAX_TARGET 0. 
ORA-01078: failure in processing system parameters
通过创建pfile.ora文件,然后在文件里删除两个参数"MEMORY_TARGET/MEMORY_MAX_TARGET"。然后再创建spfile就可以了。
-----------------------------------------------------------------

1.4、计算vm.nr_hugepages 的值 
使用Oracle 提供的脚本hugepages_settings.sh的脚本来计算vm.nr_hugepages的值
在执行脚本之前确保所有的Oracle 实例已启动以及ASM也启动(存在的情形下)
若HugePages配置可行,他就会推荐一个内存大小,若不可行则报错
$ ./hugepages_settings.sh   (具体脚本在下面)
...
Recommended setting: vm.nr_hugepages = 1496 ( sga_m / 4m + 3 )

1.5、 编辑/etc/sysctl.conf 来设置vm.nr_hugepages参数
$ sysctl -w vm.nr_hugepages = 1496 
$ sysctl -p

1.6、停止所有的Instance并重启server
上述的所有步骤已经实现了动态修改,但对于HugePages的分配需要重新启动server才能生效。

1.7、验证配值
HugePages相关参数的值会随着当前服务器上的实例的停止与启动而动态发生变化
通常情况下,HugePages_Free的值应当小于HugePages_Total的值,在HugePages被使用时HugePages_Rsvd值应当为非零值。
$ grep Huge /proc/meminfo
HugePages_Total: 131
HugePages_Free: 20
HugePages_Rsvd: 20
Hugepagesize: 2048 kB 

如下面的情形,当服务器上仅有的一个实例被关闭后,HugePages_Rsvd的值为零。且HugePages_Free等于HugePages_Total
$ grep Huge /proc/meminfo
HugePages_Total: 131
HugePages_Free: 131
HugePages_Rsvd: 0
Hugepagesize: 2048 kB 

二、使用HugePages的注意事项
下面的三种情形应当重新配置HugePages
a、物理内存的增减或减少
b、在当前服务器上新增或移出Instance
c、Instance的SGA大小增加或减少 
如果未能调整HugePages,可能会引发下面的问题
a、数据库性能地下
b、出现内存不足或者过度使用交换空间
c、数据库实例不能被启动
d、关键性系统服务故障

三、HugePages特性的常见故障处理
Symptom A:
System is running out of memory or swapping 
Possible Cause: 
Not enough HugePages to cover the SGA(s) and therefore the area reserved for HugePages are wasted where SGAs are allocated through regular pages. 
Troubleshooting Action:
Review your HugePages configuration to make sure that all SGA(s) are covered.

Symptom B:
Databases fail to start 
Possible Cause:
memlock limits are not set properly 
Troubleshooting Action:
Make sure the settings in limits.conf apply to database owner account.

Symptom C:
One of the database fail to start while another is up 
Possible Cause:
The SGA of the specific database could not find available HugePages and remaining RAM is not enough. 
Troubleshooting Action:
Make sure that the RAM and HugePages are enough to cover all your database SGAs

Symptom D:
Cluster Ready Services (CRS) fail to start 
Possible Cause:
HugePages configured too large (maybe larger than installed RAM)
Troubleshooting Action: 
Make sure the total SGA is less than the installed RAM and re-calculate HugePages.

Symptom E:
HugePages_Total = HugePages_Free
Possible Cause: 
HugePages are not used at all. No database instances are up or using AMM. 
Troubleshooting Action:
Disable AMM and make sure that the database instances are up.

Symptom F:
Database started successfully and the performance is slow 
Possible Cause:
The SGA of the specific database could not find available HugePages and therefore the SGA is handled by regular pages, which leads to slow performance 
Troubleshooting Action:
Make sure that the HugePages are many enough to cover all your database SGAs
Reference: [ID 361468.1]


四、如何控制数据库SGA是否使用Hugepages?
11.2.0.2之前的版本,database的SGA只能选择全部使用hugepages或者完全不使用hugepages。
11.2.0.2 及以后的版本, oracle增加了一个新的参数“USE_LARGE_PAGES”来管理数据库如何使用 hugepages.
USE_LARGE_PAGES参数有三个值: "true" (default), "only", "false" and "auto"(since 11.2.0.3 patchset).
1. 现在默认值是"true",如果系统设置Hugepages的话,SGA会优先使用hugepages,有多少用多少。 
11.2.0.2 如果没有足够的 hugepages, SGA是不会使用hugepages的. 这会导致ORA-4030错误,因为hugepages已经从物理内存分配,但是SGA没有使用它,却使用其他部分内存,导致内存资源不足 
但是在11.2.0.3版本这个使用策略被改变了,SGA可以一部分使用hugepages,剩余部分使用small pages。这样,SGA会有限使用hugepages,在hugepages用完之后,再使用regular sized pages。
2. 如果设置为"false" , SGA就不会使用hugepages
3. 如果设置为 "only" 如果hugepages大小不够的话,数据库实例是无法启动的 (防止内存溢出的情况发生).
4. 11.2.0.3版本之后,可以设置为 "auto".这个选项会触发oradism进程重新配置linux内核,以增加hugepages的数量。Oradism需要被赋予相应的权限,如下
-rwsr-x--- 1 root <oracle group>
它不会去改变/etc/sysctl.conf文件中的hugepages值,当OS重启后,系统会再恢复到/etc/sysctl.conf中配置的hugepages值。

五、注意事项
a、HugePage使用的是共享内存,在操作系统启动期间被动态分配并被保留,因为他们不会被置换。
b、由于不会被置换的特点,在使用hugepage的内存不能被其他的进程使用。所以要合理设置该值,避免造成内存浪费。
c、对于只使用Oracle的服务器来说,把Hugepage设置成SGA(所有instance SGA之和)大小即可。
d、如果增加HugePage或添加物理内存或者是当前服务器增加了新的instance以及SGA发生变化,应该重新设置所需的HugePage。

--  补充 hugepages_settings.sh  脚本

若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 SGA 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=`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 11g Automatic Memory Management (AMM) is not configured"
exit 1
fi
# Finish with results
case $KERN in
'2.2') echo "Kernel version $KERN is not supported. Exiting." ;;
'2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;
'2.6') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'3.8') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'3.10') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'4.1') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
esac
# End
结果如下
[oracle@n3 ~]$ chmod +x hugepages_settings.sh 
[oracle@n3 ~]$ sh hugepages_settings.sh 
Press Enter to proceed...

Recommended setting: vm.nr_hugepages = 125447

文章可以转载,必须以链接形式标明出处。

本文转自 张冲andy 博客园博客,原文链接: http://www.cnblogs.com/andy6/p/7481721.html   ,如需转载请自行联系原作者
相关文章
|
29天前
|
存储 JSON 监控
Higress Controller**不是将配置信息推送到Istio的内存存储里面的**。
【2月更文挑战第30天】Higress Controller**不是将配置信息推送到Istio的内存存储里面的**。
14 1
|
30天前
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Dept实体类和对应的配置信息
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Dept实体类和对应的配置信息
13 1
|
6月前
|
Oracle 关系型数据库 数据库
百度搜索:蓝易云【docker部署并配置oracle12c的cdb和pdb教程!】
以上是使用Docker部署和配置Oracle 12c CDB和PDB的简要教程。请注意,这只是一个概述,并且可能需要根据你的实际情况进行适当的调整和配置。建议参考Oracle官方文档和相关资源,以获得更详细和全面的指导。
103 2
|
3月前
|
监控 关系型数据库 MySQL
innodb_buffer_pool_instances 如何根据cpu和内存进行配置
`innodb_buffer_pool_instances` 是用于配置 InnoDB 缓冲池实例数的参数。每个实例都管理缓冲池的一部分,这有助于提高并发性能。通常,你可以根据系统的 CPU 和内存来调整这个参数,以获得更好的性能。 以下是一些建议和步骤,帮助你根据 CPU 和内存进行 `innodb_buffer_pool_instances` 的配置: 1. **了解系统资源:** 首先,了解系统的硬件资源,特别是内存和CPU。检查系统上可用的物理内存和 CPU 核心数量。 2. **考虑每个实例的大小:** 在配置 `innodb_buffer_pool_instances` 时,
|
30天前
|
JavaScript Java 数据库连接
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Emp实体类和对应的配置信息
struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Emp实体类和对应的配置信息
23 0
|
1月前
|
弹性计算 固态存储 调度
阿里云服务器部署配置选择全攻略,ECS实例规格、CPU内存配置
阿里云服务器部署配置选择全攻略,ECS实例规格、CPU内存配置,CPU内存、公网带宽和系统盘怎么选择?个人用户选择轻量应用服务器或ECS通用算力型u1云服务器,企业用户选择ECS计算型c7、通用型g7云服务器,阿里云百科分享阿里云服务器配置选择方法
|
1月前
|
弹性计算 固态存储 调度
阿里云配置服务器详细指南_2024新版CPU内存带宽系统盘选择
阿里云配置服务器详细指南_2024新版CPU内存带宽系统盘选择,阿里云服务器配置怎么选择?CPU内存、公网带宽和系统盘怎么选择?个人用户选择轻量应用服务器或ECS通用算力型u1云服务器,企业用户选择ECS计算型c7、通用型g7云服务器,阿里云百科分享阿里云服务器配置选择方法
|
5月前
|
SQL Oracle 关系型数据库
Oracle21C + PLSQL Developer 15 + Oracle客户端21安装配置完整图文版
Oracle21C + PLSQL Developer 15 + Oracle客户端21安装配置完整图文版
128 0
|
6月前
|
Oracle 关系型数据库 数据库
Docker安装Oracle_11g数据库并配置
Docker安装Oracle_11g数据库并配置
223 0
|
5月前
|
消息中间件 Oracle 关系型数据库
Flink CDC确实支持Oracle分区表的CDC,但是在配置时需要特别注意。以下是一些可能的解决方案
Flink CDC确实支持Oracle分区表的CDC,但是在配置时需要特别注意。以下是一些可能的解决方案
44 1