您的位置:首页 > 其它

配置lock_sga/pre_page_sga/hugepages

2013-08-18 20:56 676 查看
配置lock_sga/pre_page_sga/hugepages

1、  查看系统sga配置

 

SQL>show parameter sga;

 

NAME                                 TYPE        VALUE

----------------------------------------------- ------------------------------

lock_sga                             boolean     FALSE

pre_page_sga                         boolean     FALSE

sga_max_size                         big integer 272M

sga_target                           big integer 272M

SQL>

 

2、修改lock_sga和pre_page_sga参数

alter system set lock_sga=truescope=spfile;

alter system set pre_page_sga=truescope=spfile;

 

3、关闭数据库时再重启数据库出现以下错误

startup;

ORA-27102: out of memory

Linux-x86_64 Error: 12: Cannot allocatememory

原因很简单,Linux操作系统对每一个任务在物理内存中能够锁住的最大值做了限制!需要手工进行调整。

4、“ORA-27102”及“Cannotallocate memory”问题处理

1)使用“ulimit -a”命令获得“maxlocked memory”的默认大小

[oracle@localhost ~]$ ulimit -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 16384

max locked memory      (kbytes, -l) 32

max memory size         (kbytes, -m) unlimited

open files                      (-n) 65536

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 10240

cpu time               (seconds, -t) unlimited

max user processes              (-u) 16384

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

可见,一个任务可以锁住的物理内存最大值是32kbytes,这么小的值根本无法满足我们SGA的大小需求。

2)在root用户下尝试修改,成功。 临时的修改

[root@localhost ~]# ulimit -l unlimited

[root@localhost ~]# ulimit -l -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 16384

max locked memory       (kbytes, -l) unlimited

max memory size         (kbytes, -m) unlimited

open files                      (-n) 65536

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 10240

cpu time               (seconds, -t) unlimited

max user processes              (-u) 16384

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

然后再重新启动数据库就成功了。

永久配置 --(配置规则可以查看limits.conf注释内容)

vim /etc/security/limits.conf

*                   soft    memlock unlimited

*                   hard    memlock unlimited

 

Su – oracle

Ulimited –a

 

oracle实例启动时,只会在物理内存中载入sga的各个内存的最小的大小(以粒度为单位),而剩余的sga只会在虚拟内存中分配。只有当进程touch到相应的 page时,才会置换到物理内存中。但是,我们也希望oracle在启动后,所有的sga全部分配到物理内存上面,这时我们可以把这个参数设置成 true(默认值是false)。

当参数设置为TRUE时,不仅在实例启动时,需要touch所有的SGA页,并且由于每个oracle进程都会访问SGA区,所以每当一个新进程启动时(在Dedicated Server方式中,每个会话都会启动一个Oracle进程),都会touch一遍该进程需要访问的所有页。因此,每个进程的启动时间页增长了。所以,这个参数的设置需要根据系统的应用情况来设定。在这种情况下,进程启动时间的长短就由系统内存的页的大小来决定了。例如,SGA大小为100M,当页的大小为4K时,进程启动时需要访问100000/4=25000个页,而如果页大小为4M
时,进程只需要访问100/4=25个页。页的大小是由操作系统指定的,并且是无法修改的。但是,要记住一点:PRE_PAGA_SGA只是在启动时将物理内存分配给SGA,但并不能保证系统在以后的运行过程不会将 SGA 中的某些页置换到虚拟内存中,也就是说,尽管设置了这个参数,还是可能出现 Page In/Out。如果需要保障SGA不被换出,就需要由另外一个参数LOCK_SGA 来控制了。

lock_sga这个参数的默认值是false,为了保证sga被锁定在物理内存中,而不必页入/页出,可以把这个参数设置为true。这时就可以将全部的sga锁定在物理内存中了。但是有的系统不支持内存锁定,这时这个参数就无效了。

4、小结

通过修改lock_sga和pre_page_sga参数值为“TRUE”可以有效的将整个SGA锁定在物理内存中,这样可以有效的提高系统的性能,推荐酌情进行调整。

注意:不同的操作系统对这lock_sga参数的支持情况是不同的,如果操作系

 

5、配置hugepages

第一步:设置memlock

在/etc/security/limits.conf文件中添加memlock的限制,注意该值略微小于实际物理内存的大小。 比如物理内存是64GB,可以设置为如下:

* soft memlock unlimited

* hard memlock unlimited

如果这里的值超过了SGA的需求,也没有不利的影响。

如果使用了Oracle Linux的oracle¬-validated包,或者Exadata DB compute会自动配置这个参数。

第二步:验证memlock

使用如下命令查看参数值:

$ ulimit -l

Unlimited

第三步:11g中禁用AMM

如果Oracle 是11g以后的版本,那么默认创建的实例会使用Automatic Memory Management (AMM)的特性,该特性与HugePage不兼容。

在设置HugePage之前需要先禁用AMM。设置初始化参数MEMORY_TARGET 和MEMORY_MAX_TARGET 为0即可。

 

使用AMM的情况下,所有的SGA 内存都是在/dev/shm 下分配的,因此在分配SGA时不会使用HugePage。这也是AMM 与HugePage不兼容的原因。

另外:默认情况下ASM instance 也是使用AMM的,但因为ASM 实例不需要大SGA,所以对ASM 实例使用HugePages意义不大。

如果我们要使用HugePage,那么就必须先确保没有设置MEMORY_TARGET/ MEMORY_MAX_TARGET参数。

 

第四步:计算vm.nr_hugepages的建议值

确保所有的数据库实例都已经启动,包括ASM 实例。使用hugepages_settings.sh 脚本获取thevm.nr_hugepages 内核参数的建议值。

$ ./hugepages_settings.sh

...

Recommended setting: vm.nr_hugepages = 1496

$

也可以根据自己的经验来计算该值。

脚本如下:

#!/bin/bash

#

#hugepages_settings.sh

#

# Linux bash scriptto compute values forthe

# recommendedHugePages/HugeTLBconfiguration

#

# Note: This scriptdoes calculation for allshared memory

# segmentsavailable when the script is run,no matter it

# is an OracleRDBMS shared memory segmentor not.

#

# This script isprovided by Doc ID 401749.1from My Oracle Support

#http://support.oracle.com

 

# Welcome text

echo "

This script isprovided by Doc ID 401749.1from My Oracle Support

(http://support.oracle.com)where it isintended to compute values for

the recommendedHugePages/HugeTLBconfiguration for the current shared

memory
4000
segments.Before proceeding with theexecution please note following:

* For ASMinstance, it needs to configureASMM instead of AMM.

* The'pga_aggregate_target' is outside theSGA and

youshould accommodate this whilecalculating SGA size.

* In case youchanges the DB SGA size,

as thenew SGA will not fit in the previousHugePages configuration,

it hadbetter disable the whole HugePages,

startthe DB with new SGA size and run thescript again.

And make sure that:

* OracleDatabase instance(s) are up andrunning

* OracleDatabase 11g Automatic MemoryManagement (AMM) is not setup

(SeeDoc ID 749851.1)

* The sharedmemory segments can be listedby command:

# ipcs -m

 

 

Press Enter toproceed..."

 

read

 

# Check for thekernel version

KERN=`uname -r |awk -F. '{printf("%d.%d\n",$1,$2); }'`

 

# Find out theHugePage size

HPG_SZ=`grep Hugepagesize /proc/meminfo |awk '{print $2}'`

if [ -z"$HPG_SZ" ];then

echo "The hugepages may not besupported in the system where the script isbeing executed."

exit 1

fi

 

# Initialize thecounter

NUM_PG=0

 

# Cumulative numberof pages required tohandle 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 than100MB does not make sense

# Bail out if thatis the case

if [ $RES_BYTES -lt100000000 ]; then

echo "***********"

echo "** ERROR **"

echo "***********"

echo "Sorry! There are not enoughtotal of shared memory segmentsallocated for

HugePagesconfiguration. HugePages can onlybe used for shared memory segments

that you can listby command:

 

# ipcs -m

 

of a size that canmatch an Oracle DatabaseSGA. Please make sure that:

* OracleDatabase instance is up and running

* OracleDatabase 11g Automatic MemoryManagement (AMM) is not configured"

exit 1

fi

 

# Finish withresults

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

 

 

第五步:在/etc/sysctl.conf文件中设置vm.nr_hugepages参数

[root@localhost u01]# echo vm.nr_hugepages= 1496 >>/etc/sysctl.conf

[root@localhost u01]# sysctl -p

vm.nr_hugepages = 1496

[root@localhost u01]#

第六步:停止所有实例,并重启服务器

第七步验证配置

在重启系统之后,确保所有的数据库实例都已经启动,使用如下命令检查HugePage的状态

[oracle@localhost ~]$ grep HugePages/proc/meminfo

HugePages_Total: 1496

HugePages_Free: 485

HugePages_Rsvd: 446

HugePages_Surp: 0

[oracle@localhost ~]$

为了确保HugePages配置的有效性,HugePages_Free值应该小于HugePages_Total 的值,并且应该等于HugePages_Rsvd的值。

Hugepages_Free 和HugePages_Rsvd的值应该小于SGA 分配的gages。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: