Understanding Hugepage
Virtual Memory in Linux
In a multi-task system, the operation to the memory of different processes will have conflict problems. To solve this problem, the concept of virtual memory comes. When the process starting, OS will assign virtual memory addresses for the process to use. Also, OS will map the virtual memory addresses to physical memory addresses. So we need to mapping the table to maintain the relationship between the virtual memory address and the physical memory address.
However, if we 1:1 map the virtual and physical memory address, the table would be too large to search and maintain. To solve this problem, the concept of paging and page table comes.
Linux Paging and Page Table
In memory management, the OS will separate the physical memory into many pages (default size 4K). When the OS needs to allocate virtual memory addresses from physical memory addresses, it will assign pages. So that the mapping table between virtual memory address to physical memory address will be much smaller. In this case, we also need a table to maintain the mapping between the virtual pages and the physical pages. We called this table a paging table.
Hugepages
The OS will use a 4K size to divide memory into many pages by default. However, when the memory size becomes large, the number of pages will also be large, which will cause low efficiency when the CPU searches the memory address page by page. To solve this problem, we can only extend the size of the pages to reduce the number of pages. That’s the original concept of hugepages. We can define hugepages as 2M, 4M, 6M, and 1G max.
Hugepage Terminology
TLB
Translation Lookside Buffer is a cache in CPU with a certain size to store parts of the paging table to accelerate the mapping between virtual memory and physical memory.
hugetlb
hugetlb is the TLBs to process the mapping of hugepages.
hugetlbfs
hugetlbfs is a file system type based on memory. TLB can point to the actual hugepage memory through hugetlb. The hugepages assigned by the OS will be used by the memory as the file in the hugetlbfs.
Hugepage配置
Permanent Config
Change /etc/default/grub
content,add
after GRUB_CMDLINE_LINUX_DEFAULT
.
generate grub2 configuration
|
|
reboot
|
|
Check kernel params in cmdline
|
|
install hugepage filesystem