From: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
To: tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org,
shuah@kernel.org, mhocko@kernel.org, roman.gushchin@linux.dev,
shakeelb@google.com, muchun.song@linux.dev, sjenning@redhat.com,
ddstreet@ieee.org, vitaly.wool@konsulko.com, riel@surriel.com,
nphamcs@gmail.com
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Subject: [PATCH 3/3] selftests: cgroup: add zswap-memcg unwanted writeback test
Date: Wed, 21 Jun 2023 17:35:48 +0200 [thread overview]
Message-ID: <20230621153548.428093-4-cerasuolodomenico@gmail.com> (raw)
In-Reply-To: <20230621153548.428093-1-cerasuolodomenico@gmail.com>
Add a test to verify that when a memcg hits its limit in zswap, it
doesn't trigger an unwanted writeback that would result in pages not
owned by that memcg to be sent to disk, even if zswap isn't full.
This was fixed by commit 0bdf0efa180a("zswap: do not shrink if cgroup
may not zswap").
Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
---
tools/testing/selftests/cgroup/test_zswap.c | 61 +++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c
index e859fecd310b..49def87a909b 100644
--- a/tools/testing/selftests/cgroup/test_zswap.c
+++ b/tools/testing/selftests/cgroup/test_zswap.c
@@ -50,6 +50,66 @@ static int get_zswap_stored_pages(size_t *value)
return read_int("/sys/kernel/debug/zswap/stored_pages", value);
}
+static int get_zswap_written_back_pages(size_t *value)
+{
+ return read_int("/sys/kernel/debug/zswap/written_back_pages", value);
+}
+
+static int allocate_bytes(const char *cgroup, void *arg)
+{
+ size_t size = (size_t)arg;
+ char *mem = (char *)malloc(size);
+
+ if (!mem)
+ return -1;
+ for (int i = 0; i < size; i += 4095)
+ mem[i] = 'a';
+ free(mem);
+ return 0;
+}
+
+/*
+ * When trying to store a memcg page in zswap, if the memcg hits its memory
+ * limit in zswap, writeback should not be triggered.
+ *
+ * This was fixed with commit 0bdf0efa180a("zswap: do not shrink if cgroup may
+ * not zswap"). Needs to be revised when a per memcg writeback mechanism is
+ * implemented.
+ */
+static int test_no_invasive_cgroup_shrink(const char *root)
+{
+ size_t written_back_before, written_back_after;
+ int ret = KSFT_FAIL;
+ char *test_group;
+
+ /* Set up */
+ test_group = cg_name(root, "no_shrink_test");
+ if (!test_group)
+ goto out;
+ if (cg_create(test_group))
+ goto out;
+ if (cg_write(test_group, "memory.max", "1M"))
+ goto out;
+ if (cg_write(test_group, "memory.zswap.max", "10K"))
+ goto out;
+ if (get_zswap_written_back_pages(&written_back_before))
+ goto out;
+
+ /* Allocate 10x memory.max to push memory into zswap */
+ if (cg_run(test_group, allocate_bytes, (void *)MB(10)))
+ goto out;
+
+ /* Verify that no writeback happened because of the memcg allocation */
+ if (get_zswap_written_back_pages(&written_back_after))
+ goto out;
+ if (written_back_after == written_back_before)
+ ret = KSFT_PASS;
+out:
+ cg_destroy(test_group);
+ free(test_group);
+ return ret;
+}
+
struct no_kmem_bypass_child_args {
size_t target_alloc_bytes;
size_t child_allocated;
@@ -176,6 +236,7 @@ struct zswap_test {
const char *name;
} tests[] = {
T(test_no_kmem_bypass),
+ T(test_no_invasive_cgroup_shrink),
};
#undef T
--
2.34.1
prev parent reply other threads:[~2023-06-21 15:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-21 15:35 [PATCH 0/3] selftests: cgroup: add zswap test program Domenico Cerasuolo
2023-06-21 15:35 ` [PATCH 1/3] selftests: cgroup: add test_zswap program Domenico Cerasuolo
2023-06-21 15:35 ` [PATCH 2/3] selftests: cgroup: add test_zswap with no kmem bypass test Domenico Cerasuolo
2023-06-21 15:35 ` Domenico Cerasuolo [this message]
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=20230621153548.428093-4-cerasuolodomenico@gmail.com \
--to=cerasuolodomenico@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=ddstreet@ieee.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=riel@surriel.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@google.com \
--cc=shuah@kernel.org \
--cc=sjenning@redhat.com \
--cc=tj@kernel.org \
--cc=vitaly.wool@konsulko.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