.. /index

Huge Pages

Huge Pages

Huge pages are 2 MB or 1 GB virtual memory mappings backed by a single TLB entry, replacing the standard 4 KB page that Linux uses by default. For inter-thread communication and database workloads, huge pages eliminate TLB misses across hot data. A single 2 MB huge page covers 32× more address space than a standard 4 KB page; a 1 GB huge page covers 16,384× more. For a multi-megabyte ring buffer or a multi-gigabyte hash table, the TLB hit rate goes from ~50% to ~100%, removing one of the largest hidden costs in cache-friendly algorithms.

Why TLB misses matter

The TLB (Translation Lookaside Buffer) caches virtual-to-physical address translations. A modern x86 CPU has roughly:

A TLB miss costs 10–100 cycles for a page-table walk. For a workload that touches more memory than the TLB can cover, every access can pay this cost — even when the data itself is in L1 cache. This is the silent killer of "cache-friendly" data structures: the data fits, but the page tables don't.

A 2 MB huge page replaces 512 standard pages with a single TLB entry, raising TLB-covered memory by 32×. A 1 GB huge page replaces 524,288 standard pages, covering an entire working set in one entry.

Configuration on Linux

Two mechanisms exist:

Transparent Huge Pages (THP) — the kernel automatically promotes contiguous 4 KB pages to 2 MB huge pages when possible.

echo always > /sys/kernel/mm/transparent_hugepage/enabled

THP is convenient but has costs: page promotion is asynchronous and can cause latency spikes when khugepaged runs, and fragmentation reduces the success rate over time. Many database vendors (parlayhash / swiss-table heavy workloads, MongoDB, Redis) recommend disabling THP and using explicit huge pages instead.

Explicit huge pages — reserved at boot or runtime and allocated via mmap with MAP_HUGETLB:

# Boot args for 1 GB pages (must be at boot, can't be allocated later)
default_hugepagesz=1G hugepagesz=1G hugepages=8

# 2 MB pages can be reserved at runtime
echo 1024 > /proc/sys/vm/nr_hugepages
void *buf = mmap(NULL, 2 * 1024 * 1024,
                 PROT_READ | PROT_WRITE,
                 MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
                 -1, 0);

For 1 GB huge pages specifically, allocation must happen at kernel boot — physical fragmentation makes it unlikely to succeed at runtime on a long-running system.

Where huge pages matter most

Where huge pages are neutral or harmful

Allocator integration

Some allocators integrate huge-page support directly:

Switching to a huge-page-aware allocator gives the benefit without source changes, which is a significant ergonomic win compared to manual mmap(MAP_HUGETLB).

HFT impact

In the HFT optimization stack, huge pages contribute meaningfully to P99.9 tail latency:

The effect on median latency is small (a few ns); the effect on tail latency is large (microseconds removed from outliers).

See also

Linked from

Sources