linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>,
	ying chen <yc1082463@gmail.com>,
	 akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/vmscan: when the swappiness is set to 0, memory swapping should be prohibited during the global reclaim process
Date: Fri, 28 Feb 2025 11:21:54 +0800	[thread overview]
Message-ID: <CALOAHbAbiAFo8rMvPCet2ybgTM0DFbKOeZayz5bmTJ6KTG6naQ@mail.gmail.com> (raw)
In-Reply-To: <20250227161934.GA115948@cmpxchg.org>

On Fri, Feb 28, 2025 at 12:19 AM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> Hello,
>
> On Thu, Feb 27, 2025 at 07:54:27AM -0800, Joshua Hahn wrote:
> > On Thu, 27 Feb 2025 22:34:51 +0800 ying chen <yc1082463@gmail.com> wrote:
>
> > Previously, when the system is under a lot of memory pressure and is
> > facing OOMs, global reclaim can create space for the system and prevent
> > going out of memory by swapping, even when swappiness is 0. If this patch
> > removes that check, it would mean that global reclaim can no longer
> > "bypass" the swappiness == 0 condition.
> >
> > I am also CCing Johannes, who is the original author of this section [1],
> > who clarified in the patch that swappiness == 0 has different meanings for
> > global reclaim and memory cgroup reclaim.
>
> Yes. It's been the behavior for decades that swappiness is merely a
> preference, and that the VM *will* swap to avert OOM. You would break
> users making this change.

Hello Johannes,

How about introducing a new value, vm.swappiness=-1, to disable
swapping for global reclaim?

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 76378bc257e3..4c22352c331c 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2387,13 +2387,19 @@ static void get_scan_count(struct lruvec
*lruvec, struct scan_control *sc,
        }

        /*
-        * Global reclaim will swap to prevent OOM even with no
-        * swappiness, but memcg users want to use this knob to
-        * disable swapping for individual groups completely when
-        * using the memory controller's swap limit feature would be
-        * too expensive.
+        * swappiness > 0:
+        *   Swapping is enabled for both global reclaim and memcg reclaim.
+        *
+        * swappiness = 0:
+        *   Swapping is completely disabled for individual groups when using
+        *   the memory controller's swap limit feature would be too costly.
+        *
+        * swappiness = -1:
+        *   Swapping is disabled for both global reclaim and memcg reclaim.
+        *   This is useful when you want to enable swapping for certain
+        *   memory cgroups while disabling it for others.
         */
-       if (cgroup_reclaim(sc) && !swappiness) {
+       if ((cgroup_reclaim(sc) && !swappiness) || swappiness == -1)
                scan_balance = SCAN_FILE;
                goto out;
        }


Other parts of the code will also need to be updated to accommodate
this new swappiness value.

>
> If you want to hard-exempt cgroups, set memory.swap.max=0.

This does not apply to the root memcg.

>
> [ Yes, it's inconsistent. But it's really cgroup_reclaim() that is the
>   oddball in this. Also for historical reasons... ]
>
> > > when the vm.swappiness is set to 0, global reclaim should also refrain
> > > from memory swapping, just like these cgroups.
> > >
> > > Signed-off-by: yc1082463 <yc1082463@gmail.com>
>
> Nacked-by: Johannes Weiner <hannes@cmpxchg.org>
>

-- 
Regards
Yafang


  parent reply	other threads:[~2025-02-28  3:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-27 14:34 ying chen
2025-02-27 15:54 ` Joshua Hahn
2025-02-27 16:19   ` Johannes Weiner
2025-02-28  3:18     ` ying chen
2025-02-28  3:21     ` Yafang Shao [this message]
2025-02-28  3:16   ` ying chen
2025-02-27 19:12 ` Shakeel Butt
2025-02-28  2:48   ` ying chen
2025-03-03 12:07 ` Michal Hocko
  -- strict thread matches above, loose matches on Subject: below --
2025-02-27  7:51 ying chen

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=CALOAHbAbiAFo8rMvPCet2ybgTM0DFbKOeZayz5bmTJ6KTG6naQ@mail.gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=yc1082463@gmail.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