Oracle数据库在linux平台上开启大页特性

1、检查memory_targetmemory_max_target,如果不为0,将其更改为0.

SQL> show parameter memory_target

 

NAME      TYPE  VALUE

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

memory_target      big integer 0

SQL> show parameter memory_max_target

 

NAME      TYPE  VALUE

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

memory_max_target      big integer 0

SQL>

2、计算hugepages的值(脚本内容见最后)

[root@gxjzfpdb01 soft]# ./hugepages_settings.sh 

 

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...

 

Recommended setting: vm.nr_hugepages = 19012

 得出大页的大小为19012页(注:一页为2M,这个值不可改,19012*2M=38024M),实际上hugepages与参数sga_max_size有关,比sga_max_size的值稍微大一点点(比SGA_MAX_SIZE最少要多加一页,2M的页不要分配超过sga_max_size太多,会造成内存的浪费):

SQL> show parameter sga

 

NAME      TYPE  VALUE

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

lock_sga      boolean  FALSE

pre_page_sga      boolean  FALSE

sga_max_size      big integer 38016M

sga_target      big integer 38016M

3、设置hugepages,在内核参数中添加一行,vi /etc/sysctl.conf

vm.nr_hugepages = 19012

4、修改内核参数立即生效
[root@gxjzfpdb01 ~]# sysctl -p

5设定/etc/security/limits.conf文件,以K为单位,必须大于sga_max_size,这里设定为89128960

[root@gxjzfpdb01 ~]# vi /etc/security/limits.conf

*   soft   memlock   89128960 

*   hard   memlock   89128960

6检查limits是否正确
[root@gxjzfpdb01 ~]# su - oracle
[oracle@gxjzfpdb02 ~]$ ulimit -l

89128960

7、重启数据库,检查大页是否被使用。

SQL> shu immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,

Data Mining and Real Application Testing options

[oracle@gxjzfpdb02 ~]$ exit

logout

[root@gxjzfpdb02 ~]# su - oracle

[oracle@gxjzfpdb02 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 11.2.0.4.0 Production on Mon Jun 6 11:40:56 2016

 

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

 

Connected to an idle instance.

 

SQL> startup

ORACLE instance started.

 

Total System Global Area 3.9685E+10 bytes

Fixed Size     2261728 bytes

Variable Size  6576672032 bytes

Database Buffers  3.3018E+10 bytes

Redo Buffers    88203264 bytes

Database mounted.

Database opened.

SQL>

检查大页特性是否使用:

[root@gxjzfpdb02 soft]# cat /proc/meminfo | grep Hu

AnonHugePages:    342016 kB

HugePages_Total:   19012

HugePages_Free:    15157

HugePages_Rsvd:    15154

HugePages_Surp:        0

Hugepagesize:       2048 kB

[root@gxjzfpdb02 soft]#

注:
HugePages_Total:  19012---总共1028
HugePages_Free:    15157---空闲15157页,即当前大页被使用了19012-15157=3855页,即被用了3855*2M=7710M,小于sga_target
HugePages_Rsvd:    15154---操作系统承诺给Oracle预留15154页,即15154*2M=30308M30308+7710==SGA_MAX_SIZE
Hugepagesize:     2048 kB --每页是2M,不可修改

可以看到,大页已被使用,至此,大页特性已经开启。

附脚本内容:
#!/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



请使用浏览器的分享功能分享到微信等