From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.99 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796270968; b=QwSImEgiGWArethBNlcGkyvTZfxZlVAnFyAKqUftcR/jcDqmdWqSdDVs28bMlF3NdaSg XG0nltkTexCiHeogKvARsURgRmuXPNnUE3GEys0gGUJAsBkehynBQfD7tjiO4RkS2JkbP kAXN9n7mymXW6eUcVbWuHtpedw3zFap4yqn//IeWJ3pJrO3lCi0SSpTWcxE9AKiYwlox+ uA7RARFlSSZpewULTzZ0HuR094qzIgfN3lFnY0fRVCIZZOrZ+BAtAwXEVyEqxQ44hBVx5 CmggMSU8ybSawPXnlFItu0OKZWW4Nxi3ePy0nuqhGxDpbzdlf5G8zeFVCS61KcWfwpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796270968; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:In-Reply-To:References:Date:Message-ID:User-Agent: MIME-Version:Content-Type; bh=sD65MF3b+hxskOA8sNoFPmhA817VXnXd0E8vGdRB/oE=; b=wqYneePvgxTsDE4Z1D9PX59N84zhs+HB9KSXuGpuPsoB7v8HU/212NSgEybnol/e2AEe vmPhx+9k2geY28gAPTJStVaGBl625nE12kCXcxsksjGH6PBO5Qg2OyKSTs9SGHyr2Nb7T UWZj3iDD+tYJFqoIF33xYcXvHveUYz1Ze36k6U+Kb4dDGaVg0UC2gP5sxj1w6YjRrrAvq gaV3MZBjWfiMnNWaz0GESv9phWoMI7lt2X07KhHGGRXLcncGadhgSuW4T0tqUarxbSISE LJgUK1AoDd8y2gMygF4lZNsptynIb1x7GU25Sgw3JdMCV6VTmzmaMspjM8KBdS7fODQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=cLL6GfpC; arc=none smtp.remote-ip=115.124.30.99 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C88C606A322 for ; Thu, 3 Dec 2026 04:09:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3C88C606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=cLL6GfpC DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796270963; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=sD65MF3b+hxskOA8sNoFPmhA817VXnXd0E8vGdRB/oE=; b=cLL6GfpCBnUa6yO98lJnbfcF/TpYcGZDzBZQQdqcShtO4JihHvPBFBSRbywFWN6Bnd5P33m1c5Apx+9gwa9czbnoHxfpPs2VPUVImHHmfc56PzZVa2LIqLZe5gEujB1Nuiyj6cG57WjnMWmW7dHxF6Ni3P51+6TTTW5bSYf7GOA= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037009110;MF=ying.huang@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0XGCph30_1796270960; Received: from DESKTOP-5N7EMDA(mailfrom:ying.huang@linux.alibaba.com fp:SMTPD_---0XGCph30_1796270960 cluster:ay36) by smtp.aliyun-inc.com; Thu, 03 Dec 2026 12:09:21 +0800 From: "Huang, Ying" 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@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 In-Reply-To: <20261202150538.294531-6-joshua.hahnjy@gmail.com> (Joshua Hahn's message of "Wed, 2 Dec 2026 07:28:52 -0800") References: <20261130215258.2202513-1-joshua.hahnjy@gmail.com> <20261130215258.2202513-3-joshua.hahnjy@gmail.com> <87qzg1yv12.fsf@DESKTOP-5N7EMDA> <20261201155714.294531-1-joshua.hahnjy@gmail.com> <87fqwgzau0.fsf@DESKTOP-5N7EMDA> <20261202150538.294531-6-joshua.hahnjy@gmail.com> Date: Thu, 03 Dec 2026 12:09:20 +0800 Message-ID: <871p7zxaxb.fsf@DESKTOP-5N7EMDA> User-Agent: Gnus/5.13 (Gnus v5.13) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Joshua Hahn writes: > On Wed, Dec 02, 2026 at 10:16:07AM +0800, Huang, Ying wrote: >> Joshua Hahn writes: >> >> > On Tue, Dec 01, 2026 at 09:45:13PM +0800, Huang, Ying wrote: >> >> Hi, Joshua, >> >> >> >> Joshua Hahn 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