From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796075582; b=LZEl53rGFO0cB19fUMiUgj+gAlUq61UhdNDvIqX94wUVqxv5SgKPvy2W7GV1tManHwwP IthFLHs/BpBCXrlfsjcLMT7br+dzRFiT9slmUfwROmMP+oOmKOS0f/Tq+jirAMsM0meoM M/47Mpz8z9MJgVVg0UVJj0oClKzW2c/emM4YRKeCx2IEOrATKgqPBuYGJmqcq6qK27gax MD4Gju1iQVBaFyRzARibhZcj0AR0EYVmYFYYZcr6wHJ/bcK2ORZs5p3BX3ZS+JOyBS9xX 8R+w4lgo3CgkVWzLQRSobOh19IVInIDxbGgLP3czUh22WDEhfOO0clgnivbQhi5TqNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075582; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=JX8POcBsagax5eeiRFmemyANi0pWF2BYsLGSFu8gGYk=; b=sygoR1VTtF7aOVYH1SbLyOwsa7tPWjN9Afpsk+TekOKGhRsnWcdCo3KDz4FtzrpW3nen kxrWO6i6XmqTxQTaJGnX+q9uHAit+Eo5PBdqfYg3zQXw8lPGVP0iy1E/42AdnNYI3B1lX wQKe0MkzAvrs3lWL+2gEDZ8TkQPy70A8IesDcomIRORgt3ilMyT16Wtz0ROTCIttAgIhk 4EJqJ8nC5+KXwn0a4geVcAMFbX6JVZ2tWvU1xsYPrkQDbYqP5V0dW/L0vLS4xhEcIdCxV BIYygaNl0GvtFc7KgOcpjQfk/Xbv65/ZUbm3Yfl274R7HGwJPa9JS8ntrlqsoN4rd4Q== 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=JlQRaLU3; arc=none smtp.remote-ip=209.85.161.47 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (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 611D9606A333 for ; Mon, 30 Nov 2026 21:53:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 611D9606A333 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=JlQRaLU3 Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-70b875f6f13so8312804eaf.0 for ; Mon, 30 Nov 2026 13:53:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796075581; x=1796680381; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JX8POcBsagax5eeiRFmemyANi0pWF2BYsLGSFu8gGYk=; b=JlQRaLU3KhnUQG1nQuYSQnUI/DXFqChJdmorW8ugwXgShEguAcDNFaykKdIjh1Mmwp mNfCtLm4MqYpzhvageJOTyuQV023ycfzB9EUDChbhuDcPrXyil314v79f+I9rh4JCy/k YlUAQoEB6MtBpX88L9NQduRLGrjJEkf08Jck3ZqIJbOXjLV/yUYqhKmG3MDfeW6ttjKd fl7kd6ki8lN57YaEP+CKjB5t4QDQiMhdleaNtbGzdvxHiZKVfpZ0WPeZ00WdcoaEUzX6 WUA94319kvUVdU0/1cqRzYT9xpxX8MTpgDSWveSzqkGMA3ERfAroLRmOMnn9Ya7V78Xr XkTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796075581; x=1796680381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=JX8POcBsagax5eeiRFmemyANi0pWF2BYsLGSFu8gGYk=; b=X/sOT4kViPWDr0nLlVxf+BBgPl6FXsfxJ7Iy0NR7SpA2XWXJZlgIt6RBFronmMlMb8 4tx5bK6qYsFy4RN6d8Y/M6m/E6D+2x4Gi8RSsuoD1TpRlqQPlMHaywXAY0I6aIO5jfMR tn6aJL3OGOiWWL/KS1PvlSI7q2C4K+0M9uTqOUOCVXEH0rfW9RgWCW9wX2zNZuEaXWus 3D1yrPoVTMnJ1GVRtpXNMSfwjsNAG7BkFi7FF/bf4kgu5uihy0A28iltsqW6fQIDoUNd CoY3ABYU8lMTk6AaPPX6eOoxwm1XqBJRCxLpKNwZVFvCEAwYOw8rQ8VcUopwJrkZakui hliA== X-Forwarded-Encrypted: i=1; AL+hErEtZe0THsqF9vWh1jrlKDT4kn/UXFxDCmoJq5IkJnYqYdvBYtLFoIU7zthqFaFyUlWaea1B1Z4Lh9u5vXI=@vger.kernel.org X-Gm-Message-State: APuU4Z8y4fCcz+on/PPBJOT9iOwxm45hinqSUlw/RadESkDDZ68jkChZ E3NkEuKWPGlxZdt2azrwPdiB+s2kNVpg1SiLiBI4lXGKlu/GlxQ01Art X-Gm-Gg: AZFdTZcCQ25ItV8zGQsjAnGrk5C7bd8IFq6MFffvJ0z69+30/6OmBXYPVdd8BRIaQxW qvwTsZR13ecFfRthJeH3RAPdb8goJK0OU6uXwIyMotLoNpLQhkvHkDW+mL4ZWnnOrrHHCBiApr7 Jlivt11RFW/XNdmm5mwqviNvjJ72103cnJz/hmmC9KGnE9goL6ooqVfiqQeLXjRYR7Xgrg3dX0I FqQgTJcKvF522RMCRNL1Rmm3doXkDLxTgbYrCIH+4VKapRSGzeOyk7Op+xlCJZ+vT2ddalNmsfI 47lVYNC574kU7Zwspc0WUybBrEP2SDcJBr3II0RqYS/+JqdjDRsQHXH/t2jeStdrYJi8iGt1hgR 5J5mLd67a8FVru1X/Y9ixO1ncZYBkY1skoHgeLDODs7CTDtswv2pg0WjzqI0kyYNx+BdHbEAtQD Uh5JtAfJCFDqEwIzwQx3dP0p9/Y/W4vxEFoHTTtjRXeJ+rW08ivOPuWIM7e8b/Uud3yX+EI/mb+ 6qIz0NeDaLFjsug4kSTllCCiYYEZMeL463LHOs27m8ia0jdEwuL1XLufpO81xKjxKE6XoTMdzRq ximItnQveAonRANhZzIwb3bMK2EChLK9A6YxIUVZ72gLG5kGvuWIYm9zQRgPTQTl8BXFKlzWowb 5ctWzmg== X-Received: by 2002:a05:6820:619:b0:71b:7de2:cb98 with SMTP id 006d021491bc7-71b7de2cf33mr17582304eaf.82.1796075581306; Mon, 30 Nov 2026 13:53:01 -0800 (PST) Received: from localhost ([2a03:2880:10ff:70::]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b37ea818bsm24296695eaf.1.2026.11.30.13.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:53:00 -0800 (PST) From: Joshua Hahn 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@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 2/2] mm/vmscan: don't demote in memcg limit reclaim while the node has room Date: Mon, 30 Nov 2026 13:52:57 -0800 Message-ID: <20261130215258.2202513-3-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261130215258.2202513-1-joshua.hahnjy@gmail.com> References: <20261130215258.2202513-1-joshua.hahnjy@gmail.com> 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-Transfer-Encoding: 8bit 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 --- 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