Skip to content

RFC mm/hugetlb: Dynamic, NUMA-aware HugePage Cache & Free Page Reporting

Sourav Panda linux-doc linux-fsdevel linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest6 patches 16 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6mm/hugetlb: add Kconfig and basic cache infrastructurefs/Kconfig include/linux/hugetlb.h mm/hugetlb.c+98 -70 replies
2/6mm/hugetlb: implement cache recycling and allocationinclude/linux/hugetlb.h mm/hugetlb.c+77 -30 replies
3/6mm/hugetlb: add sysfs interfaces for cachemm/hugetlb.c mm/hugetlb_internal.h mm/hugetlb_sysfs.c+390 -00 replies
4/6mm/hugetlb: add memory shrinker for cachemm/hugetlb.c+77 -00 replies
5/6Documentation/admin-guide/mm/hugetlbpage.rst: document cache interfacesDocumentation/admin-guide/mm/hugetlbpage.rst+29 -20 replies
6/6mm/hugetlb: support free page reporting for cached hugepagesinclude/linux/hugetlb.h include/linux/page_reporting.h mm/hugetlb.c +2 more+163 -62 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/6] mm/hugetlb: Dynamic, NUMA-aware HugePage Cache & Free Page Reporting

Overview
This patch series introduces a dynamic, NUMA-aware HugePage Cache, backed by a kernel shrinker to safely return memory under pressure, and integrates it with Free Page Reporting (virtio-balloon) for HugeTLB, specifically targeting gigantic (1GB) hugepages. The goal is to solve the tradeoff between allocation latency and memory fungibility in virtualized and heterogeneous cloud environments.

---

The Core Problem: Allocation Latency vs. Memory Fungibility

With highly heterogeneous workloads, latency-critical applications demand gigantic hugepages. However, dynamic runtime allocation of 1GB pages from the buddy allocator (via CMA) is slow.

To bypass this latency, operators often pre-allocate hugepages statically. However, this locks up the memory: when the HugeTLB workloads are idle, that memory is completely unavailable for other buddy-allocator workloads (e.g., page cache, anonymous memory). If buddy memory is exhausted, the system will OOM even if gigabytes of HugeTLB pages are sitting idle.

This series resolves this challenge by delivering Dynamic Fungibility:

1. Dynamic Caching: Intercepts freed surplus hugepages and recycles them into a NUMA-aware cache instead of dissolving them immediately.
2. Fast Allocations: Satisfies subsequent dynamic allocations instantly from this warm, local hugepage cache.
3. Kernel Shrinker Integration: Registers a NUMA-aware kernel shrinker to dynamically dissolve cached pages back to the buddy allocator under memory pressure, restoring host/guest memory fungibility.
4. Free Page Reporting Integration: For virtualized environments (Guest VMs), cached pages trigger background Free Page Reporting via virtio-balloon. This allows the host to reclaim the physical memory while the guest retains its Vmemmap Optimization (HVO) metadata savings (~14GB saved per 1TB VM)!

  +---------------+   Slow Allocate  +---------------------+
  | Buddy         | ---------------> | Active HugeTLB Page |
  | Allocator     |                  +---------------------+
  +---------------+                    |                ^
    ^                                  | (1) Free to    | (2) Fast
    | (3) Under                        v     Cache      |     Allocate
    | Pressure                       +---------------------+
    | Shrink()  <------------------- | HugeTLB Cache       |
                                     +---------------------+
                                       |

v (4) Free Page Reporting
(Host Reclaim in the case
of virtualization)

---

Patch Series Structure

Patch 1/6: mm/hugetlb: add Kconfig and basic cache infrastructure
- Introduces the CONFIG_HUGETLB_CACHE option, hstate tracking fields, and the HPG_cached page flag.
- Establishes the clean helper API (hugetlb_folio_is_cached(), hugetlb_cache_remove(), hugetlb_cache_add()) and updates remove_hugetlb_folio() to be cache-aware, eliminating inline #ifdef blocks.
Patch 2/6: mm/hugetlb: implement cache recycling and allocation
- Hooks up recycling in free_huge_folio() (up to the cache limit) and allocation in alloc_surplus_hugetlb_folio().
- Implements MRU allocation policy for maximum warmth, poison safety checks, and MTE/dcache cleaning.
Patch 3/6: mm/hugetlb: add sysfs interfaces for cache
- Exposes global and per-node sysfs attributes (max_cached_huge_pages, nr_cached_hugepages) for dynamic userspace control, including NUMA memory policy scaling.
- Supports dynamic delta adjustments (+1/-1) to safely scale cache sizes alongside concurrent background reclaim operations.
Patch 4/6: mm/hugetlb: add memory shrinker for cache
- Registers a NUMA-aware kernel shrinker to evict and dissolve cached gigantic pages back to buddy under memory pressure.
Patch 5/6: Documentation/admin-guide/mm/hugetlbpage.rst: document cache
interfaces
- Documents the Kconfig option, sysfs attributes, and shrinker behavior in the admin guide.
Patch 6/6: mm/hugetlb: support free page reporting for cached hugepages
- Integrates the cache with the Free Page Reporting framework (virtio- balloon), introducing the HPG_reported flag and the reporting/isolation/draining lifecycle.
Sourav Panda (6):
mm/hugetlb: add Kconfig and basic cache infrastructure mm/hugetlb: implement cache recycling and allocation mm/hugetlb: add sysfs interfaces for cache
mm/hugetlb: add memory shrinker for cache Documentation/admin-guide/mm/hugetlbpage.rst: document cache
interfaces
mm/hugetlb: support free page reporting for cached hugepages

 Documentation/admin-guide/mm/hugetlbpage.rst |  34 +-
 fs/Kconfig                                   |   9 +
 include/linux/hugetlb.h                      |  45 ++
 include/linux/page_reporting.h               |   1 +
 mm/hugetlb.c                                 | 590 ++++++++++++++++++-
 mm/hugetlb_internal.h                        |   9 +
 mm/hugetlb_sysfs.c                           | 158 +++++
 mm/page_reporting.c                          |  10 +-
 mm/page_reporting.h                          |   6 +
 9 files changed, 844 insertions(+), 18 deletions(-)
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog