Re: [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room
From: Huang, Ying
Date: Tue Dec 01 2026 - 08:45:23 EST
Hi, Joshua,
Joshua Hahn <joshua.hahnjy@xxxxxxxxx> writes:
> When a memcg hits a memory limit, reclaim demotes folios from toptier
> nodes and only swaps out the ones it fails to demote. Demoted folios
> stay charged, so it does not bring the memcg closer to the limit.
> It still counts towards reclaim progress though:
> - try_to_free_mem_cgroup_pages(): If demotion can satisfy the nr_pages,
> pages are not swapped out.
> - try_charge_memcg(): Demoted pages count towards progress, so retries
> are not used up.
>
> When toptier nodes have room, this is the undercommit case that commit
> 3f1509c57b1b ("Revert "mm/vmscan: never demote for memcg reclaim"")
> describes at the end. A memcg at its limit keeps demoting its own memory
> to the lower tier with no bound, as long as demotion target nodes have
> capacity to take the demotions. This leads to memcg-limit bound
> workloads on otherwise empty machines to run mostly out of the lower
> tier. If NUMA balancing tiering mode is on, the demotions constantly
> churn against promotion that then brings those pages back to DRAM.
>
> This has been observed in Meta production workloads, where we see
> pgdemote_direct taking up about 80% of pgsteal_direct, and CXL bandwidth
> continuously being hammered while DRAM still has 60% of its memory free.
>
> In can_demote(), for non-proactive cgroup reclaim, don't demote from a
> node that pgdat_free_space_enough() considers to have enough room, as
> long as memcg can swap. This is the same check that promotion makes
> to determine when the toptier is full.
>
> This still leaves 3 participants in the cross-node aging process:
> proactive reclaim, kswapd / global direct reclaim, and memcgs that
> cannot swap out.
>
> Signed-off-by: Joshua Hahn <joshua.hahnjy@xxxxxxxxx>
> ---
> mm/memory-tiers.c | 3 +++
> mm/vmscan.c | 5 +++++
> 2 files changed, 8 insertions(+)
>
> diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
> index caf28ca662f75..57a25cbd7741f 100644
> --- a/mm/memory-tiers.c
> +++ b/mm/memory-tiers.c
> @@ -305,6 +305,9 @@ bool node_is_toptier(int node)
> * advantage of fast memory capacity, all recently accessed slow
> * memory pages will be migrated to fast memory node without
> * considering hot threshold.
> + *
> + * Memcg limit reclaim does not demote from such a node either; see
> + * can_demote().
> */
> bool pgdat_free_space_enough(pg_data_t *pgdat)
> {
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index bc7579d47f9b4..cfd40771b4bf3 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -250,6 +250,11 @@ static bool can_demote(int nid, struct scan_control *sc,
> if (nodes_empty(allowed_mask))
> return false;
>
> + if (sc && cgroup_reclaim(sc) && !sc->proactive && memcg &&
> + mem_cgroup_get_nr_swap_pages(memcg) > 0 &&
> + pgdat_free_space_enough(pgdat))
pgdat_free_space_enough() is much larger than WMARK_PROMO. Is it better
to use a watermark that is closer to it?
> + return false;
> +
> /* Filter out nodes that are not in cgroup's mems_allowed. */
> mem_cgroup_node_filter_allowed(memcg, &allowed_mask);
> return !nodes_empty(allowed_mask);
---
Best Regards,
Huang, Ying