Oracle优化之配置内存大页以及异步IO(仅限CENTOS6)

Oracle优化之配置内存大页以及异步IO(仅限CENTOS6)

关闭THP

vi /etc/rc.local

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi


cat /sys/kernel/mm/transparent_hugepage/enabled

修改 limits.conf

vi /etc/security/limits.conf

oracle soft memlock unlimited
oracle hard memlock unlimited

编写hugepages_settings.sh

#!/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 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" ;;
esac

# End

修改/etc/sysctl.conf

这里可以不使用上述脚本,自己估计就好,譬如ORACLE内存1G,大页默认是2M,那么只要保证个数比Oracle使用的内存大就可以,比系统总内存小上述脚本可用可不用

vi /etc/sysctl.conf
vm.nr_hugepages = 51200
#是全部允许使用的共享内存大小,shmmax 是单个段允许使用的大小。这两个可以设置为内存的 90%,必须保证比SGA大
kernel.shmall = 123695058124
kernel.shmmax = 123695058124

sysctl -p
cat /proc/meminfo |grep Huge

禁用AMM(Oracle 11g)

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

通过如下执行查询大页内存是否正常
cat /proc/meminfo |grep Huge

oracle启用异步IO

1 检查是否有依赖包,没有自行安装

rpm -qa | grep aio 

libaio-0.3.107-10.el6.x86_64
libaio-devel-0.3.107-10.el6.x86_64

2 检查系统是否支持异步I/O

cat /proc/slabinfo | grep kio 
kioctx                32     60    384   10    1 : tunables   54   27    8 : slabdata      6      6      0
kiocb                 90    105    256   15    1 : tunables  120   60    8 : slabdata      7      7      0

3 修改、优化系统内核参数

cat /proc/sys/fs/aio-max-nr
1048576
# 根据需要自定义,可以通过/etc/sysctl.conf进行修改
vi /etc/sysctl.conf

fs.aio-max-nr = 1048576

4 检查ORACLE软件是否支持开启AIO

/usr/bin/ldd $ORACLE_HOME/bin/oracle | grep libaio
libaio.so.1 => /lib64/libaio.so.1 (0x0000003c47000000)
/usr/bin/nm $ORACLE_HOME/bin/oracle | grep io_getevent 
 w io_getevents@@LIBAIO_0.4

5 数据库级别启用异步I/O

alter system set filesystemio_options = setall scope=spfile; 
alter system set disk_asynch_io = true scope=spfile; 

6 参数知识

You can use the FILESYSTEMIO_OPTIONS initialization parameter to enable or disable asynchronous I/O or direct I/O on file system files. This parameter is platform-specific and has a default value that is best for a particular platform. It can be dynamically changed to update the default setting.

FILESYTEMIO_OPTIONS can be set to one of the following values:

  • ASYNCH: enable asynchronous I/O on file system files, which has no timing requirement for transmission.

    在文件系统文件上启用异步I/O,在数据传送上没有计时要求。

  • DIRECTIO: enable direct I/O on file system files, which bypasses the buffer cache.

    在文件系统文件上启用直接I/O,绕过buffer cache。

  • SETALL: enable both asynchronous and direct I/O on file system files.

    在文件系统文件上启用异步和直接I/O。

  • NONE: disable both asynchronous and direct I/O on file system files.

    在文件系统文件上禁用异步和直接I/O。

注:
1 ORA-27102: out of memory,这个错误不一定是shm造成的,也可能是kernel.shmall = 123695058124
kernel.shmmax = 123695058124这两个值设置的比SGA小造成的,所以具体问题具体分析

你可能感兴趣的:(oracle)