Oracle Database, bellek yönetimini optimize etmek için Linux sistemlerde HugePages kullanımını destekler. HugePages, özellikle büyük veritabanı sistemlerinde bellek parçalanmasını önler ve performansı artırabilir. Ancak her sistemde gerekli olmayabilir. Bu yazıda HugePages’in nasıl etkinleştirileceğini ve gerektiğinde nasıl kaldırılacağını anlatacağım.
1. HugePages Nedir?
HugePages, Linux çekirdeğinin normalden daha büyük bellek sayfaları ayırmasına olanak tanır. Normalde sayfa boyutu 4KB iken, HugePages ile bu boyut 2MB veya 1GB olabilir.
2. Oracle Database Kurulmadan Önce HugePages Ayarlanması
Bu yöntem, veritabanı kurulumundan önce HugePages’i hazır hale getirerek Oracle’ın baştan bu yapıyla çalışmasını sağlar.
2.1. NUMA’yı devre dışı bırakmak (isteğe bağlı ama önerilir)
Eğer sunucunda NUMA destekliyse, Oracle için önerilen yöntem NUMA’yı devre dışı bırakmaktır. Oracle Database Preinstallation RPM kurulduğunda Linux x86_64 ve Linux aarch64 makineleri için çekirdekte numa=off değerini ayarlar.
Bunu GRUB yapılandırmasında yapabilirsin:
vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/ol-swap rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rhgb quiet numa=off transparent_hugepage=never"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
Oracle Database Preinstallation RPM kurulu değilse veya herhangi bir nedenden dolayı NUMA aktif ise GRUB_CMDLINE_LINUX satırına şu ifadeyi ekle:
numa=off
Kaydettikten sonra GRUB’u yeniden oluştur:
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
2.2. Bellek Miktarına Göre HugePages Hesaplama
SGA için ayrılacak bellek miktarını belirleyin. Sunucuda 64 GB bellek olduğunu varsayarak hesaplayalım.
İlk olarak, sistemdeki toplam fiziksel belleği kontrol ediyoruz:
# grep MemTotal /proc/meminfo
MemTotal: 67108864 kB
Oracle için SGA’nın, sistem belleğinin yaklaşık %90’ını kullanmasını istiyoruz (ihtiyaca göre değişebilir).
%90 x 67108864 kB = 60397977 kB ≈ 57,5 GB
Geri kalan 6,5 GB sistem ve PGA için ayrılabilir.
Sisteminizdeki HugePage boyutunu kontrol etmek için:
# cat /proc/meminfo | grep Hugepagesize
Hugepagesize: 2048 kB
Bu durumda her bir HugePage 2 MB boyutundadır.
Hedef belleği (3343604 kB) HugePage boyutuna (2048 kB) bölelim:
60397977 / 2048 = 29490
Bu durumda 29.490 adet HugePage ayırmamız gerekiyor.
Aşağıdaki satırı /etc/sysctl.conf dosyasının sonuna ekleyin:
vm.nr_hugepages = 29490
Değişiklikleri etkinleştirmek için:
# sudo sysctl -p
...
vm.nr_hugepages = 29490
oracle kullanıcısına belleği kilitleme izni vermek için /etc/security/limits.conf dosyasına şu satırları ekleyin:
oracle soft memlock 60397977
oracle hard memlock 60397977
Ayrıca /etc/pam.d/login dosyasında şu satırın bulunduğundan emin olun:
session required pam_limits.so
Oracle, RAC ortamlarında düğüm yeniden başlatmalarına yol açabilecek bellek erişim gecikmelerini önlemek için Transparent HugePages’in devre dışı bırakılmasını önerir. Oracle Database Preinstallation RPM kurulumunda Transparent HugePages’i never olarak ayarlar. Ayarlanmamış ise devre dışı bırakmalıyız:
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
Bu ayarı kalıcı yapmak için /etc/rc.d/rc.local dosyasına (yoksa oluşturabilirsiniz) aşağıdaki satırları ekleyin:
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
Dosyayı çalıştırılabilir yapın:
chmod +x /etc/rc.d/rc.local
Yapılandırmaları uyguladıktan sonra sistemi yeniden başlatın. Yeniden başladıktan sonra HugePages durumunu kontrol edin:
# grep Huge /proc/meminfo
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
FileHugePages: 0 kB
HugePages_Total: 29490
HugePages_Free: 29490
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 3344384 kB
2.3. Oracle Parametresi (Kurulum sonrası)
Oracle veritabanınız çalıştıktan sonra, sadece HugePages kullanılsın isterseniz aşağıdaki parametreyi ayarlayabilirsiniz:
ALTER SYSTEM SET USE_LARGE_PAGES = ONLY SCOPE=SPFILE;
Oracle kurulumundan sonra veritabanını yeniden başlatın:
shutdown immediate;
startup;
3. Oracle Database Kurulu İken HugePages Ayarlanması (64 GB Bellek)
3.1. Ön Koşul: AMM Devre Dışı Olmalı
SQL> SHOW PARAMETER memory_target;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------
memory_target big integer 1280M
SQL> sho parameter memory_max_target
NAME TYPE VALUE
------------------------------------ ----------- ------------------------
memory_max_target big integer 1280M
Eğer memory_target veya memory_max_target > 0 ise, sıfırla:
ALTER SYSTEM SET memory_target = 0 SCOPE=SPFILE;
ALTER SYSTEM SET memory_max_target = 0 SCOPE=SPFILE;
Sonra SGA ve PGA’yı ayarla:
ALTER SYSTEM SET sga_target = 60G SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target = 4G SCOPE=SPFILE;
3.2. HugePages Hesaplama Aracı
Doc ID 401749.1
cd $ORACLE_HOME/bin
vi ./hugepages_settings.sh
Script:
#!/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 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 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 Automatic Memory Management (AMM) is not configured"
exit 1
fi
# Finish with results
echo "Recommended setting: vm.nr_hugepages = $NUM_PG";
# End
chmod +x ./hugepages_settings.sh
./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 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 Doc ID 749851.1)
* The shared memory segments can be listed by command:
# ipcs -m
Press Enter to proceed...
Recommended setting: vm.nr_hugepages = 29490
Çıktıya göre örneğin yine 29490 önerildiyse, aşağıdaki adımları uygulayabilirsin.
Aşağıdaki satırı /etc/sysctl.conf dosyasının sonuna ekleyin:
vm.nr_hugepages = 29490
Değişiklikleri etkinleştirmek için:
# sudo sysctl -p
...
vm.nr_hugepages = 29490
oracle kullanıcısına belleği kilitleme izni vermek için /etc/security/limits.conf dosyasına şu satırları ekleyin:
oracle soft memlock 60397977
oracle hard memlock 60397977
HugePages kullanılması için aşağıdaki parametre ayarlanması gerekir:
ALTER SYSTEM SET use_large_pages = 'ONLY' SCOPE=SPFILE;
Oracle’ı Yeniden Başlat:
shutdown immediate;
startup;
3. HugePages’i Kaldırma
Eğer HugePages devre dışı bırakılmak istenirse:
3.1. Oracle Parametresini Kapat
ALTER SYSTEM SET use_large_pages = 'FALSE' SCOPE=SPFILE;
3.2. /etc/sysctl.conf Güncelle
vm.nr_hugepages = 0
sudo sysctl -p
3.3. limits.conf İsteğe Bağlı Temizleme
/etc/security/limits.conf dosyasına şu satırları silinebilir:
oracle soft memlock 60397977
oracle hard memlock 60397977
3.4. Oracle’ı Yeniden Başlat
shutdown immediate;
startup;







Leave a Reply to %s