Huge pages are memory pages whose size is larger than the traditional page size of 4 KB. Huge pages help accelerate memory access and reduce the number of Translation Lookaside Buffer (TLB) misses during address translation. In most cases, the size of a huge page is 2 MB. If an excessive number of huge pages are allocated, the amount of regular memory that the operating system can dynamically allocate to applications or services decreases. As a result, the applications or system services that do not use huge pages may get stuck or fail to run due to insufficient memory. If the size of huge pages on an Elastic Compute Service (ECS) instance is excessively large, you may be unable to connect to the instance. This topic describes how to adjust the huge page size on a Linux ECS instance.
Procedure
Connect to the Linux ECS instance by using Virtual Network Computing (VNC).
For more information, see Connect to an instance by using VNC.
Run the following command to back up the
/etc/sysctl.conf
file:cp /etc/sysctl.conf /etc/sysctl.conf_bak
Run the following command to open the
/etc/sysctl.conf
file:sudo vim /etc/sysctl.conf
Find the
vm.nr_hugepages
parameter and decrease the value of the parameter.Calculate the required number of huge pages based on the size of huge pages required by applications and the total memory size of the system by using the following formula:
Required number of huge pages = Size of huge pages required by applications/Size of a huge page. In most cases, the default size of a huge page in Linux is 2 MB. For example, if an application requires 16 GB of huge pages and the size of a huge page is 2 MB, the application requires 8,192 huge pages, which is calculated by using the following formula: 16 GB/2 MB = 8,192. In the preceding example, change the vm.nr_hugepages parameter to the following value:
vm.nr_hugepages = 8,192
Run the following command to allow the change to take effect:
sudo sysctl -p
View the
/proc/meminfo
file to check whether the change takes effect.cat /proc/meminfo
References
Alibaba Cloud Linux can use transparent huge pages (THPs) and huge pages to improve system performance. For more information, see THP-related performance optimization in Alibaba Cloud Linux and Huge Pages.