Skip to content

Commit 0bdf0ef

Browse files
nhatsmrtakpm00
authored andcommitted
zswap: do not shrink if cgroup may not zswap
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/] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: f4840cc ("zswap: memcg accounting") Signed-off-by: Nhat Pham <[email protected]> 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]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 9425c59 commit 0bdf0ef

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

mm/zswap.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,16 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
11741174
goto reject;
11751175
}
11761176

1177+
/*
1178+
* XXX: zswap reclaim does not work with cgroups yet. Without a
1179+
* cgroup-aware entry LRU, we will push out entries system-wide based on
1180+
* local cgroup limits.
1181+
*/
11771182
objcg = get_obj_cgroup_from_page(page);
1178-
if (objcg && !obj_cgroup_may_zswap(objcg))
1179-
goto shrink;
1183+
if (objcg && !obj_cgroup_may_zswap(objcg)) {
1184+
ret = -ENOMEM;
1185+
goto reject;
1186+
}
11801187

11811188
/* reclaim space if needed */
11821189
if (zswap_is_full()) {

0 commit comments

Comments
 (0)