How to Configuring HugePages on Linux Server.

Introduction:-

In this article, we will learn how to configuring hugepages on linux. Create a file called “hugepages_setting.sh” to Configuring HugePages with the mentatory contents.

HugePages:-

The operating system keeps each 4 KB of memory as a page. When it allocates pages to the database System Global Area (SGA), the operating system kernel must continually update its page table with the page life cycle (dirty, free, mapped to a process, and so on) for each 4 KB page allocated to the SGA.

The operating system page table (virtual memory to physical memory mapping) is smaller, because each page table entry is pointing to pages from 2 MB to 256 MB.

Also, the kernel has fewer pages whose lifecycle must be monitored. For example, if you use HugePages with 64-bit hardware, and you want to map 256 MB of memory, you may need one page table entry (PTE). If you do not use HugePages, and you want to map 256 MB of memory, then you must have 256 MB * 1024 KB/4 KB = 65536 PTEs.

Oracle HugePages provides the following advantages:

👉>Increased performance through increased TLB hits.

👉>Pages are locked in memory and never swapped out, which provides RAM for shared memory structures such as SGA.

👉>Contiguous pages are preallocated and cannot be used for anything else but for System V shared memory (for example, SGA).

👉>Less bookkeeping work for the kernel for that part of virtual memory because of larger page sizes.

Configuring HugePages on Linux:-

Follow the below steps to complete oracle hugepages configuration in linux operating system.

Check if kernal support hugepages.

$ grep Huge /proc/meminfo

AnonHugePages:         0 kB

HugePages_Total:       0

HugePages_Free:        0

HugePages_Rsvd:        0

HugePages_Surp:        0


Hugepagesize:       2048 kB

The default HugePage size is 2MB on Oracle Linux 5.x and as you can see from the output below, by default no HugePages are defined.

Create a file called “hugepages_setting.sh” with the following contents.

#!/bin/bash

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

# Check for the kernel version

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

# Find out the HugePage size

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

# Start from 1 pages to be on the safe side and guarantee 1 free HugePage

NUM_PG=1

# 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

# 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' | '3.8' | '3.10' | '4.1' | '4.14' ) echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;

    *) echo "Unrecognized kernel version $KERN. Exiting." ;;

esac


# End

Execute as below to check recommended value for vm.nr_hugepages.

$sh hugepages_setting.sh

Recommended setting: vm.nr_hugepages = XXXXX

Calculate Hugepages manually.

SGA_TARGET=50G

SGA / Hugepagesize = Number Hugepage

52428800/2048       =25600

Calculate the Security Limits for Oracle.

Number Hugepages * Hugepagesize = minimum Memlock

/etc/security/limits.conf

25600*2048      = 52428800

$sysctl -p

Modify the file

#vi /etc/security/limits.conf

oracle               soft    memlock 52428800

oracle               hard    memlock 52428800

Run the following command as the “root” user.

#sysctl -p

Check if Memlock correct?

ulimit -l

Disabling Transparent HugePages (RHEL6/OL6 and RHEL7/OL7)

For Oracle Linux 6 the preferred method to disable Transparent HugePages is to add "transparent_hugepage=never" to the kernel boot

The following instruction are for Redhat 6 or lower, Oracle Linux 6 or lower, and SLES 11 or lower:



To check if the Transparent HugePages are enabled in your server execute the following:


Default/Enabled setting is  [always]:


# cat /sys/kernel/mm/transparent_hugepage/enabled

[always] never

To disable Transparent HugePages boot time

echo never > /sys/kernel/mm/transparent_hugepage/enabled

echo never > /sys/kernel/mm/transparent_hugepage/defrag

before reboot.

ulimit -l

64

Reboot the Server.

After reboot, check HugePages correctly configured and in use?

echo 1 > /proc/sys/vm/drop_caches

#grep Huge /proc/meminfo

grep Huge /proc/meminfo

AnonHugePages:         0 kB

HugePages_Total:   25604

HugePages_Free:      682

HugePages_Rsvd:      678

HugePages_Surp:        0

Hugepagesize:       2048 kB

 
Check the MEMORY_TARGET parameters are not set for the database and SGA_TARGET and PGA_AGGREGATE_TARGET parameters are being used instead.

SQL> show parameter target

 

NAME                                      TYPE        VALUE

———————————— ———– ——————————

archive_lag_target                    integer     0

db_flashback_retention_target   integer     1440

fast_start_io_target                   integer     0

fast_start_mttr_target               integer     0

memory_max_target                 big integer 0

memory_target                         big integer 0

parallel_servers_target              integer     8

pga_aggregate_target               big integer 10G

sga_target                                big integer 50G

 

Related/Referance post:-

Leave a Comment