Step-by-Step HugePages Configuration (Oracle 19c on Linux)
🔹 Step 1: Check Current HugePages Status
grep Huge /proc/meminfo
Key parameters:
HugePages_TotalHugePages_FreeHugepagesize (usually 2 MB)
🔹 Step 2: Disable Transparent HugePages (THP)
Oracle recommends disabling THP.
Check status:
cat /sys/kernel/mm/transparent_hugepage/enabled
Disable temporarily:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
Disable permanently:
Edit:
vi /etc/default/grub
Add:
transparent_hugepage=never
Then apply:
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot
🔹 Step 3: Calculate Required HugePages
3.1 Check Oracle SGA size
From SQL:
show parameter sga_target;
or:
show parameter memory_target;
3.2 Use Oracle Script (Recommended)
$ORACLE_HOME/bin/hugepages_settings.sh
If not available, download from Oracle MOS.
3.3 Manual Calculation
Formula:
HugePages = Total_SGA_Size / HugePage_Size
Example:
- SGA = 64 GB
- Page size = 2 MB
64 * 1024 MB / 2 MB = 32768 HugePages
🔹 Step 4: Configure HugePages in Kernel
Edit:
vi /etc/sysctl.conf
Add/update:
vm.nr_hugepages=32768
Apply:
sysctl -p
🔹 Step 5: Configure memlock for Oracle User
Edit:
vi /etc/security/limits.conf
Add:
oracle soft memlock 67108864
oracle hard memlock 67108864
👉 Value should match SGA size (in KB)
Example:
64 GB = 67108864 KB
🔹 Step 6: Disable AMM (Very Important)
HugePages does NOT work with AMM.
Check:
show parameter memory_target;
If > 0, disable:
ALTER SYSTEM SET memory_target=0 SCOPE=SPFILE;
ALTER SYSTEM SET memory_max_target=0 SCOPE=SPFILE;
Instead, use ASMM:
ALTER SYSTEM SET sga_target=64G SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target=8G SCOPE=SPFILE;
Restart DB:
shutdown immediate;
startup;
🔹 Step 7: Restart Server
reboot
🔹 Step 8: Validate HugePages Usage
grep Huge /proc/meminfo
Check:
HugePages_Total → should match configured valueHugePages_Free → should decrease after DB startHugePages_Rsvd → reserved pages
🔹 Step 9: Verify Oracle is Using HugePages
grep -i huge /proc/meminfo
Also check alert log:
grep HugePages $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log
Expected message:
Huge Pages allocation successful
✅ Best Practices
✔ Always leave some RAM for OS (not 100% HugePages)
✔ Use static SGA (ASMM)
✔ Set HugePages slightly higher than requirement
✔ Monitor with:
vmstat
free -g
⚠️ Common Mistakes
❌ Using AMM (memory_target)
❌ Not setting memlock
❌ THP not disabled
❌ Underestimating number of HugePages
🚀 Quick Example Summary
For a 64 GB SGA:
| Setting | Value |
|---|
| HugePage size | 2 MB |
| Required pages | 32768 |
| memlock | 67108864 KB |
| vm.nr_hugepages | 32768 |
Oracle Script for huge_page setting
vi 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 KB151310 from My Oracle Support
# http://support.oracle.com
# Welcome text
echo "
This script is provided by KB151310 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 the overall 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 Automatic Memory Management (AMM) is not setup
(See KB83222)
* 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 Automatic Memory Management (AMM) is not configured"
exit 1
fi
# Finish with results
echo "Recommended setting: vm.nr_hugepages = $NUM_PG";
# End
No comments:
Post a Comment