From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796328333; b=JgRnPAgyrIVNP+78ywnOGBj9kX2Eo1OQ6fPHxzrLGZyt5VMGwZC0YYlh1CnJLYQ6f/W6 ezRMc2pRAa2QpVzOIAdIwYmeaQwRKxDxy3R0xOAlZ1h6Odtm8q5WIRA1OFzBUKdLxryyj M+rNbbdwhhNYcWrTOHIL1cCcuB2JvmG+uRNODgAVQB6GIlJrRtSvtAcOYARTMk3Ip5082 rk6G+zjLZYXWkkZyhzSB/s1aGrSA3Q9XAB2F6h9nIPBAU8Be6ppiQ1/dHI92oirGRyiU4 KhP+cckmxZrCEkZ9VLMo1CJ0LGZpMEpweSFdIW4hWa5GkAcXRPvE26RG2OOSPdVuTAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796328333; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=O1otwlP2sk6odBabRoIqGMger1g7qZltQM7Az/CbuWo=; b=rQiGodnMdwY2ufgRaZMBYgyeCrZbKyU3jfGOaGQkoFs2WvoH0Waaayx687T8dRJq68cS YWPqs8KtYMOLhyUTMSV7QsWv1zYKKnNK1itXnXyGfnzCgjy2ZZCN1ir7kHQUdEpzd9vDr mwr4dqsyY66g1OcycRgnrCr0yjtOqpmZmEIvYD6jPdLy6CJWTKl9JYZNEFB9teVVAWeqm 7d38YbXeV4SnVp7hhRbOAH7l2Z+cobYwXBBL9wHT6ZtbPNfL5ZV/aItmvlieJwdj9XLX/ 44nvJAMdP4SMOPgXfz+Huh3IzPf9n7e+4Zd7+/5SGZbFVj+Uzg4C+oYJ4X+2L90ztTw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ijzItvsB; arc=none smtp.remote-ip=209.85.128.177 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96D04606A322 for ; Thu, 3 Dec 2026 20:05:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 96D04606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ijzItvsB Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-8b595601695so1849277b3.3 for ; Thu, 03 Dec 2026 12:05:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796328333; x=1796933133; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=O1otwlP2sk6odBabRoIqGMger1g7qZltQM7Az/CbuWo=; b=ijzItvsBJfKMWwR2IOgrQprN8gJmzk2ySootZt30jLW3RsBv8NUO5Av7KY++g0ZfIF v2X8PD3d88RpX2C9Zyy6Wu/YgT6qhNwVWN05F3mCmvM9jENy9Lb3uekC3tq2fqfr1ugm gUcblOqPa29ktgnPa9DtSX73R1mJfO78dFBj1DswVWAojWMxif7qLp0jGic1k84bdqNP P+ZBoEPCBc8GY6NE4fl7CZWXosneQZkXtc616zzYrmwajWoWsy0iBWA3yKFSQcyPyS9h rMAZSniflYGanQLi8Hj+nx+QXNo7Gw49sZW9ks3bBf5WchZWukvJ6a4wEn84iLEelQoF SmjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796328333; x=1796933133; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=O1otwlP2sk6odBabRoIqGMger1g7qZltQM7Az/CbuWo=; b=bZeg/UmiOJdLqtZLZl7hWGvy2IxkkjUSyfkR1infmUGjqPxH8xO41MTinhkLSKiSTb 0QpNd6naIyuMZwszEM4lqM8CeYOngjdVWWfGxo7hascXtSzvWfE2YAhKeDZVFLqMv8tb eVouHOVcCrPAG4HmOpBZYeT8PCzOIFGUazQpYKt792yVkUdWXbrujwcAqci4SYcyWFL1 zc5BpLyxKo+SFyiS2//VIAfPkqnm4A7dfSFh9e+KdbYzb2ErzFX62D5dy6qVnLlIyxJ2 c2RGljM/gX/K1ctY96bbdwcryLBGe/qQZYcueKRt+R3PcYDEegMtaRqfLEPCEkn/Yohv a6LA== X-Forwarded-Encrypted: i=1; AL+hErFYvUl2XYJJb4LFa2AveXg55BfY6AkRqHwZB3z4RItddvem2LuO16F3YXNPE7e+VKWciqyYPBgya7a0B+E=@vger.kernel.org X-Gm-Message-State: APuU4Z+e//lECZw19qoRCNsNBO6y1GT6pxByivtgZceD14rmThlpx9qr OutOyShTGsFH9Gr/Nl1xUBT1TTeG1hxA9PpP/4ens1pBYWbyzSU/lxuk X-Gm-Gg: AZFdTZdJJiScLW0KDs5i5BFdUSph+58Sn9yi/9FUmfa8CZHH0+ASaQ88B4/mIkx+fxf xI8JY1qNJfs5yLgZmPYMQpS/lwGUW9nHjEtzhrw1l0VrgtB1aXMu726HD6uqz1yv/HfLqQqjjBK dTKbB3UbHIynIOSG3Vy53uNAXpfb0Zp+b/a6r52KU+tv2V4f89ubpnDTHtOJow6bjv1OAI2jldC KWGQn8LO9APvFEz2SDSFP3FMpkjWRldJdy0g+nH3aw0E58ZrNb8+CXOwUPiAXDCEP/SndhweNwL N8KfRlaz+lGeKU0wfE+vEEm0mewseoOfB2oi1UVv+waQdW8IWSjF/MxbuhDg9HGLJxfUeletgWb 4ng2L3HI3lGBDuNGhTUOu1xadDRARNr5jBJ9FOr04xD9y1S3uiUN1y8Y2S2TORp6Tk+Ms7J99J5 RYzCIFAV59iQpcl6zugQYupwzG0BRMbckj85APxBjhBU+dMbVAizolr6BNgEkZWjJX3WXz/Td5J ZHWOE4ceUXhURo4L19dRWXuD1t7QbFGX0Hbl6lz+zs6VblmOmH1E8PXPQjOO7zwvRLS/q6W3s47 jfFbIFWQCGazYiAb4FL4Kg7ArmQlFa+hhyaUp/Y+kZAjtJuhY+5Ke4VABec= X-Received: by 2002:a05:690c:442:b0:8b1:567c:e7b2 with SMTP id 00721157ae682-8b5204a1eb1mr178013017b3.39.1796328332530; Thu, 03 Dec 2026 12:05:32 -0800 (PST) Received: from localhost ([2a03:2880:10ff:a::]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b5202bf474sm176147447b3.21.2026.12.03.12.05.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 12:05:32 -0800 (PST) Date: Thu, 3 Dec 2026 12:05:31 -0800 From: Joshua Hahn 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@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 Message-ID: <20261203200426.3155944-2-joshua.hahnjy@gmail.com> 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> <871p7zxaxb.fsf@DESKTOP-5N7EMDA> 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=us-ascii Content-Disposition: inline In-Reply-To: <871p7zxaxb.fsf@DESKTOP-5N7EMDA> On Thu, Dec 03, 2026 at 12:09:20PM +0800, Huang, Ying wrote: > 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. Ah yeah, that makes sesne. In that case I'll go ahead and send a new version out that uses a step size as the drift margin? So it would check for promo + (promo - high) for the zones. Thanks for explaining this to me, Ying. Have a great day!! Joshua