在Linux 中为oracle配置hugepage的方法

在Linux 中为oracle配置hugepage的方法  


在Linux中配置hugepage可以提高oracle的性能,减少oracle sga的页交换,类似于aix中的lagepage。
下面演示配置hugepage的方法。
系统环境:
OS:CentOS5 x86
Oracle:10.2.0.1
配置过程  18010133657 


检查hugepagesize
ora_test@root[/root]> grep Hugepagesize /proc/meminfo
Hugepagesize: 4096 kB
配置分配hugepage的数量
nr_hugepages的计算公式:nr_hugepages>=sga(mb)/Hugepagesize(mb)
ora_test@root[/root]> echo 50 > /proc/sys/vm/nr_hugepages
ora_test@root[/root]> sysctl -w vm.nr_hugepages=50
vm.nr_hugepages = 50
ora_test@root[/root]> echo "vm.nr_hugepages=50" >> /etc/sysctl.conf
检查hugepage的分配情况
ora_test@root[/root]> grep HugePages_Total /proc/meminfo
HugePages_Total: 6
这里显示的值为6,小于我配置的数量50,所以需要重启
ora_test@root[/root]> reboot


Broadcast message from root (pts/1) (Mon Jan 25 09:38:04 2010):


The system is going down for reboot NOW!
重启之后,检查hugepage的分配情况
ora_test@root[/root]> grep HugePages_Total /proc/meminfo
HugePages_Total: 50
现在确认hugepage已经分配了50个单位(50×4096kb=200mb)
http://cnhtm.itpub.net/post/39970/496273
配置oracle用户的memlock
需要修改/etc/security/limits.conf文件,加入标记为红色的两行
计算公式为:>=HugePages_Total×1024,我这里设置了2倍的值,即:2×50×1024=102400
ora_test@root[/root]> cat /etc/security/limits.conf|grep lock
# - memlock - max locked-in-memory address space (KB)
# - locks - max number of file locks the user can hold
oracle soft memlock 102400
oracle hard memlock 102400
检查memlock情况
切换到oracle用户身份,使用ulimit -l命令检查memlock情况
ora_test@root[/root]> su - oracle
ora_test@oracle[/home/oracle]> ulimit -l
102400
启动数据库
ora_test@oracle[/home/oracle]> sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jan 25 09:50:33 2010


Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to an idle instance.


idle> startup
ORACLE instance started.


Total System Global Area 167772160 bytes
Fixed Size 1218292 bytes
Variable Size 67111180 bytes
Database Buffers 92274688 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.
idle> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
检查是否已经使用了hugepage
ora_test@oracle[/home/oracle]> grep HugePages_Free /proc/meminfo
HugePages_Free: 30
这里显示剩余的hugepage为30,小于HugePages_Total(50),证明oracle已经使用了hugepage
--end--






为何oracle一起来,系统就会有swap?


db是11g,total memory 是16g ,swap 是8g,分给sga_target=8g,pga_aggregate_target=3g.按理说,这个内存分配也不会导致oracle吞噬过多内存导 致系统发生swap,可现在只要db起来,用vmsta 命令观察就会出现swap, 类似如下。
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
0  0 168524  87336    340  26356  128 3014   178  3054 1305  417  0  1 94  5  0
0  3 168524  81336    480  29052 1798    0  3166     8 1243  687  0  0 94  6  0
0  0 171024  85292    496  28984  880 1500  1176  1500 1225  612  0  0 89 11  0
0  0 171024  85292    496  28960   24    0    24     0 1055  348  0  0 99  0  0
0  3 172284  81960    512  34860  372 1158   430  1230 1307 1496  0  2 94  4  0
0  1 167072  84424    320  38828 1564  210  1716   230 1545 2796  0  3 85 12  0
0  1 167072  84008    340  39152  286    0   362    18 1115  504  0  0 96  4  0
0  0 167072  83764    352  39392   34    0    94     6 1069  344  0  0 99  0  0
0  0 167072  83764    352  39580   32    0    32     0 1072  347  0  0 100  0  0
0  0 167072  82896    352  39568  410    0   410     0 1075  367  0  0 99  1  0




我看了alert log,没有其他报错。现在系统非常慢,大伙帮我分析分析。


QUOTE:
原帖由 oracle_kai 于 2010-12-7 18:28 发表 


系统使用的就是hugepage,但问题也就出现在hugepage 参数的设置上面。


原先vm.nr_hugepages = 41984  
cat /proc/memory|grep HugePages_Total


HugePages_Total=7925


7925*2m 几乎就是整个os内存了。


后来修改该参数,参考sga=8g,所以新设vm.nr_hugepages =4096


重启机器,oracle起来后memory swap 消失,系统反应也正常。


#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
#
# 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. Before proceeding with the execution please 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}'`


# Initialize the counter
NUM_PG=0


# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk '{print $5}' | 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.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" ;;
    *) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac


# End

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值