Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] mm: memcg: settle memory.high debt for non-blocking THP charges
@ 2026-09-04  3:54 Qinyun Tan
  2026-09-04  3:54 ` [PATCH 1/2] mm: memcg: settle memory.high debt after THP faults with non-blocking gfp Qinyun Tan
  2026-09-04  3:54 ` [PATCH 2/2] mm: memcg: settle memory.high debt after large folio swapin Qinyun Tan
  0 siblings, 2 replies; 6+ messages in thread
From: Qinyun Tan @ 2026-09-04  3:54 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Johannes Weiner, Michal Hocko, Roman Gushchin, Shakeel Butt,
	Muchun Song, David Hildenbrand, Lorenzo Stoakes, Zi Yan,
	Baolin Wang, Xunlei Pang, Liam R . Howlett, Nico Pache,
	Ryan Roberts, Dev Jain, Barry Song, Lance Yang, Usama Arif,
	Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Chris Down,
	Chuanhua Han, Kairui Song, linux-mm, cgroups, linux-kernel,
	Qinyun Tan

memory.high is enforced at two points after a charge succeeds: on
return to userspace, and synchronously in try_charge_memcg() for
large overcharges, the latter gated on gfpflags_allow_blocking().

THP charge paths pass the physical allocation gfp from
vma_thp_gfp_mask() to the memcg charge.  With the default
defrag=madvise (and no MADV_HUGEPAGE), as well as with defrag=defer,
that gfp does not allow blocking.  This is the right allocation
policy -- a THP is not worth direct compaction, fall back to smaller
orders instead -- but the charge code also reads it as "this context
cannot sleep" and skips the synchronous enforcement, even though
fault context sleeps just fine.  Inside a single-syscall populate
loop (mlock(), MADV_POPULATE_*, any GUP-driven population) the
return-to-userspace hook is not reached between faults either, so
nothing throttles at all: a memcg's usage runs from memory.high
straight up to memory.max with zero reclaim and zero penalty sleep,
consuming the reaction window that userspace OOM handlers (oomd,
Kubernetes) depend on.

Patch 1 fixes the anonymous THP/mTHP fault path.  The pre-existing
selftest test_memcg_high_sync readily reproduces the problem: with
transparent_hugepage/enabled=always it fails without the patch and
passes with it.

Patch 2 fixes the same problem for large folio swapin on
SWP_SYNCHRONOUS_IO devices (zram) with mTHP swapin enabled.  Its
changelog carries measured before/after numbers for both the
reclaim-keeps-up regime and the penalty-sleep regime.

In both patches the charge gfp deliberately stays coupled to the
allocation gfp, so the fail-fast fallback at memory.max is fully
preserved; the over-high debt is instead settled from the fault
path, which knows its context can sleep.

A note for stable backports: mem_cgroup_handle_over_high() only
gained its gfp_mask argument in v6.6, from commit 9ea9cb00a82b ("mm:
memcontrol: fix GFP_NOFS recursion in memory.high enforcement");
older kernels take no argument.  On kernels predating the swap table
rework the swapin charge sits in alloc_swap_folio() rather than
__swap_cache_alloc(), but patch 2's fix location at the end of
do_swap_page() applies unchanged.

Qinyun Tan (2):
  mm: memcg: settle memory.high debt after THP faults with
    non-blocking gfp
  mm: memcg: settle memory.high debt after large folio swapin

 mm/huge_memory.c |  8 ++++++++
 mm/memory.c      | 10 ++++++++++
 2 files changed, 18 insertions(+)

--
2.55.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-04 15:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04  3:54 [PATCH 0/2] mm: memcg: settle memory.high debt for non-blocking THP charges Qinyun Tan
2026-09-04  3:54 ` [PATCH 1/2] mm: memcg: settle memory.high debt after THP faults with non-blocking gfp Qinyun Tan
2026-09-04  6:50   ` Baolin Wang
2026-09-04  9:05     ` Qinyun Tan
2026-09-04 15:10   ` Zi Yan
2026-09-04  3:54 ` [PATCH 2/2] mm: memcg: settle memory.high debt after large folio swapin Qinyun Tan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox