huge page

A memory page larger than the architecture's base size (2 MB or 1 GB on x86_64 vs 4 KB baseline) that lets a single TLB entry cover more memory, reducing page-table walks for large working sets.

also known as hugepage · hugepages · THP · transparent-huge-pages

stack memory · kernel

A huge page is a memory page larger than the architecture’s base page size. On x86_64, the base is 4 KB; huge pages are 2 MB or 1 GB. A single TLB entry covers a whole huge page, so a workload with a large working set pays far fewer page-table walks than it would with 4 KB pages. For in-memory databases, JVM heaps, and ML inference with large tensors, this is measurable.

Linux offers three modes for enabling huge pages:

  1. Explicit hugetlbfs — reserved at boot, opted into via mmap flags. No fragmentation risk but inflexible.
  2. Transparent Huge Pages (THP) — always — the kernel tries to back every mapping with huge pages. Can hurt latency-sensitive workloads due to compaction stalls.
  3. THP — madvise — the kernel allocates huge pages only where the application calls madvise(MADV_HUGEPAGE). The modern recommended default.

Recent kernels added mTHP (multi-size THP) with intermediate sizes (16K–1M), giving the kernel flexibility to huge-page fragmented memory. Phoronix’s Linux 6.18 LTS benchmarks showed ~20% Memcached ops/sec improvement from mTHP — but also that large-folio allocation success drops precipitously under fragmentation (>90% failure after ~2 hours of sustained fragmentation pressure).

The nuance: huge pages help until they don’t. Compaction stalls, CoW cost per 2 MB page, and allocation-failure cliffs are real.

sources