linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hailong Liu <hailong.liu@oppo.com>
To: Zhongkun He <hezhongkun.hzk@bytedance.com>
Cc: <akpm@linux-foundation.org>, <mhocko@suse.com>,
	<hannes@cmpxchg.org>, <muchun.song@linux.dev>,
	<yosry.ahmed@linux.dev>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V2] mm: vmscan: skip the file folios in proactive reclaim if swappiness is MAX
Date: Fri, 14 Mar 2025 19:32:10 +0800	[thread overview]
Message-ID: <20250314113210.2z36hilxwfbnl4ms@oppo.com> (raw)
In-Reply-To: <20250314033350.1156370-1-hezhongkun.hzk@bytedance.com>

On Fri, 14. Mar 11:33, Zhongkun He wrote:
> With this patch 'commit <68cd9050d871> ("mm: add swappiness= arg to
> memory.reclaim")', we can submit an additional swappiness=<val> 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
>
> V2:
>   Add reviewed from Yosry Ahmed.
>
> Signed-off-by: Zhongkun He <hezhongkun.hzk@bytedance.com>
> Reviewed-by: Yosry Ahmed <yosry.ahmed@linux.dev>
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> ---
>  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.
> +
mglru ?
https://elixir.bootlin.com/linux/v6.13-rc1/source/mm/vmscan.c#L4533
>    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
> --
> 2.39.5
>
>

--

Help you, Help me,
Hailong.


      parent reply	other threads:[~2025-03-14 11:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14  3:33 Zhongkun He
2025-03-14  6:11 ` Muchun Song
2025-03-14  8:52 ` Michal Hocko
2025-03-14  9:24   ` [External] " Zhongkun He
2025-03-14  9:27   ` Michal Hocko
2025-03-14 10:35     ` [External] " Zhongkun He
2025-03-14 14:18     ` Johannes Weiner
2025-03-14 14:49       ` Michal Hocko
2025-03-14 16:57         ` Johannes Weiner
2025-03-14 17:52           ` Yosry Ahmed
2025-03-14 11:32 ` Hailong Liu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250314113210.2z36hilxwfbnl4ms@oppo.com \
    --to=hailong.liu@oppo.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hezhongkun.hzk@bytedance.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=yosry.ahmed@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox