1. 程式人生 > >mysql大頁記憶體的使用

mysql大頁記憶體的使用

一些系統支援記憶體頁大於預設的4KB,有很多記憶體訪問的應用通過使用大頁記憶體可以減少Translation Lookaside Buffer的缺失。

在mysql中,大頁記憶體可以被InnoDB使用,來分配buffer pool和別的記憶體

檢視是否支援大頁記憶體

shell> cat /proc/meminfo | grep -i huge
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       4096 kB

設定系統

# Set the number of pages to be used.
# Each page is normally 2MB, so a value of 20 = 40MB.
# This command actually allocates memory, so this much
# memory must be available.
echo 20 > /proc/sys/vm/nr_hugepages

# Set the group number that is permitted to access this
# memory (102 in this case). The mysql user must be a
# member of this group.
echo 102 > /proc/sys/vm/hugetlb_shm_group

# Increase the amount of shmem permitted per segment
# (12G in this case).
echo 1560281088 > /proc/sys/kernel/shmmax

# Increase total amount of shared memory.  The value
# is the number of pages. At 4KB/page, 4194304 = 16GB.
echo 4194304 > /proc/sys/kernel/shmall

對於mysql的使用,最好是shmmax與shmall接近,檢視是否配置好

shell> cat /proc/meminfo | grep -i huge
HugePages_Total:      20
HugePages_Free:       20
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       4096 kB
設定mysql使用者的memlock limit為unlimited
ulimit -l unlimited

/etc/security/limits.conf

mysql預設情況下是不用大頁記憶體的,要啟用在配置檔案中新增

[mysqld]

large-pages