Linux Huge Page
by Wenwei Weng
When a process uses some memory, the CPU is marking the RAM as used by that process. For efficiency, the CPU allocate RAM by chunks of 4K bytes (it’s the default value on many platforms). Those chunks are named pages. Those pages can be swapped to disk, etc.
Since the process address space are virtual in Linux, the CPU and the operating system have to remember which page belong to which process, and where it is stored, i.e. translate from virtual to physical address. The translation is done through TLB. A TLB is a cache of virtual-to-physical translations. Typically this is a very scarce resource on processor. Operating systems try to make best use of limited number of TLB resources. Huge page is a way to reduce number of pages in the kernel so that less TLB entries are used, translation will be faster.
#How to check if the running kernel supports huge page ?
By checking the kernel config, we can find if huge pages is supported.
#How to check what are supported huge page size using “hugeadm” tool?
The above output shows that the supported huge page size is 2MB.
#How to check the current huge pages status?
where: HugePages_Total is the size of the pool of huge pages. HugePages_Free is the number of huge pages in the pool that are not yet allocated. HugePages_Rsvd is short for “reserved,” and is the number of huge pages for which a commitment to allocate from the pool has been made, but no allocation has yet been made. Reserved huge pages guarantee that an application will be able to allocate a huge page from the pool of huge pages at fault time. HugePages_Surp is short for “surplus,” and is the number of huge pages in the pool above the value in /proc/sys/vm/nr_hugepages. The maximum number of surplus huge pages is controlled by /proc/sys/vm/nr_overcommit_hugepages.
The above output says there is no huge pages created so far.
#How to create huge pages ? There are two ways:
- Add kernell boot parameter, e.g. "hugepagesz=2MB hugepages=16"
- Create on the fly, e.g. 'echo 16 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages'
Verify if it is created:
#How to use these huge pages?
First, we need create a directory as mount point, then mount it like below:
Now /mnt/huge/ is ready to be used.
1) map_hugetlb: see tools/testing/selftests/vm/map_hugetlb.c
2) hugepage-shm: see tools/testing/selftests/vm/hugepage-shm.c
3) hugepage-mmap: see tools/testing/selftests/vm/hugepage-mmap.c
4) The libhugetlbfs (https://github.com/libhugetlbfs/libhugetlbfs) library provides a wide range of userspace tools to help with huge page usability, environment setup, and control.
Subscribe via RSS