当前位置: 首页 > ORACLE > 正文

7 easy steps to configure HugePages for your Oracle Database Server

Hugepages and Large Pages

If you run a Oracle Database on a Linux Server with more than 16 GB physical memory and your System Global Area (SGA) is greater than 8 GB, you should configure HugePages. Oracle promises more performance by doing this. A HugePages configuration means, that the linux kernel can handle „large pages“, like Oracle generally calls them. Instead of standardly 4 KB on x86 and x86_64 or 16 KB on IA64 systems – 4 MB on x86, 2 MB on x86_64 and 256 MB on IA64 system. Bigger pages means, that the system uses less page tables, manages less mappings and by that reduce the effort for their management and access.
However their is a limitation by Oracle, because Automatic Memory Management (AMM) does not support HugePages. If you already use AMM and MEMORY_TARGET is set you have to disable it and switch back to Automatic Shared Memory Management (ASMM). That means set SGA_TARGET and PGA_AGGREGATE_TARGET. But there is another innovation called Transparent Hugpages (THP) which should be disabled as well. The feature will be delivered since Red Hat Linux 6 or a according derivate. Oracle as well as Red Hat recommend to disable Transparent Hugepages. Explanation in point 5 – Change Server configuration. So lets get started and come to the 7 steps:

1. Check Physical Memory

First we should check our „physical“ available Memory. In the example we have about 128 GB of RAM. SGA_TARGET and PGA_AGGREGATE_TARGET together, should not be more than the availabel memory. Besides should be enough space for OS processes itself:
grepMemTotal /proc/meminfo
MemTotal:65712800 kB
2. Check Database Parameter
Second check your database parameter. Initially: AMM disabled? MEMORY_TARGET and MEMORY_MAX_TARGET should be set to 0:
ALTER SYSTEM RESET memory_target SCOPE=SPFILE;
SQL>select value from v$parameterwherename =’memory_target’;
VALUE —————————
0
How big is our SGA? In this example about 40 GB. Important: In the following query we directly convert into kB (value/1024). With that we can continue to calculate directly:
ALTER SYSTEM SET sga_target=28G SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target=5760M SCOPE=SPFILE;
SQL>select value/1024 from v$parameterwherename =’sga_target’;
VALUE
—————————
29360128
Finally as per default the parameter use_large_pages should be enabled:
SQL>select value from v$parameterwherename =’use_large_pages’;
VALUE
—————————
TRUE

3. Check Hugepagesize

In our example we use a x86_64 Red Hat Enterprise Linux Server. So by default hugepagesize should be set to 2 MB:
grepHugepagesize /proc/meminfo
Hugepagesize:      2048kB

4. Calculate Hugepages

For the calculation of the number of hugepages there is a easy way:
SGA/ Hugepagesize = Number Hugepages
Following our example:
29360128 / 2048 = 14336
If you run more than one database on your server, you should include the SGA of all of your instances into the calculation:
( SGA1.Instance + SGA2.Instance + … etc. ) / Hugepagesize =NumberHugepages
In My Oracle Support you can find a script (Doc ID 401749.1) called hugepages_settings.sh, which does the calculation. This also includes a check of your kernel version and the actually used shared memory area by the SGA. Please consider that this calculation observes only the actual use of SGA and their use. If your second instance is down it will be not in the account. That means to adjust your SGA and restart your database first. Than you can run the script. Result should be the following line. Maybe you can make your own calculation and than check it with the script:
Recommendedsetting: vm.nr_hugepages =14336

5. Change Server Configuration

The next step is to enter the number of hugepages in the server config file. For that you need root permissions. On Red Hat Linux 6 /etc/sysctl.conf.
vm.nr_hugepages = ( sga_m / 4m + 3 )
vi/etc/sysctl.conf
vm.nr_hugepages=14336
Correctly inserted, following result should show up:
grepvm.nr_hugepages /etc/sysctl.conf
vm.nr_hugepages=14336
The next parameter is hard and soft memlock in /etc/security/limits.conf for our oracle user. This value should be smaller than our available memory but minor to our SGA. Our hugepages should fit into that by 100 percent. For that following calculation:
NumberHugepages * Hugepagesize = minimum Memlock
Following our example:(字节)
14336 * 2048 = 29360128
vi/etc/security/limits.conf
oracle               soft    memlock29360128
oracle               hard    memlock29360128
Correctly inserted, following result should show up:
greporacle /etc/security/limits.conf
oracle               soft    memlock29360128
oracle               hard    memlock29360128
As mentioned before we have to disable transparent hugepages from Red Hat Linux version 6 ongoing:
cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
echo never >/sys/kernel/mm/transparent_hugepage/enabled
echo never >/sys/kernel/mm/transparent_hugepage/defrag
cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

6. Server Reboot

If all parameter are set, make a complete reboot your server. As an alternative you can reload the parameters with sysctl -p.

7. Check Configuration

Memlock correct?
ulimit-l
29360128
HugePages correctly configured and in use?
grep Huge /proc/meminfo
AnonHugePages:    538624 kB
HugePages_Total:    20480
HugePages_Free:     12292
HugePages_Rsvd:      8188
HugePages_Surp:        0
Hugepagesize:       2048 kB
Transparent Hugepages disabled?
cat/sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
Did the database uses HugePages? For that we take a look into the alert log. After „Starting ORACLE instance (normal)“ following entry „Large Pages Information“ gives us advise:
************************ Large Pages Information *******************
Per process system memlock (soft) limit = 100 GB
Total Shared Global Region in Large Pages = 40 GB (100%)
Large Pages used by this instance: 20481 (40 GB)
Large Pages unused system wide = 0 (0 KB)
Large Pages configured system wide = 20481 (40 GB)
Large Page size = 2048 KB
********************************************************************
第一次配置:
************************ Large Pages Information *******************
Per process system memlock (soft) limit = 60 GB
Total Shared Global Region in Large Pages = 28 GB (100%)
Large Pages used by this instance: 14337 (28 GB)
Large Pages unused system wide = 2047 (4094 MB)
Large Pages configured system wide = 16384 (32 GB)
Large Page size = 2048 KB
********************************************************************
第二次配置:
************************ Large Pages Information *******************
Per process system memlock (soft) limit = UNLIMITED
Total Shared Global Region in Large Pages = 28 GB (99%)
Large Pages used by this instance: 14336 (28 GB)
Large Pages unused system wide = 0 (0 KB)
Large Pages configured system wide = 14336 (28 GB)
Large Page size = 2048 KB
RECOMMENDATION:
  Total System Global Area size is 28 GB. For optimal performance,
  prior to the next instance restart:
  1. Increase the number of unused large pages by
at least 1 (page size 2048 KB, total size 2048 KB) system wide to
  get 100% of the System Global Area allocated with large pages
********************************************************************
If your configuration is incorrect Oracle delivers recommendation here for the right setting. In the following example exactly one Page is missing, so 2048 kB memlock to come to 100% of SGA use of hugepages:
************************ Large Pages Information *******************
RECOMMENDATION:
Total System Global Area size is 40 GB. For optimal performance,
prior to the next instance restart:
1.Increase the number of unused large pages by
at least 1 (page size 2048 KB, total size 2048 KB) system wide to
get 100% of the System Global Area allocated with large pages
2.Large pages are automatically locked into physical memory.
Increase the per process memlock (soft) limit to at least 40 GB to lock
100% System Global Area’s large pages into physical memory
********************************************************************

Hugepage计算脚本

REQUIREMENTS

  1. Oracle Database instance(s) are up and running
  2. Oracle Database 11g Automatic Memory Management (AMM) is not setup (See Note 749851.1)
  3. The shared memory segments can be listed by command “ipcs -m”
  4. Oracle Linux
  5. Package ‘bc’ installed

CONFIGURING

  1. Create a text file named hugepages_settings.sh
  2. Copy the contents below in the file
cat ./hugepages_settings.sh
#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
# on Oracle Linux
#
# 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 on Oracle Linux. 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” ;;
    ‘3.8’) echo “Recommended setting: vm.nr_hugepages = $NUM_PG” ;;
    ‘3.10’) echo “Recommended setting: vm.nr_hugepages = $NUM_PG” ;;
    ‘4.1’) echo “Recommended setting: vm.nr_hugepages = $NUM_PG” ;;
esac
# End
./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 on Oracle Linux. 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…
Recommended setting: vm.nr_hugepages = 14340
( sga_m / 4m + 3 )
Done!
SQL> col name for a50
SQL> select * from v$sgainfo;
NAME                                                    BYTES RESIZEABL
————————————————– ———- ———
Fixed SGA Size                                        2267792 No
Redo Buffers                                         64827392 No
Buffer Cache Size                                  2.5703E+10 Yes
Shared Pool Size                                   3422552064 Yes
Large Pool Size                                     402653184 Yes
Java Pool Size                                      335544320 Yes
Streams Pool Size                                           0 Yes
Shared IO Pool Size                                         0 Yes
Granule Size                                         67108864 No
Maximum SGA Size                                   2.9931E+10 No
Startup overhead in Shared Pool                    2148965528 No
NAME                                                    BYTES RESIZEABL
————————————————– ———- ———
Free SGA Memory Available                                   0
12 rows selected.

sga_target和sga_max_size
pga_aggregate_target = sga_target * 20%

SQL> col type for a8
SQL> col value for a20
SQL> show parameter control_management_pack_access
NAME                                 TYPE     VALUE
———————————— ——– ——————————
control_management_pack_access       string   DIAGNOSTIC+TUNING
SQL> show parameter sga_target;
NAME_COL_PLUS_SHOW_PARAM
——————————————————————————–
TYPE
———————————
VALUE_COL_PLUS_SHOW_PARAM
——————————————————————————–
sga_target
big integer
28G
SQL> select value from v$pgastat where name=’maximum PGA allocated’;
     VALUE
———-
320244736
SQL> show parameter pga_aggregate_target
NAME_COL_PLUS_SHOW_PARAM
——————————————————————————–
TYPE
———————————
VALUE_COL_PLUS_SHOW_PARAM
——————————————————————————–
pga_aggregate_target
big integer
5760M

禁用AMM(Oracle 11g)
如果当前的Oracle 版本为10g,可以跳过此步骤。
如果当前的Oracle 版本为11g,由于AMM(Automatic Memory Management)特性与Hugepages不兼容,需要禁用AMM。
SQL> select * from v$version;
BANNER
——————————————————————————–
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production
PL/SQL Release 11.2.0.4.0 – Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 – Production
NLSRTL Version 11.2.0.4.0 – Production
SQL> ALTER SYSTEM RESET memory_target SCOPE=SPFILE;
System altered.
SQL> ALTER SYSTEM RESET memory_max_target SCOPE=SPFILE;
System altered.
SQL> ALTER SYSTEM SET sga_target=28G SCOPE=SPFILE;
System altered.
SQL> ALTER SYSTEM SET pga_aggregate_target=5760MSCOPE=SPFILE;
System altered.
此时Oracle选择ASMM,对应参数USE_LARGE_PAGES为TRUE。
SQL> show parameter use_large
NAME                                 TYPE        VALUE
———————————— ———– ——————————
use_large_pages                      string      TRUE

本文固定链接: http://t.yjsec.com/index.php/2018/07/17/594/ | 下一站

该日志由 admin 于2018年07月17日发表在 ORACLE 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 7 easy steps to configure HugePages for your Oracle Database Server | 下一站

7 easy steps to configure HugePages for your Oracle Database Server:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter