Thursday, December 10, 2009

Linux HugePages for Oracle

HugePages is a feature in the Linux kernel with release 2.6. This feature provides the alternative to the 4K page size providing bigger pages, and is a very useful feature when we have a big SGA configured for the Oracle database.


To setup HugePages, the following changes must be completed:

Set the vm.nr_hugepages kernel parameter to a required value.

In this test case we will use a 20GB SGA , we can calculate the vm.nr_hugepages as below

Assuming we have only one instance running in the box, and also we have a 2MB hugepage for Linux x86_64.

(20480 MB [SGA] + 260 [buffer+ reserve for other applications to use shared memory] )/2 MB = 10500

and from the above derivation we set the value as below:

sysctl -w vm.nr_hugepages=10500


/etc/securities/limits.conf must be updated to increase soft and hard memlock values for oracle userid.

oracle soft memlock 20971520
oracle hard memlock 20971520

After setting this up, we will test to see if SGA is using HugePages.

The value, (HugePages_Total- HugePages_Free)*2MB will be the approximate size of SGA.

SQL> show parameter sga

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 1536M
sga_target big integer 1536M

SQL> alter system set sga_max_size=20g scope=spfile sid='*';

srvctl stop database -d test
srvctl start database -d test

SQL> show parameter sga

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 20G
sga_target big integer 1536M

$ cat /proc/meminfo |grep HugePages
HugePages_Total: 10500
HugePages_Free: 10297
HugePages_Rsvd: 10038

SQL> alter system set sga_target=20g scope=both sid='test2';

$ cat /proc/meminfo |grep HugePages
HugePages_Total: 10500
HugePages_Free: 818
HugePages_Rsvd: 559

Note : When started up using sqlplus the hugepages is not being used, bu twhen started up using srvctl it works.

[Metalink Reference HugePages on Linux: What It Is... and What It Is Not... [ID 361323.1]]
[Metalink Reference Shell Script to Calculate Values Recommended HugePages / HugeTLB Configuration [ID 401749.1]]