From: Zhongkun He <hezhongkun.hzk@bytedance.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: hannes@cmpxchg.org, mhocko@suse.com, yosry.ahmed@linux.dev,
muchun.song@linux.dev, yuzhao@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [External] Re: [PATCH V3 1/3] mm: add swappiness=max arg to memory.reclaim for only anon reclaim
Date: Thu, 10 Apr 2025 11:48:14 +0800 [thread overview]
Message-ID: <CACSyD1NbZag42VQ0kdyjnDPU2cJimF9K51d7k__pXi-4joJa9Q@mail.gmail.com> (raw)
In-Reply-To: <20250409190933.3f08db6d6c1f13bc14a170f9@linux-foundation.org>
On Thu, Apr 10, 2025 at 10:09 AM Andrew Morton
<akpm@linux-foundation.org> wrote:
>
> On Wed, 9 Apr 2025 15:06:18 +0800 Zhongkun He <hezhongkun.hzk@bytedance.com> 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.
> >
> > 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.
> >
> > ...
> >
> > --- a/Documentation/admin-guide/cgroup-v2.rst
> > +++ b/Documentation/admin-guide/cgroup-v2.rst
> > @@ -1348,6 +1348,9 @@ 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 valid range for swappiness is [0-200, max], setting
> > + swappiness=max exclusively reclaims anonymous memory.
>
> Being able to assign either a number or a string feels a bit weird.
> Usually we use something like "-1" for a hack like this. eg,
> NUMA_NO_NODE.
>
> Perhaps we just shouldn't overload swappiness like this. Add a new
> tunable (swappiness_mode?) which can override the swappiness setting.
>
> I guess it doesn't matter much. We're used to adding messy interfaces ;)
>
Hi Andrew, thanks for your review.
In the initial patch, I used 200 (the maximum value of swappiness) to represent
the semantics of reclaiming only from anonymous pages. However, someone
pointed out that the current usage needs some fine-tuning. Later discussions
suggested using max(swappiness=201) to represent this specific
semantic explicitly
in the code. It was then discovered that MGLRU already includes this logic(201),
so it's only necessary to make the intention of the code clearer.
So we can add the max to memory.reclaim and lru_gen.
More info please see:
https://lore.kernel.org/all/Z9Rs8ZtgkupXpFYn@google.com/
>
next prev parent reply other threads:[~2025-04-10 3:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 7:06 [PATCH V3 0/3] add max arg to swappiness in memory.reclaim and lru_gen Zhongkun He
2025-04-09 7:06 ` [PATCH V3 1/3] mm: add swappiness=max arg to memory.reclaim for only anon reclaim Zhongkun He
2025-04-10 2:09 ` Andrew Morton
2025-04-10 3:48 ` Zhongkun He [this message]
2025-04-09 7:06 ` [PATCH V3 2/3] mm: add max swappiness arg to lru_gen for anonymous memory only Zhongkun He
2025-04-10 2:09 ` Andrew Morton
2025-04-10 4:50 ` [External] " Zhongkun He
2025-04-30 7:59 ` Dan Carpenter
2025-05-01 1:56 ` [External] " Zhongkun He
2025-05-02 6:58 ` Dan Carpenter
2025-05-07 3:27 ` Zhongkun He
2025-04-09 7:06 ` [PATCH V3 3/3] mm: vmscan: add more comments about cache_trim_mode Zhongkun He
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=CACSyD1NbZag42VQ0kdyjnDPU2cJimF9K51d7k__pXi-4joJa9Q@mail.gmail.com \
--to=hezhongkun.hzk@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--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 \
--cc=yuzhao@google.com \
/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