Skip to content

mm: split underused anonymous mTHP folios

Joanne Koong linux-mm sashiko-reviews 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 16 repliesIn review
  2. v33 patches 5 repliesSuperseded
  3. v23 patches 18 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches31 repliesSuperseded

Changes in v4 from the cover letter

* Scale khugepaged/max_ptes_none with truncating division instead of rounding up, which is exact given the strict > comparison (Sashiko, Lance)
* New patch 3: keep thp_underused_split_page PMD-only and add a per-order split_underused counter (Kiryl)
* Fix typo in patch 4's commit message (Kiryl)

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4mm/huge_memory: scale thp_underused() to the folio sizemm/huge_memory.c+14 -64 replies
2/4mm/huge_memory: don't queue folios when underused splitting is inactivemm/huge_memory.c+21 -33 replies
3/4mm/huge_memory: add a per-order counter for underused splitsDocumentation/admin-guide/mm/transhuge.rst include/linux/huge_mm.h mm/huge_memory.c+15 -24 replies
4/4mm: add anonymous mTHP folios to the deferred split listmm/huge_memory.c mm/memory.c+16 -05 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchUsama ArifBarry SongKiryl Shutsemau (Meta)Zi YanBaolin Wang
1/4R-b A-b R-b
2/4A-b R-b R-b
3/4A-b R-b R-b
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/4] mm: split underused anonymous mTHP folios

PMD-sized THPs that are mostly zero-filled are reclaimed under memory pressure by the deferred split shrinker, but this is not done for mTHP folios. At Meta we would like to deploy 2M THP=always on arm64 with 64k base pages, as 2M provides the contpte benefits while the PMD size there (512M) is too big to use. However, 2M THP=always causes memory regressions unless the unused portions of those folios can be broken down and reclaimed.

This series lets the underused shrinker handle anonymous mTHP folios. It has four patches:

Patch 1 makes thp_underused() folio-size-aware. It scales khugepaged/max_ptes_none to the folio size, so every folio tolerates the same fraction of zero-filled pages.

Patch 2 stops queueing folios for underused splitting when khugepaged/max_ptes_none is at its default maximum, where the shrinker would never split them anyway. This applies to PMD-sized folios too, which are unconditionally queued today.

Patch 3 keeps thp_underused_split_page counting only PMD-sized folios and adds a per-order split_underused counter, matching how thp_split_page and thp_deferred_split_page are handled.

Patch 4 queues anonymous mTHP folios on the deferred split list, with a hard-coded 2M minimum folio size as suggested by Barry. PMD-sized folios are exempt from the minimum, since on s390 the PMD size is 1M.

At the default khugepaged/max_ptes_none, no folio is queued for underused splitting. Once it's lowered, mTHP folios of at least 2M are queued along with PMD-sized folios.

Changelog
---------
v3: https://lore.kernel.org/linux-mm/[email protected]/
Changes since v3:
* Scale khugepaged/max_ptes_none with truncating division instead of rounding up, which is exact given the strict > comparison (Sashiko, Lance)
* New patch 3: keep thp_underused_split_page PMD-only and add a per-order split_underused counter (Kiryl)
* Fix typo in patch 4's commit message (Kiryl)

v2: https://lore.kernel.org/linux-mm/[email protected]/
Changes since v2:
* Go back to scaling khugepaged/max_ptes_none per folio size (David)
* Keep the check for the sysctl maximum on the raw, unscaled value (Sashiko, from v1). Round the scaled value up so a folio is never split when fewer than the configured fraction of its pages are zero-filled.
* Only queue mTHP folios of at least 2M, a hard-coded minimum (Barry, David)

v1: https://lore.kernel.org/linux-mm/[email protected]/
Changes since v1:
* Drop the per-order scaling of khugepaged_max_ptes_none. Keep it absolute, matching collapse (David, Johannes)
* New patch 2 (suggested by Johannes): don't queue folios that can never be underused, which both bounds what patch 3 adds and stops queuing PMD folios under default settings (Johannes, David, Barry)
* Fix the thp_underused() early exit to scale to the folio's own size

Joanne Koong (4):
mm/huge_memory: scale thp_underused() to the folio size mm/huge_memory: don't queue folios when underused splitting is
inactive
mm/huge_memory: add a per-order counter for underused splits
mm: add anonymous mTHP folios to the deferred split list

 Documentation/admin-guide/mm/transhuge.rst |  6 ++
 include/linux/huge_mm.h                    |  1 +
 mm/huge_memory.c                           | 66 ++++++++++++++++++----
 mm/memory.c                                |  2 +
 4 files changed, 65 insertions(+), 10 deletions(-)

base-commit: 74d73ffcffe03804f97e9fb82301dadf75671282

Signature · 1 line
2.52.0