linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nhat Pham <nphamcs@gmail.com>
To: akpm@linux-foundation.org
Cc: hannes@cmpxchg.org, cerasuolodomenico@gmail.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com,
	yosryahmed@google.com, kernel-team@meta.com
Subject: [PATCH v3] zswap: do not shrink if cgroup may not zswap
Date: Tue, 30 May 2023 16:24:35 -0700	[thread overview]
Message-ID: <20230530232435.3097106-1-nphamcs@gmail.com> (raw)
In-Reply-To: <CAJD7tkaveZ44agL0-iLfHdX1Pm_xEwBSYo=n5Tnm7pVWbsdTug@mail.gmail.com>

Before storing a page, zswap first checks if the number of stored pages
exceeds the limit specified by memory.zswap.max, for each cgroup in the
hierarchy. If this limit is reached or exceeded, then zswap shrinking is
triggered and short-circuits the store attempt.

However, since the zswap's LRU is not memcg-aware, this can create the
following pathological behavior: the cgroup whose zswap limit is 0 will
evict pages from other cgroups continually, without lowering its own
zswap usage. This means the shrinking will continue until the need for
swap ceases or the pool becomes empty.

As a result of this, we observe a disproportionate amount of zswap
writeback and a perpetually small zswap pool in our experiments, even
though the pool limit is never hit.

More generally, a cgroup might unnecessarily evict pages from other
cgroups before we drive the memcg back below its limit.

This patch fixes the issue by rejecting zswap store attempt without
shrinking the pool when obj_cgroup_may_zswap() returns false.

Fixes: f4840ccfca25 ("zswap: memcg accounting")
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Nhat Pham <nphamcs@gmail.com>
---
 mm/zswap.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mm/zswap.c b/mm/zswap.c
index 59da2a415fbb..cff93643a6ab 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1174,9 +1174,14 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
 		goto reject;
 	}
 
+	/*
+	 * XXX: zswap reclaim does not work with cgroups yet. Without a
+	 * cgroup-aware entry LRU, we will push out entries system-wide based on
+	 * local cgroup limits.
+	 */
 	objcg = get_obj_cgroup_from_page(page);
 	if (objcg && !obj_cgroup_may_zswap(objcg))
-		goto shrink;
+		goto reject;
 
 	/* reclaim space if needed */
 	if (zswap_is_full()) {
-- 
2.34.1


  reply	other threads:[~2023-05-30 23:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30 16:21 [PATCH] zswap: do not shrink when memory.zswap.max is 0 Nhat Pham
2023-05-30 16:52 ` Yosry Ahmed
2023-05-30 18:00   ` Johannes Weiner
2023-05-30 18:41     ` Yosry Ahmed
2023-05-30 19:13       ` Johannes Weiner
2023-05-30 20:19         ` Yosry Ahmed
2023-05-30 20:59           ` Johannes Weiner
2023-05-30 21:04             ` Yosry Ahmed
2023-05-30 21:46               ` Nhat Pham
2023-05-30 22:24                 ` [PATCH] zswap: do not shrink if cgroup may not zswap Nhat Pham
2023-05-30 22:30                   ` Andrew Morton
2023-05-30 23:37                     ` Nhat Pham
2023-05-30 22:36                   ` Yosry Ahmed
2023-05-30 23:24                     ` Nhat Pham [this message]
2023-05-30 18:27   ` [PATCH] zswap: do not shrink when memory.zswap.max is 0 Nhat Pham
2023-05-30 18:42     ` Yosry Ahmed
2023-06-07 19:09       ` Andrew Morton
2023-06-07 19:17         ` Yosry Ahmed
2023-06-07 19:31         ` Nhat Pham
2023-06-07 20:42         ` Johannes Weiner

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=20230530232435.3097106-1-nphamcs@gmail.com \
    --to=nphamcs@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cerasuolodomenico@gmail.com \
    --cc=ddstreet@ieee.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sjenning@redhat.com \
    --cc=vitaly.wool@konsulko.com \
    --cc=yosryahmed@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;
as well as URLs for NNTP newsgroup(s).