Definition of Linux HugePages
In this article, we are going to talk and learn about a management system in Linux which mainly drives the memory management. Through this article we will talk about ways of enabling or disabling Hugepages in Linux, how can one determine value of a hugepage and many other intricate information. So, formally defining hugepage, it is a utility that drives virtual memory management in the Linux system. And as the name itself suggests, “huge” sized pages which are in addition to the standard 4KB page size can be managed using the concept. One can easily handle pages as huge as 1GB. Now, one must be wondering that which are those pages that require such high size and to answer that we have an example just for you! Think about using a database with high requirement of memory.
Syntax of Linux HugePages
There is no particular fixed syntax for hugepages. But according to the usability of the user, there are a bunch of them which we would discuss in this section. The first one refers to the usability of checking the current huge page details. The syntax for the same is:
grep Huge /proc/meminfo
Once the user has checked for details, one would need to know the number of huge pages the system would require currently. There is a script, also present in Oracle which we would describe in the example section. Now, once the user has checked for the details, it entails them to configure in case it is required. That can be done in /etc/sysctl.conf and once the variable is changed there, the following syntax can be used for reloading the configuration:
Apart from syntaxes, one must also be wary about the configuration, when changed. For example, in case the number of hugepages is changed then the corresponding locked memory needs to be changed as well. Also, once the changes to the configuration is done, it is very important to restart the application so as to make the effects to the configuration take place.
How does HugePages Work in Linux?
Now, it is time for our understanding of the working of hugepages in Linux. In modern day architecture, multiple page size support is provided, for example, x86 CPUs have capability of supporting 4K and 2M page sizes (if architectural support is present, 1G of page size is also supported) and ia64 supports 4K, 8K, 64K, 256K and so on. There are many such examples. Hugepages have something known as translation lookaside buffer (abbreviated as TLB) which facilitates caching of virtual to physical translations. With bigger and bigger physical memory now getting available, the optimization of the scarce TLB resource in supporting hugepages are getting more and more critical.
Now that we have a fair idea of the importance, it is very important to know some common parameters, so as to make the flow of information in subsequent paragraph seamless. HugePages_Total is one such parameter which mentions the size of the pool of huge pages. HugePages_Free denotes the number of the hugepages from the pool which is not allocated yet. HugePages_Rsvd denotes the reserved number of huge pages, but these pages are not yet allocated and just “reserved”. HugePages_Surp is the “surplus” pages which is a number above and beyond the current hugepages the system needs currently.
Now the reserved hugepages return to the pool of hugepages when freed up by a task and also reserved hugepages memory inside kernel can’t be used for any other purposes along with incapability of swapping out under memory pressure. Now the pre-allocation of the hugepages is done to the kernel and once the allocation is complete a user with privilege as appropriate can use either map system call or calls from a shared memory system for using huge pages. Persistent hugepages can be allocated on the kernel boot line command by administrator when one changes the nr_hugepages parameter. This allocation can be freeing up hugepages as well, if required.
Now, once the pre-allocation is done, the kernel will attempt distribution of the hugepage pool over the set of allowed nodes. These nodes are specified by the NUMA memory policy. Any allowed node with insufficient continuous memory will be silently skipped when persistent hugepages are allocated. In case of unavailable continuous memory while the allocation of the huge pages may result into success or failure of huge page allocation. Hence in the following way, the allocation or freeing up of space is done in Linux hugepages.
One important thing to be kept as a warning or a pinch of note is in case the administrator shrink the hugepages via nr_hugepages to a number which is less than the number of huge pages in currently in use will convert the balance of the in-use huge pages to surplus hugepages till a point where it equals to the sum of nr_hugepages and overcommit hugepages. Once it crosses that, no more surplus hugepages will be allocated.
Examples of Linux HugePages
In this section, we will go through all the options we have talked about earlier through a particular example.
grep Huge /proc/meminfo
Explanation: Using the grep command, we get all the details corresponding to hugepages, where all the properties like, total hugepages, free hugepages, etc. are zero, and incase a hugepage is allocated some size, it will have 2048 kB by default.
Enter the command:
Inside the conf file:
Close the earlier file and then enter the command:
Inside the conf file:
soft memlock 262144
hard memlock 262144
Once all changes are done then run the command:
Explanation: This is to increase the hugepages from any number to our required number 128. Now, as we discussed earlier, the memory limit should also be increased or decreased as deemed fit in the limits.conf file.
In this article, we have discussed the usage of hugepages in today’s architecture and how it is becoming increasingly important to have a confident knowledge about these so as to explore the power of hugepages in one’s everyday work. With ever increasing database size having knowledge about the hugepages is a boon in disguise.
This is a guide to Linux HugePages. Here we discuss the definition and how does hugepages work in linux? along with different examples and its code implementation. You may also have a look at the following articles to learn more –