From patchwork Thu Mar 13 03:48:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhongkun He X-Patchwork-Id: 14014238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E9D4C282DE for ; Thu, 13 Mar 2025 03:48:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9B8A280003; Wed, 12 Mar 2025 23:48:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C57EE280001; Wed, 12 Mar 2025 23:48:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC4DB280003; Wed, 12 Mar 2025 23:48:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8AD00280001 for ; Wed, 12 Mar 2025 23:48:26 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E77121619E6 for ; Thu, 13 Mar 2025 03:48:26 +0000 (UTC) X-FDA: 83215145412.16.14AFA90 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf04.hostedemail.com (Postfix) with ESMTP id 6572740003 for ; Thu, 13 Mar 2025 03:48:24 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=X2lnQszn; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741837705; a=rsa-sha256; cv=none; b=enh9+cghc8yJQ44HF69Bv/4g6UWgCBJdoIC9KPuTHHo9jxt0KIeX7uZwCO/WBDvFZt15aq lAKnmpN1OZrW8tkRfBz9EhE9cIOVOIjmPAU/n0+efoGk/nO/2dGDTgs2XdKprpfP7p9RZy rW/8R4n9rwFAPzcIiaXhjR3c4vZ5iwo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=X2lnQszn; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of hezhongkun.hzk@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=hezhongkun.hzk@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741837705; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=yFkhLOrOugcxeT1NkNYtdDdVlD9vOgxf/q0l13x2PvI=; b=5r8QfpcURCCUASPfU9zW65n2MhDZIFl1NxsYh9wMMM780EybIFTa5dCrb0w3HiDYdqgoHg k4RyRp98t1XS48TCQ+lGRXUo2d9a78nLYbwF+ulGr4oQ4QhG1WVA2uN0BNiuq07XbzihcA LNWwGq2RotLyK8PGqXtB6ujMCvcoENc= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-22580c9ee0aso8881965ad.2 for ; Wed, 12 Mar 2025 20:48:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1741837703; x=1742442503; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yFkhLOrOugcxeT1NkNYtdDdVlD9vOgxf/q0l13x2PvI=; b=X2lnQsznRDjTBD+a9Bl7ocq00M3Oc44CJbnn4MGSkRXMk0Vx7G9FI1ngpfIYx/htD7 Er1XNTwl4J+a58uP6bCt5C7IlOdr6R6XBsP1EjSwyhZ7ZStKtU4bkt8L3eBKlfr6LI3f a4kx32btiN4HIGvB0opHoCH2Ah5JzmlzlkXPljE3KoWKSjFJWhzY96FmqgRKmj13im68 x3kyfbYryS8q9mq9esCncwfUdRVGSffehGCOTpn+WcOFPkGYfLwp6d/ZnYBcvQ1t7ocJ A6cjuaAkvnYdJTwfJI6H6zgbvyMYfiasmIsI3R/3NV/UIs+9BWctvAscr+ufCXi1FhmI eZsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741837703; x=1742442503; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yFkhLOrOugcxeT1NkNYtdDdVlD9vOgxf/q0l13x2PvI=; b=SPT2PM2vwYGhupV9j5mVDlIQocjUdF55V8FtWRRwOcm4aExSTzy6VsHHFENGTyRnE4 22l87s9gODNujGZw5uxynu8LHzBzY28Wrr85G5izprZ68IJzMEBXOFol6tYJ1MlLSVPj n23pk/ZmC1KDLnxBhauWs8a51zELxC+qKFqOMyWpAi4m8g2y3Ag9lq2ah6bkfCEateFz q+4CXXUMVIGitkmjkzXxbUM9CeDjYs6n1LblAg7IL0u/uD75VNYQhJY1CPSHTmLxUBJn 2DfUAjQGYA193OcRFCbh3sbavLepe14paVe95Bcuey5AKGujbigb4xJ0NC1LcASO9i11 MKhQ== X-Forwarded-Encrypted: i=1; AJvYcCVj/7PMnWpBdGlliTzReZ4/Ry1K2AOuEXkKXabnr+y7fCdRTkSWDVQjqPLKSPdh6CLIeEpZ6oqeTA==@kvack.org X-Gm-Message-State: AOJu0YzJ3MlN5IlQlH2zPsNwvgcXDBZ5Vzj6jkqe3kq15+YShhWPPSsV /JsfVvdgGtfrZCBDv47COxoZugDPeS6oa1eZ9nQTVmIC1I3PchHhxTYnX2AOpN4= X-Gm-Gg: ASbGncsZuZj0GL+jUp4xWMAM3tTN4GRr3t2JQz+gs3BUq1/D/Ai9G85g9em5/yocAMu 8IURcC3FpjU3lQ7vuBTPRwFpIFLs7vV6NFK9cB7maUBso83wREXH2iTUt0E6WaAWxwxCcCpzJ7x b92DL/EIVC6O1Y5+W4U/sSMQkIu0Nf9IUNcBdSEKHn9q56gJ0jKQaDxtzMfd79uhY8kx9KtYhmd VNtzgNCaqv4a3GfBYi07eyh54wdIC82/xtQcTy+361ErYvHTQG/IPWvbkm6TJH4K9iqzLh9cYw7 AG+4d0zvKuSneICrOgdqeBa5SN7CFld8i1bYlbHUnE4uIXLlVxW0yAzIRwgQKwMvBgq/K+Lop1M kZ2a7 X-Google-Smtp-Source: AGHT+IHb8R6fInhQdJ0Z0KxYAmZL9TTX8Gbtcci8MLZpk/dPB1qvfzZaK2XFMIZCt5WZe3MmaWfAZQ== X-Received: by 2002:a17:903:32c5:b0:224:249f:9734 with SMTP id d9443c01a7336-2242887ecd7mr351205205ad.4.1741837703151; Wed, 12 Mar 2025 20:48:23 -0700 (PDT) Received: from n37-069-081.byted.org ([115.190.40.11]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-225c68aa62csm3590615ad.92.2025.03.12.20.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 20:48:22 -0700 (PDT) From: Zhongkun He To: akpm@linux-foundation.org Cc: mhocko@suse.com, hannes@cmpxchg.org, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhongkun He Subject: [PATCH V1] mm: vmscan: skip the file folios in proactive reclaim if swappiness is MAX Date: Thu, 13 Mar 2025 11:48:12 +0800 Message-Id: <20250313034812.3910627-1-hezhongkun.hzk@bytedance.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6572740003 X-Rspamd-Server: rspam05 X-Stat-Signature: n1bfkaajo9r41u4kuppywh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ilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With this patch 'commit <68cd9050d871> ("mm: add swappiness= arg to memory.reclaim")', we can submit an additional swappiness= argument to memory.reclaim. It is very useful because we can dynamically adjust the reclamation ratio based on the anonymous folios and file folios of each cgroup. For example,when swappiness is set to 0, we only reclaim from file folios. However,we have also encountered a new issue: when swappiness is set to the MAX_SWAPPINESS, it may still only reclaim file folios. This is due to the knob of cache_trim_mode, which depends solely on the ratio of inactive folios, regardless of whether there are a large number of cold folios in anonymous folio list. So, we hope to add a new control logic where proactive memory reclaim only reclaims from anonymous folios when swappiness is set to MAX_SWAPPINESS. For example, something like this: echo "2M swappiness=200" > /sys/fs/cgroup/memory.reclaim will perform reclaim on the rootcg with a swappiness setting of 200 (max swappiness) regardless of the file folios. Users have a more comprehensive view of the application's memory distribution because there are many metrics available. For example, if we find that a certain cgroup has a large number of inactive anon folios, we can reclaim only those and skip file folios, because with the zram/zswap, the IO tradeoff that cache_trim_mode is making doesn't hold - file refaults will cause IO, whereas anon decompression will not. With this patch, the swappiness argument of memory.reclaim has a more precise semantics: 0 means reclaiming only from file pages, while 200 means reclaiming just from anonymous pages. V1: Update Documentation/admin-guide/cgroup-v2.rst --from Andrew Morton Add more descriptions in the comment. --from Johannes Weiner Signed-off-by: Zhongkun He Acked-by: Johannes Weiner --- Documentation/admin-guide/cgroup-v2.rst | 4 ++++ mm/vmscan.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index cb1b4e759b7e..6a4487ead7e0 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1343,6 +1343,10 @@ The following nested keys are defined. same semantics as vm.swappiness applied to memcg reclaim with all the existing limitations and potential future extensions. + The swappiness have the range [0, 200], 0 means reclaiming only + from file folios, 200 (MAX_SWAPPINESS) means reclaiming just from + anonymous folios. + memory.peak A read-write single value file which exists on non-root cgroups. diff --git a/mm/vmscan.c b/mm/vmscan.c index c767d71c43d7..f4312b41e0e0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2438,6 +2438,16 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, goto out; } + /* + * Do not bother scanning file folios if the memory reclaim + * invoked by userspace through memory.reclaim and the + * swappiness is MAX_SWAPPINESS. + */ + if (sc->proactive && (swappiness == MAX_SWAPPINESS)) { + scan_balance = SCAN_ANON; + goto out; + } + /* * Do not apply any pressure balancing cleverness when the * system is close to OOM, scan both anon and file equally