Calculate the number of HugePages needed to back a given amount of application memory.
HugePages reduce Translation Lookaside Buffer (TLB) misses for memory-intensive applications like databases by using much larger page sizes (2MB or 1GB) instead of the standard 4KB page. The number of huge pages required is the required memory divided by the huge page size, rounded up, since HugePages must be allocated in whole units. Any excess from rounding is memory reserved but unused by the target application.
Huge pages required
nr_hugepages = ceil(required_memory_MB / hugepage_size_MB)
Larger pages mean fewer page table entries are needed to map the same amount of memory, which reduces TLB misses and page table walk overhead — a meaningful performance gain for applications with large, actively-used memory regions like database shared buffers.
2MB pages are the standard HugeTLB size supported on virtually all x86_64 systems and can be allocated dynamically at runtime. 1GB 'gigantic' pages need CPU and kernel support, are typically reserved at boot time via a kernel parameter, and are used for very large, static memory regions.
No — memory reserved for HugePages is removed from the normal page allocator and can only be used by applications explicitly requesting huge pages, so over-allocating wastes RAM that regular processes could have used.