From: "Huang, Ying" <ying.huang@linux.alibaba.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@kernel.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Qi Zheng <qi.zheng@linux.dev>,
David Hildenbrand <david@kernel.org>,
Gregory Price <gourry@gourry.net>, Zi Yan <ziy@nvidia.com>,
Rakie Kim <rakie.kim@sk.com>, Kairui Song <kasong@tencent.com>,
Barry Song <baohua@kernel.org>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Baoquan He <baoquan.he@linux.dev>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com
Subject: Re: [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room
Date: Thu, 03 Dec 2026 12:09:20 +0800 [thread overview]
Message-ID: <871p7zxaxb.fsf@DESKTOP-5N7EMDA> (raw)
In-Reply-To: <20261202150538.294531-6-joshua.hahnjy@gmail.com> (Joshua Hahn's message of "Wed, 2 Dec 2026 07:28:52 -0800")
Joshua Hahn <joshua.hahnjy@gmail.com> writes:
> On Wed, Dec 02, 2026 at 10:16:07AM +0800, Huang, Ying wrote:
>> 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?
>
> I think you could have an iterator that just checks the usage against
> the promo watermark, maybe like:
>
> for (zone) {
> if (!managed_zone(zone))
> continue;
> if (zone_watemark_ok(zone, 0, promo_wmark_pages(zone),
> ZONE_MOVABLE, 0))
> return true;
> }
>
> As for if we need the extra free space I'm not really sure. It would be
> there to prevent an accidental demotion skip, but given that the drift
> can be at most 125 pages per cpu, I'm not sure if it's big enough to
> cause too much concern? Also I think this would push the error in the
> other direction where we demote when we have enough room.
>
> I don't feel particularly strongly about this, just wanted to think out
> loud. FWIW I think migrate_balanced_pgdat() does something similar.
> If you think this will be a concern, I'd be happy to just change that
> watermark check above to promo + step.
[snip]
IIUC, if memory usage < DRAM size, we want reclaiming; if memory usage >
DRAM + CXL size, we want demotion to create DRAM -> CXL -> swap memory
hotness tiers. And we demote in between as well.
If so, I think it's better to use WMARK_PROMO + drift margin, to avoid
missing the second situation.
---
Best Regards,
Huang, Ying
prev parent reply other threads:[~2026-12-03 4:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 21:52 [RFC PATCH 0/2] Prevent demotions in memcg limit reclaim when toptier " 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
2026-12-02 15:28 ` Joshua Hahn
2026-12-03 4:09 ` Huang, Ying [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871p7zxaxb.fsf@DESKTOP-5N7EMDA \
--to=ying.huang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=rakie.kim@sk.com \
--cc=shakeel.butt@linux.dev \
--cc=weixugc@google.com \
--cc=yuanchu@google.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®