* [RFC PATCH 0/2] Prevent demotions in memcg limit reclaim when toptier has room @ 2026-11-30 21:52 Joshua Hahn 2026-11-30 21:52 ` [RFC PATCH 1/2] mm/memory-tiers: move pgdat_free_space_enough() out of the scheduler Joshua Hahn 2026-11-30 21:52 ` [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room Joshua Hahn 0 siblings, 2 replies; 6+ messages in thread From: Joshua Hahn @ 2026-11-30 21:52 UTC (permalink / raw) To: Johannes Weiner Cc: Dave Hansen, Andrew Morton, Michal Hocko, Shakeel Butt, Qi Zheng, David Hildenbrand, Gregory Price, Zi Yan, Rakie Kim, Ying Huang, Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, linux-mm, linux-kernel, kernel-team On tiered systems, cgroups above their memory limit can still demote and count it towards reclaim progress, despite not shrinking the cgroup's memory usage. This is so that limit reclaim participates in the cross-tier aging pipeline, as explained in 3f1509c57b1b (Revert "mm/vmscan: never demote for memcg reclaim"). The revert notes that in the undercommit case where the sum of cgroup limits <= toptier memory, "shuffling pages out to lower tiers first to reclaim them from there is inefficient". In Meta production, we have seen this on undercommitted hosts and hosts where memcg limits add up to more than DRAM, but bursty usage keeps host memory well below DRAM capacity for long periods. Caching workloads on these hosts saw pgdemote_direct taking up about 80% of pgsteal_direct, so only 1 in 5 reclaimed pages actually lowered the memcg's usage. NUMA balancing kept promoting the hot demoted pages back, and this led the CXL bandwidth to be completely saturated. When there is free space in DRAM, prevent demotions from cgroup limit reclaim. The cross-node LRU aging pipeline is still kept moving forward through proactive reclaim, kswapd, and direct reclaim when the system is also pressured. Running the same caching workload mentioned above on a pool of 50 hosts, throughput increased by about 27%. Joshua Hahn (2): mm/memory-tiers: move pgdat_free_space_enough() out of the scheduler mm/vmscan: don't demote in memcg limit reclaim while the node has room include/linux/memory-tiers.h | 11 +++++++++++ kernel/sched/fair.c | 28 ---------------------------- mm/memory-tiers.c | 31 +++++++++++++++++++++++++++++++ mm/vmscan.c | 5 +++++ 4 files changed, 47 insertions(+), 28 deletions(-) base-commit: 9f004372ebeb18fdeb699f9880a0e472df90135b -- 2.53.1-Meta ^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC PATCH 1/2] mm/memory-tiers: move pgdat_free_space_enough() out of the scheduler 2026-11-30 21:52 [RFC PATCH 0/2] Prevent demotions in memcg limit reclaim when toptier has room Joshua Hahn @ 2026-11-30 21:52 ` Joshua Hahn 2026-11-30 21:52 ` [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room Joshua Hahn 1 sibling, 0 replies; 6+ messages in thread From: Joshua Hahn @ 2026-11-30 21:52 UTC (permalink / raw) To: Johannes Weiner Cc: Dave Hansen, Andrew Morton, Michal Hocko, Shakeel Butt, Qi Zheng, David Hildenbrand, Gregory Price, Zi Yan, Rakie Kim, Ying Huang, Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, linux-mm, linux-kernel, kernel-team pgdat_free_space_enough() decides when a top tier node has enough free memory that NUMA balancing promotes slow memory pages without applying the hot threshold. It is a memory tiering policy, but it lives in kernel/sched/fair.c as a static helper, so mm cannot use it. Move it to mm/memory-tiers.c and declare it in <linux/memory-tiers.h>, next to node_is_toptier(), with a stub that returns false when !CONFIG_NUMA_MIGRATION. NUMA balancing depends on CONFIG_NUMA_MIGRATION, so its caller always gets the real function. The next patch uses it in reclaim, so that memcg limit reclaim and promotion share one definition of a top tier node with room. No functional changes intended. Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com> --- include/linux/memory-tiers.h | 11 +++++++++++ kernel/sched/fair.c | 28 ---------------------------- mm/memory-tiers.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 7999c58629eeb..e32a02f85f517 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -56,6 +56,7 @@ void mt_put_memory_types(struct list_head *memory_types); int next_demotion_node(int node, const nodemask_t *allowed_mask); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); bool node_is_toptier(int node); +bool pgdat_free_space_enough(pg_data_t *pgdat); #else static inline int next_demotion_node(int node, const nodemask_t *allowed_mask) { @@ -71,6 +72,11 @@ static inline bool node_is_toptier(int node) { return true; } + +static inline bool pgdat_free_space_enough(pg_data_t *pgdat) +{ + return false; +} #endif #else @@ -116,6 +122,11 @@ static inline bool node_is_toptier(int node) return true; } +static inline bool pgdat_free_space_enough(pg_data_t *pgdat) +{ + return false; +} + static inline int register_mt_adistance_algorithm(struct notifier_block *nb) { return 0; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 0c8af1cac2d5b..aadb815960558 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2764,34 +2764,6 @@ static inline bool cpupid_valid(int cpupid) return cpupid_to_cpu(cpupid) < nr_cpu_ids; } -/* - * For memory tiering mode, if there are enough free pages (more than - * enough watermark defined here) in fast memory node, to take full - * advantage of fast memory capacity, all recently accessed slow - * memory pages will be migrated to fast memory node without - * considering hot threshold. - */ -static bool pgdat_free_space_enough(struct pglist_data *pgdat) -{ - int z; - unsigned long enough_wmark; - - enough_wmark = max(1UL * 1024 * 1024 * 1024 >> PAGE_SHIFT, - pgdat->node_present_pages >> 4); - for (z = pgdat->nr_zones - 1; z >= 0; z--) { - struct zone *zone = pgdat->node_zones + z; - - if (!populated_zone(zone)) - continue; - - if (zone_watermark_ok(zone, 0, - promo_wmark_pages(zone) + enough_wmark, - ZONE_MOVABLE, 0)) - return true; - } - return false; -} - /* * For memory tiering mode, when page tables are scanned, the scan * time will be recorded in struct page in addition to make page diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 7fc56a8c66518..caf28ca662f75 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -299,6 +299,34 @@ bool node_is_toptier(int node) return toptier; } +/* + * For memory tiering mode, if there are enough free pages (more than + * enough watermark defined here) in fast memory node, to take full + * advantage of fast memory capacity, all recently accessed slow + * memory pages will be migrated to fast memory node without + * considering hot threshold. + */ +bool pgdat_free_space_enough(pg_data_t *pgdat) +{ + int z; + unsigned long enough_wmark; + + enough_wmark = max(1UL * 1024 * 1024 * 1024 >> PAGE_SHIFT, + pgdat->node_present_pages >> 4); + for (z = pgdat->nr_zones - 1; z >= 0; z--) { + struct zone *zone = pgdat->node_zones + z; + + if (!populated_zone(zone)) + continue; + + if (zone_watermark_ok(zone, 0, + promo_wmark_pages(zone) + enough_wmark, + ZONE_MOVABLE, 0)) + return true; + } + return false; +} + void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) { struct memory_tier *memtier; -- 2.53.1-Meta ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room 2026-11-30 21:52 [RFC PATCH 0/2] Prevent demotions in memcg limit reclaim when toptier has room Joshua Hahn 2026-11-30 21:52 ` [RFC PATCH 1/2] mm/memory-tiers: move pgdat_free_space_enough() out of the scheduler Joshua Hahn @ 2026-11-30 21:52 ` Joshua Hahn 2026-12-01 13:45 ` Huang, Ying 1 sibling, 1 reply; 6+ messages in thread From: Joshua Hahn @ 2026-11-30 21:52 UTC (permalink / raw) To: Johannes Weiner Cc: Dave Hansen, Andrew Morton, Michal Hocko, Shakeel Butt, Qi Zheng, David Hildenbrand, Gregory Price, Zi Yan, Rakie Kim, Ying Huang, Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, linux-mm, linux-kernel, kernel-team 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@gmail.com> --- 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)) + 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); -- 2.53.1-Meta ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room 2026-11-30 21:52 ` [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room Joshua Hahn @ 2026-12-01 13:45 ` Huang, Ying 2026-12-01 15:58 ` Joshua Hahn 0 siblings, 1 reply; 6+ messages in thread From: Huang, Ying @ 2026-12-01 13:45 UTC (permalink / raw) To: Joshua Hahn Cc: Johannes Weiner, Dave Hansen, Andrew Morton, Michal Hocko, Shakeel Butt, Qi Zheng, David Hildenbrand, Gregory Price, Zi Yan, Rakie Kim, Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, linux-mm, linux-kernel, kernel-team Hi, Joshua, Joshua Hahn <joshua.hahnjy@gmail.com> 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@gmail.com> > --- > 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room 2026-12-01 13:45 ` Huang, Ying @ 2026-12-01 15:58 ` Joshua Hahn 2026-12-02 2:16 ` Huang, Ying 0 siblings, 1 reply; 6+ messages in thread From: Joshua Hahn @ 2026-12-01 15:58 UTC (permalink / raw) To: Huang, Ying Cc: Johannes Weiner, Dave Hansen, Andrew Morton, Michal Hocko, Shakeel Butt, Qi Zheng, David Hildenbrand, Gregory Price, Zi Yan, Rakie Kim, Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, linux-mm, linux-kernel, kernel-team On Tue, Dec 01, 2026 at 09:45:13PM +0800, Huang, Ying wrote: > Hi, Joshua, > > Joshua Hahn <joshua.hahnjy@gmail.com> 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. [... snip ...] > > + if (sc && cgroup_reclaim(sc) && !sc->proactive && memcg && > > + mem_cgroup_get_nr_swap_pages(memcg) > 0 && > > + pgdat_free_space_enough(pgdat)) Hi Ying, I hope you have been doing well, thanks a lot for taking a look at the patch! > pgdat_free_space_enough() is much larger than WMARK_PROMO. Is it better > to use a watermark that is closer to it? Yeah, that's a good point. Thinking about it again, I guess space_enough is only the ratelimiting threshold, so it wouldn't make much heuristic sense here anyways. Maybe pgdat_balanced() is a better fit here? Then this check here will be in agreement with kswapd. Hopefully the rest of the commit makes sense to you. Thanks again, I hope you have a great day! Joshua > > + 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room 2026-12-01 15:58 ` Joshua Hahn @ 2026-12-02 2:16 ` Huang, Ying 0 siblings, 0 replies; 6+ messages in thread From: Huang, Ying @ 2026-12-02 2:16 UTC (permalink / raw) To: Johannes Weiner Cc: Dave Hansen, Andrew Morton, Michal Hocko, Shakeel Butt, Qi Zheng, David Hildenbrand, Gregory Price, Zi Yan, Rakie Kim, Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, linux-mm, linux-kernel, kernel-team Joshua Hahn <joshua.hahnjy@gmail.com> writes: > On Tue, Dec 01, 2026 at 09:45:13PM +0800, Huang, Ying wrote: >> Hi, Joshua, >> >> Joshua Hahn <joshua.hahnjy@gmail.com> 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. > > [... snip ...] > >> > + if (sc && cgroup_reclaim(sc) && !sc->proactive && memcg && >> > + mem_cgroup_get_nr_swap_pages(memcg) > 0 && >> > + pgdat_free_space_enough(pgdat)) > > Hi Ying, I hope you have been doing well, thanks a lot for taking a > look at the patch! > >> pgdat_free_space_enough() is much larger than WMARK_PROMO. Is it better >> to use a watermark that is closer to it? > > Yeah, that's a good point. Thinking about it again, I guess space_enough > is only the ratelimiting threshold, so it wouldn't make much heuristic > sense here anyways. Maybe pgdat_balanced() is a better fit here? Then > this check here will be in agreement with kswapd. I'm not sure whether it's good to use pgdat_balanced() directly. Could we use a simplified version with just some extra free space to deal with stats drift? > Hopefully the rest of the commit makes sense to you. Yes. I think that it's a real problem we need to deal with. > Thanks again, > I hope you have a great day! You too! > Joshua > >> > + 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-02 2:16 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-30 21:52 [RFC PATCH 0/2] Prevent demotions in memcg limit reclaim when toptier has room Joshua Hahn 2026-11-30 21:52 ` [RFC PATCH 1/2] mm/memory-tiers: move pgdat_free_space_enough() out of the scheduler Joshua Hahn 2026-11-30 21:52 ` [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room Joshua Hahn 2026-12-01 13:45 ` Huang, Ying 2026-12-01 15:58 ` Joshua Hahn 2026-12-02 2:16 ` Huang, Ying
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.