Updated on 2026-04-01 GMT+08:00

THP and Memory Bloat

Normally, the size of a Linux memory page is 4 KB. After THP is enabled, the kernel tries to combine 4 KB pages into 2 MB huge pages to reduce TLB misses and improve performance. Enabling THP for small objects may cause memory bloat (internal fragmentation) and increase the risk of OOM errors.

Causes of THP Memory Bloat

  1. Internal fragmentation
    • Although only a small part of a 2 MB huge page is used by a process, the remaining space is also occupied by the process and cannot be used by other processes.
      • Common small page: 8 KB of space is requested and two 4 KB pages are allocated and used. There is no waste.
      • THP: 8 KB of space is requested. The kernel allocates a 2 MB huge page. Only 8 KB is used actually but the remaining space is also considered used.
  2. Large allocation granularity
    • If THP is enabled, memory is allocated in the units of 2 MB, which easily causes high memory usage.
  3. Slow memory reclamation
    • THP reclamation and migration are more complex than those of 4 KB pages. As a result, memory cannot be reclaimed in a timely manner, and the memory usage keeps increasing.

The bloated memory usage is not reflected in the top command's per-process statistics.