HugePages是通过使用大页内存来取代传统的4kb内存页面,使得管理虚拟地址数变少,加快了从虚拟地址到物理地址的映射以及通过摒弃内存页面的换入换出以提高内存的整体性能。尤其是对于8GB以上的内存以及较大的Oracle SGA size,建议配值并使用HugePage特性。本文基于x86_64 Linux下来描述如何配值 HugePages。
有关HugePages的特性请参考:Linux HugePage 特性
有关HugePages的特性请参考:Linux HugePage 特性
1、为什么需要配值HugePages ?a、Larger Page Size and Less # of Pages: Default page size is 4K whereas the HugeTLB size is 2048K. That means the system would need to handle 512 times less pages.
b、No Page Table Lookups: Since the HugePages are not subject to replacement (despite regular pages), page table lookups are not required.
c、Better Overall Memory Performance: On virtual memory systems (any modern OS) each memory operation is actually two abstract memory operations. With HugePages, since there are less number of pages to work on, the possible bottleneck on page table access is clearly avoided.
d、No Swapping:
We must avoid swapping to happen on Linux OS at all Document 1295478.1. HugePages are not swappable (whereas regular pages are). Therefore there is no page replacement mechanism overhead. HugePages are universally regarded as pinned.
e、No 'kswapd' Operations: kswapd will get very busy if there is a very large area to be paged (i.e. 13 million page table entries for 50GB memory) and will use an incredible amount of CPU resource. When HugePages are used, kswapd is not involved in managing them. See also Document 361670.1
2、配值HugePages 下面列出了配值HugePages的所有步骤
a、查看当前系统是否配值HugePages 下面的查询中HugePages相关的几个值都为0,表明当前未配值HugePages,其次可以看到Hugepagesize为2MB。
$ grep Huge /proc/meminfo
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB
b、修改用户的memlock限制 通过修改/etc/security/limits.conf 配值文件来实现
该参数的值通常配值位略小于当前的已安装系统内存,如当前你的系统内存为64GB,可以做如下设置
* soft memlock 60397977
* hard memlock 60397977
$ grep Huge /proc/meminfo
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
Hugepagesize: 2048 kB
b、修改用户的memlock限制 通过修改/etc/security/limits.conf 配值文件来实现
该参数的值通常配值位略小于当前的已安装系统内存,如当前你的系统内存为64GB,可以做如下设置
* soft memlock 60397977
* hard memlock 60397977
上述的设置单位为kb,不会降低系统性能。至少也要配值为略大于系统上所有SGA的总和。
使用ulimit -l 来校验该设置
使用ulimit -l 来校验该设置
c、禁用AMM(Oracle 11g) 如果当前的Oracle 版本为10g,可以跳过此步骤。
如果当前的Oracle 版本为11g,由于AMM(Automatic Memory Management)特性与Hugepages不兼容,需要禁用AMM。
ALTER SYSTEM RESET memory_target SCOPE=SPFILE;
如果当前的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;
ALTER SYSTEM SET sga_target=<n>g SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target=<n>g SCOPE=SPFILE;
SHUTDOWN IMMEDIATE;
STARTUP;
d、计算vm.nr_hugepages 的值
使用Oracle 提供的脚本hugepages_settings.sh的脚本来计算vm.nr_hugepages的值
在执行脚本之前确保所有的Oracle 实例已启动以及ASM也启动(存在的情形下)
$ ./hugepages_settings.sh
...
Recommended setting: vm.nr_hugepages = 1496
d、计算vm.nr_hugepages 的值
使用Oracle 提供的脚本hugepages_settings.sh的脚本来计算vm.nr_hugepages的值
在执行脚本之前确保所有的Oracle 实例已启动以及ASM也启动(存在的情形下)
$ ./hugepages_settings.sh
...
Recommended setting: vm.nr_hugepages = 1496
e、 编辑/etc/sysctl.conf 来设置vm.nr_hugepages参数 $ sysctl -w vm.nr_hugepages = 1496
$ sysctl -p
-- Author : Robinson
-- Blog : http://blog.csdn.net/robinson_0612
f、停止所有的Instance并重启server 上述的所有步骤已经实现了动态修改,但对于HugePages的分配需要重新启动server才能生效。
$ sysctl -p
-- Author : Robinson
-- Blog : http://blog.csdn.net/robinson_0612
f、停止所有的Instance并重启server 上述的所有步骤已经实现了动态修改,但对于HugePages的分配需要重新启动server才能生效。
h、验证配值 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_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
3、使用HugePages的注意事项 下面的三种情形应当重新配置HugePages
a、物理内存的增减或减少
b、在当前服务器上新增或移出Instance
c、Instance的SGA大小增加或减少
如果未能调整HugePages,可能会引发下面的问题
a、数据库性能地下
b、出现内存不足或者过度使用交换空间
c、数据库实例不能被启动
d、关键性系统服务故障
4、HugePages特性的常见故障处理
a、物理内存的增减或减少
b、在当前服务器上新增或移出Instance
c、Instance的SGA大小增加或减少
如果未能调整HugePages,可能会引发下面的问题
a、数据库性能地下
b、出现内存不足或者过度使用交换空间
c、数据库实例不能被启动
d、关键性系统服务故障
4、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.
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.
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
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.
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.
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
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]
5、计算vm.nr_hugepages 值的脚本
No comments:
Post a Comment