Huge pages

Also known as: large pages

On this page 6

Huge pages, also called large pages, are virtual memory pages that are much larger than the default page size, typically 2 MiB or 1 GiB on x86-64 instead of the standard 4 KiB. In memory management, they let one page table entry map a large contiguous block of physical memory, which reduces translation lookaside buffer (TLB) misses and shrinks page tables for workloads that touch many gigabytes of data.

Huge pages are a performance feature of operating systems and processors working together. The memory management unit must support the larger page sizes, and the kernel must find physically contiguous, aligned memory to back them. The benefit is faster address translation; the cost is coarser allocation granularity and harder memory management.

How huge pages speed up address translation

Huge pages work by mapping more memory per TLB entry. Every memory access needs a translation from a virtual address to a physical address. The TLB caches recent translations, but it holds only a limited number of entries, often between a few dozen and a few thousand.

With 4 KiB pages, a TLB of 1,536 entries covers only about 6 MiB of memory, a measure called TLB reach. A process scanning a 64 GiB database buffer therefore misses the TLB constantly, and each miss triggers a multi-level page walk through four or five page table levels. With 2 MiB pages, the same number of entries covers about 3 GiB, and the page walk is one level shorter.

The table below compares the standard page sizes on x86-64 and their effect on translation.

Page sizePage table levelReach of 1,536 TLB entriesTypical use
4 KiBPage table entry (PTE)About 6 MiBGeneral-purpose memory
2 MiBPage directory entry (PMD)About 3 GiBDatabases, JVM heaps, VMs
1 GiBPage directory pointer entry (PUD)About 1.5 TiBVery large static buffers
Page sizes on x86-64

Other architectures offer different sizes. ARM64 supports 64 KiB, 2 MiB, 32 MiB and 512 MiB pages depending on the base granule, and POWER systems commonly use 16 MiB pages.

Explicit huge pages and transparent huge pages

Operating systems provide huge pages through two main models: explicit reservation, where an administrator sets aside a pool in advance, and transparent allocation, where the kernel promotes ordinary memory to huge pages automatically. On Linux, these are hugetlbfs and Transparent Huge Pages (THP); Windows calls the feature large pages.

MechanismPlatformHow memory is obtainedSwappable
hugetlbfs poolLinuxReserved via vm.nr_hugepages at boot or runtimeNo
Transparent Huge PagesLinuxKernel allocates or collapses on demandYes, after splitting
Large pagesWindowsVirtualAlloc with MEM_LARGE_PAGESNo
SuperpagesFreeBSD and macOSAutomatic promotion of reservationsYes, after demotion
Huge page mechanisms by platform

Explicit pools give predictable, guaranteed huge pages but waste memory if the application does not use them. Transparent mechanisms need no application changes but depend on the kernel finding contiguous free memory at the right moment, and the khugepaged daemon on Linux spends CPU time collapsing small pages into huge ones in the background. On Windows, a process also needs the Lock pages in memory privilege.

When huge pages help and when they hurt

Huge pages help most when a workload has a large, densely used working set and spends measurable time on TLB misses. Gains of a few percent to over 20 percent are reported for such workloads, but the effect depends on access patterns and must be measured rather than assumed.

WorkloadRecommendationReason
Large relational database bufferExplicit huge pagesStable size, heavy random access
Virtual machine guest memoryHuge pages on the hostFewer nested page walks
JVM with a large heapEnable large pages optionDense access across the heap
Key-value store with fork snapshotsDisable THPCopy-on-write copies 2 MiB per write
Many small short-lived processesDefault 4 KiB pagesLittle TLB pressure, more waste
Decision guide for huge pages

Some database vendors explicitly recommend disabling transparent huge pages because THP compaction can cause latency spikes and memory bloat, while still recommending explicit huge pages for their shared buffers. The distinction between the two mechanisms is therefore essential when reading tuning advice.

Costs, risks and common mistakes

The main drawbacks of huge pages come from their size and contiguity requirements. A process that touches one byte of a 2 MiB page still consumes the whole page, so sparse access causes internal fragmentation and a higher resident set size. Over time, external memory fragmentation makes contiguous 2 MiB blocks scarce, forcing the kernel to run compaction.

  • Reserving too large a pool leaves memory unusable for other processes and can trigger out-of-memory conditions.
  • Copy-on-write after fork duplicates an entire huge page on the first write, which can multiply memory use.
  • Assuming THP is active without checking its mode, which may be always, madvise or never.
  • Ignoring NUMA placement, because a huge page lives on one node and remote access stays slow.

Diagnosis usually starts with TLB miss counters from hardware performance tools and the kernel’s huge page statistics, which show whether pages were actually allocated and how often allocation failed.

A careful rollout compares throughput and tail latency before and after the change under a realistic load. Because the benefit depends on access patterns, a setting that speeds up one database can slow down another, so each workload deserves its own measurement rather than a fleet-wide default.

Put simply

A computer finds data in memory with the help of a small address notebook. Each line in the notebook points to one block of memory. Normal blocks are tiny, so a big program needs far more lines than the notebook can hold.

Huge pages make each block much bigger. One line now covers a large area of memory. The computer looks things up less often and works faster. The catch is that big blocks can waste space when a program uses only a small part of them.

In practice

A database administrator runs a server with 256 GiB of RAM and a 96 GiB shared buffer pool. Profiling shows that a noticeable share of CPU cycles goes to page walks. The administrator reserves 49,152 huge pages of 2 MiB at boot, enough for the buffer pool plus a small margin, and configures the database to use them.

The same administrator sets transparent huge pages to madvise so that unrelated processes do not trigger background compaction. After the change, page table memory for the database drops from several hundred megabytes to a few megabytes, TLB misses fall sharply and query throughput rises by roughly ten percent in that workload. The administrator documents the reserved pool so that it is resized whenever the buffer size changes.