PostgreSQL DBA(100) - Linux(Huge Pages)

husthxd 發表於 2019-09-27

PostgreSQL通過引數huge_pages設定是否啟用大頁,利用常駐記憶體用以提升效能,本節簡單介紹了Linux中Huge Pages的相關設定。

Check if CPU supports HugePages 2MB Size
命令如下,關鍵字是 pse(Page Size Extension)

[[email protected] ~]# cat /proc/cpuinfo | grep pse | uniq
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm fsgsbase smep arat
[[email protected] ~]# 
[[email protected] ~]#cat /proc/cpuinfo | egrep -o pse | head -n 1
pse
[[email protected] ~]#

Check if CPU supports HugePages 1GB Size
命令如下,關鍵字是pdpe1gb

[[email protected] ~]# grep pdpe1gb /proc/cpuinfo | head -n 1
flags   : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm fsgsbase smep arat
[[email protected] ~]# 
[[email protected] ~]# egrep -o pdpe1gb /proc/cpuinfo | head -n 1
pdpe1gb
[[email protected] ~]#

How to change default HugePage size?
預設大小為2MB

[[email protected] ~]# grep Hugepagesize: /proc/meminfo
Hugepagesize:       2048 kB
[[email protected] ~]#

修改命令為

[[email protected] ~]# grep GRUB_CMDLINE_LINUX /etc/sysconfig/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
[[email protected] ~]# 
[[email protected] ~]# vim /etc/sysconfig/grub
[[email protected] ~]# grep GRUB_CMDLINE_LINUX /etc/sysconfig/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet  default_hugepagesz=1G"
[[email protected] ~]# 
[[email protected] ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.2.14-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.2.14-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.27.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.27.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-f0b4bffdc9e44816abd201320f8a4f75
Found initrd image: /boot/initramfs-0-rescue-f0b4bffdc9e44816abd201320f8a4f75.img
done
[[email protected] ~]# 
[[email protected] ~]# reboot
Connection closed by foreign host.
[[email protected] ~]# grep Hugepagesize /proc/meminfo
Hugepagesize:    1048576 kB
[[email protected] ~]#

參考資料
Check if CPU supports HugePages & change default hugepage size in RHEL 7

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/6906/viewspace-2658465/,如需轉載,請註明出處,否則將追究法律責任。