From mboxrd@z Thu Jan 1 00:00:00 1970 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 38AE5C28B2F for ; Tue, 18 Mar 2025 14:10:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4983280002; Tue, 18 Mar 2025 10:10:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD1E4280001; Tue, 18 Mar 2025 10:10:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 974AB280002; Tue, 18 Mar 2025 10:10:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 72553280001 for ; Tue, 18 Mar 2025 10:10:24 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E4EF81A1269 for ; Tue, 18 Mar 2025 14:10:24 +0000 (UTC) X-FDA: 83234856768.23.AA1B4E4 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) by imf09.hostedemail.com (Postfix) with ESMTP id E8450140018 for ; Tue, 18 Mar 2025 14:10:22 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="lAAaoRY/"; spf=pass (imf09.hostedemail.com: domain of yosry.ahmed@linux.dev designates 91.218.175.170 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742307023; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/yh8Ym+ECWzQ1Tx2CMjrE4Vg5wnvaSOPbsBq3IpvaIM=; b=S57Odn6NBEypZ3M77dLyDwLCCKAK8DWz7nhFotZ2wT6EaJSZBX2XVlB+Tk2IgBFgTOPHzt y6c86IEmmjHkq3+qJO8gKESB8DgGBu9uT0zDEskYScIyZ+S9ubxbyc6t5BW3JRXtgI5jgV QWmDZ01mNjo/UbICchbqONB/mbxI58Q= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="lAAaoRY/"; spf=pass (imf09.hostedemail.com: domain of yosry.ahmed@linux.dev designates 91.218.175.170 as permitted sender) smtp.mailfrom=yosry.ahmed@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742307023; a=rsa-sha256; cv=none; b=tfsA6XEzEyCF5dN2ccD8uLRIi6Ttgo/gleKg0hSAlw7PXJgc5ul+/d8CygXhD6xcxu3knm zjRXyHaft8pyEhddN5eupqHztaKG6nFUDpXIc3E75wM8YzJlIwSOl59e7PrdIf+v6y2OYm jspvPcSzyga+eEKG9ssfmJxqa4bvKe0= Date: Tue, 18 Mar 2025 14:10:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1742307020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/yh8Ym+ECWzQ1Tx2CMjrE4Vg5wnvaSOPbsBq3IpvaIM=; b=lAAaoRY/wdVvq+G5Z0aQ7RPljrBAVKz4psTXspaaz8OHii4FtoiNVPOZxKTRmMJ0SrGVEt fHIaAePt57dmK905b/oRE98zXZj9HkQeTgHlPpH/Vjc0dM7e+NcSvufkBHsrRLjbCwL3ea t6v9oec4XFwNH1m2yedXc7gOY6zu2Is= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yosry Ahmed To: Zhongkun He Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, yuzhao@google.com, mhocko@suse.com, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: add swappiness=max arg to memory.reclaim for only anon reclaim Message-ID: References: <20250318135330.3358345-1-hezhongkun.hzk@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250318135330.3358345-1-hezhongkun.hzk@bytedance.com> X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 9n4z7y3opz9b4n5ce4yxnt7o8sqibkqo X-Rspamd-Queue-Id: E8450140018 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1742307022-754593 X-HE-Meta: U2FsdGVkX19QMV3AzW1/Ss6C5o9NheicZmH9c984cKWH8C2WKUXqW7F9YAjwK85t68ViUuDTdFyTt1OiagFUEg//uR31ocsNbgQ6ZweqROQ0dzkdN04AA3izfZWfiv9VBl0dUT1VvVZXr2Fe0YTNid722CoB4gr8KIZwiOF2glG/YuhsUnUAU/AkF+QDlGV9LITsjRqxgVnF/DqnzHhVJjP/8aPEALJcSzzt4pBTgb7x5T4lHFrGqyo2o3SBdHvS40l02Se/mkLPqm8xfBsptZ5/XaWMENMiGj2P9FXHAdPH7DXAwOcLjybft+MSOl9YTzs+SmB9/f8V2G4CBmvJXZ0vOoBBoumzYU+Z4iYY9CLfnGBnUUO8oZg9kOG6KZqzbNRktr6ZB3F1lxfRlS9nG/DG+dfvWtHA24+kcfcdPWVuumwVmm9O091m2JMbkoJP0v4emtPwXfyIfk5Z7IZTBBObKikup84qKdBWq1vAbp7/SDdtO8cAEIujpNtudWCQ/BTH3N70l01yN00MSq0p5soORs6Il5zc6A9FG/a+vPDlfVMJox1vourkMHLD3km02hyPMibhUDMiAwZuNHr2RDah7JC/2lhZdDN/WZP/MP5e3zmKCclrF6zIB3o5/Hutwh3rdtjnK1glQzAZvNB7JyzC2lUwYJ+QJhDqW9TEryBalYH9F8iamo6Y2/i58IlfQVeonVthL5AKS5muOOKuVO5xpXv5COSUtBTVgeCpTKef7VJFMLg+RTmoTGW0doOtpGe++bi1Jx2ewk9OGieth9pUDNN5bChx29opFYbixnS1uyU+fxpY03iYTWHHcTID9E3lf9x5QYU= X-Bogosity: Ham, tests=bogofilter, 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: On Tue, Mar 18, 2025 at 09:53:30PM +0800, Zhongkun He wrote: > 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. > > So, we hope to add a new arg 'swappiness=max' in memory.reclaim where > proactive memory reclaim only reclaims from anonymous folios when > swappiness is set to max. The swappiness semantics from a user > perspective remain unchanged. > > For example, something like this: > > echo "2M swappiness=max" > /sys/fs/cgroup/memory.reclaim > > will perform reclaim on the rootcg with a swappiness setting of 'max' (a > new mode) 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 or other file first logic 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 new > mode 'max', means reclaiming just from anonymous folios both in traditional > LRU and MGLRU. Is MGLRU handled in this patch? > > Here is the previous discussion: > https://lore.kernel.org/all/20250314033350.1156370-1-hezhongkun.hzk@bytedance.com/ > https://lore.kernel.org/all/20250312094337.2296278-1-hezhongkun.hzk@bytedance.com/ > > Suggested-by: Yosry Ahmed > Signed-off-by: Zhongkun He > --- > Documentation/admin-guide/cgroup-v2.rst | 4 ++++ > include/linux/swap.h | 4 ++++ > mm/memcontrol.c | 5 +++++ > mm/vmscan.c | 10 ++++++++++ > 4 files changed, 23 insertions(+) > > diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst > index cb1b4e759b7e..c39ef4314499 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. > > + If set swappiness=max, memory reclamation will exclusively > + target the anonymous folio list for both traditional LRU and > + MGLRU reclamation algorithms. > + I don't think we need to specify LRU and MGLRU here. What about: Setting swappiness=max exclusively reclaims anonymous memory. > memory.peak > A read-write single value file which exists on non-root cgroups. > > diff --git a/include/linux/swap.h b/include/linux/swap.h > index b13b72645db3..a94efac10fe5 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -419,6 +419,10 @@ extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order, > #define MEMCG_RECLAIM_PROACTIVE (1 << 2) > #define MIN_SWAPPINESS 0 > #define MAX_SWAPPINESS 200 > + > +/* Just recliam from anon folios in proactive memory reclaim */ > +#define ONLY_ANON_RECLAIM_MODE (MAX_SWAPPINESS + 1) > + This is a swappiness value so let's keep that clear, e.g. SWAPPINESS_ANON_ONLY or similar. > extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, > unsigned long nr_pages, > gfp_t gfp_mask, > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 4de6acb9b8ec..0d0400f141d1 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -4291,11 +4291,13 @@ static ssize_t memory_oom_group_write(struct kernfs_open_file *of, > > enum { > MEMORY_RECLAIM_SWAPPINESS = 0, > + MEMORY_RECLAIM_ONLY_ANON_MODE, > MEMORY_RECLAIM_NULL, > }; > > static const match_table_t tokens = { > { MEMORY_RECLAIM_SWAPPINESS, "swappiness=%d"}, > + { MEMORY_RECLAIM_ONLY_ANON_MODE, "swappiness=max"}, MEMORY_RECLAIM_SWAPPINESS_MAX? > { MEMORY_RECLAIM_NULL, NULL }, > }; > > @@ -4329,6 +4331,9 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, > if (swappiness < MIN_SWAPPINESS || swappiness > MAX_SWAPPINESS) > return -EINVAL; > break; > + case MEMORY_RECLAIM_ONLY_ANON_MODE: > + swappiness = ONLY_ANON_RECLAIM_MODE; > + break; > default: > return -EINVAL; > } > diff --git a/mm/vmscan.c b/mm/vmscan.c > index c767d71c43d7..779a9a3cf715 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 set > + * 'swappiness=max'. > + */ /* Proactive reclaim initiated by userspace for anonymous memory only */ > + if (sc->proactive && (swappiness == ONLY_ANON_RECLAIM_MODE)) { Do we need to check sc->proactive here? Supposedly this swappiness value can only be passed in from proactive reclaim. Instead of silently ignoring the value from other paths, I wonder if we should WARN on !sc->proactive instead. > + 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 > -- > 2.39.5 >