Skip to contentSkip to conversation

zswap-do-not-shrink-if-cgroup-may-not-zswap.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Jun 7, 2023 Stable branch

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: zswap: do not shrink if cgroup may not zswap
has been removed from the -mm tree. Its filename was
zswap-do-not-shrink-if-cgroup-may-not-zswap.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Nhat Pham <[email protected]>
Subject: zswap: do not shrink if cgroup may not zswap
Date: Tue, 30 May 2023 15:24:40 -0700

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.

[[email protected]: fix return of unintialized value]
[[email protected]: s/ENOSPC/ENOMEM/]
Fixes f4840ccfca25 ("zswap: memcg accounting")
Cc Dan Streetman <[email protected]>
Cc Domenico Cerasuolo <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Seth Jennings <[email protected]>
Cc Vitaly Wool <[email protected]>
Cc Yosry Ahmed <[email protected]>

---

 mm/zswap.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
mm/zswap.c renamed from mm/zswap.c~zswap-do-not-shrink-if-cgroup-may-not-zswap +9 -2
@@ -1174,9 +1174,16 @@ static int zswap_frontswap_store(unsigne
 		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;
+	if (objcg && !obj_cgroup_may_zswap(objcg)) {
+		ret = -ENOMEM;
+		goto reject;
+	}
 
 	/* reclaim space if needed */
 	if (zswap_is_full()) {

_

Patches currently in -mm which might be from [email protected] are

workingset-refactor-lru-refault-to-expose-refault-recency-check.patch cachestat-implement-cachestat-syscall.patch cachestat-implement-cachestat-syscall-fix.patch cachestat-wire-up-cachestat-for-other-architectures.patch cachestat-wire-up-cachestat-for-other-architectures-fix.patch selftests-add-selftests-for-cachestat.patch