Generally, the memory used is 4 kb per page. If the huge page is used, the default memory is 2 MB per page. If you set MySQL to use the huge page, there are at least two advantages: one is to reduce the errors of the translation lookaside buffer (TLB) to improve performance, the other is to ensure that MySQL memory is not exchanged to swap by using the feature that the huge page does not use swap.
MySQL 5.0.3 and later support the huge page on Linux. You can use the large-page option to start MySQL.
Of course there are some related system settings.
echo 400 > /proc/sys/vm/nr_hugepages
This specifies the total number of huge pages, which can be placed in/etc/rc. Local. Because the allocation requires continuous memory space, if the execution is performed on the system for a period of time, it may not be allocated to the specified amount, even if there is enough memory.
You also need to set the kernel parameters kernel. shmmax and kernel. Shmall. Otherwise, MySQL will report the 22 error at startup.
InnoDB: HugeTLB: Warning: Failed to allocate 536887296 bytes. errno 22
Shmmax is the maximum size of the shared memory segment, in bytes. The default value is 32 MB, which is definitely not enough. This should be larger than innodb_buffer_pool. Shmall indicates the total size of the shared memory. The unit is page. The default value is 2097152 (8 GB ). You can use sysctl-W or set it in/etc/sysctl. conf.
In addition, you also need to set Max locked memory, use ulimit-l or set/etc/security/limits. conf. Otherwise, a 12 error will be reported:
Warning: Failed to allocate 31457280 bytes from HugeTLB memory. errno 12
MySQL can be used after startup
grep Huge /proc/meminfo
View the usage of the huge page.
HugePages_Total: 400
HugePages_Free: 128
Hugepagesize: 2048 kB