From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44F6F1BE85D for ; Fri, 16 Aug 2024 21:22:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723843359; cv=none; b=tw3G6b4LHP4rKwSD8wzzPEHnHcn2K8vqWb8ZDdqLDORScQKM88MIyeN5sjJubCaiUoWaUBH2iKzx2Iz0joCUuMAubJ2iOP0mkbeqR1gOZg/cXZUCtvB76qT/9tjN/bwBJIsxjZrcMdtxAaKAVonRhCesLe7SwMs1sNXOuvpe9yg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723843359; c=relaxed/simple; bh=IKcyT/5FrG9PgC6aZ6MAkyhwt+dq4HvH3HTo8C0ae1Q=; h=Date:To:From:Subject:Message-Id; b=hcLEM5jA9JIX2/VwcIDRT2IrQfwaYFSOEbKggmApNa4ukaqw1qaM2khjyuUMARFgm0EsdNkTjx/Hc0mXLdkZx7e+MGZOq3YuSUZXuQ4hAdeteTxz+Wwmy7cR9/04VPmFmkk1RCQ93+7PNbhFPJoFHvFwluMbwHmO8oxRgbzFsW4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=MnYqq/6N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="MnYqq/6N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEBCDC32782; Fri, 16 Aug 2024 21:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1723843358; bh=IKcyT/5FrG9PgC6aZ6MAkyhwt+dq4HvH3HTo8C0ae1Q=; h=Date:To:From:Subject:From; b=MnYqq/6NANfR0oUqryCOUrw9TA79uVnyjZ2sVklAkvNK57TzsCTOnMKmVoaBo0jWy ME1x4gMaS5lI/8ZSrL/+RKmWFGGUWQ+oFYuLj5p8d5CsWr5fxis6EN3F0Decogc8Kt wprArpSw/7OLfUC7kCr+GP2pAW5A6rc/4HeIiTO4= Date: Fri, 16 Aug 2024 14:22:38 -0700 To: mm-commits@vger.kernel.org,yosryahmed@google.com,shakeel.butt@linux.dev,roman.gushchin@linux.dev,nphamcs@gmail.com,muchun.song@linux.dev,mhocko@kernel.org,hannes@cmpxchg.org,me@yhndnzj.com,akpm@linux-foundation.org From: Andrew Morton Subject: + selftests-test_zswap-add-test-for-hierarchical-zswapwriteback.patch added to mm-unstable branch Message-Id: <20240816212238.AEBCDC32782@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: selftests: test_zswap: add test for hierarchical zswap.writeback has been added to the -mm mm-unstable branch. Its filename is selftests-test_zswap-add-test-for-hierarchical-zswapwriteback.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-test_zswap-add-test-for-hierarchical-zswapwriteback.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Mike Yuan Subject: selftests: test_zswap: add test for hierarchical zswap.writeback Date: Fri, 16 Aug 2024 14:44:19 +0000 Ensure that zswap.writeback check goes up the cgroup tree. Link: https://lkml.kernel.org/r/20240816144344.18135-2-me@yhndnzj.com Signed-off-by: Mike Yuan Cc: Johannes Weiner Cc: Michal Hocko Cc: Muchun Song Cc: Nhat Pham Cc: Roman Gushchin Cc: Shakeel Butt Cc: Yosry Ahmed Signed-off-by: Andrew Morton --- tools/testing/selftests/cgroup/test_zswap.c | 69 ++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) --- a/tools/testing/selftests/cgroup/test_zswap.c~selftests-test_zswap-add-test-for-hierarchical-zswapwriteback +++ a/tools/testing/selftests/cgroup/test_zswap.c @@ -263,15 +263,13 @@ out: static int attempt_writeback(const char *cgroup, void *arg) { long pagesize = sysconf(_SC_PAGESIZE); - char *test_group = arg; size_t memsize = MB(4); char buf[pagesize]; long zswap_usage; - bool wb_enabled; + bool wb_enabled = *(bool *) arg; int ret = -1; char *mem; - wb_enabled = cg_read_long(test_group, "memory.zswap.writeback"); mem = (char *)malloc(memsize); if (!mem) return ret; @@ -288,12 +286,12 @@ static int attempt_writeback(const char memcpy(&mem[i], buf, pagesize); /* Try and reclaim allocated memory */ - if (cg_write_numeric(test_group, "memory.reclaim", memsize)) { + if (cg_write_numeric(cgroup, "memory.reclaim", memsize)) { ksft_print_msg("Failed to reclaim all of the requested memory\n"); goto out; } - zswap_usage = cg_read_long(test_group, "memory.zswap.current"); + zswap_usage = cg_read_long(cgroup, "memory.zswap.current"); /* zswpin */ for (int i = 0; i < memsize; i += pagesize) { @@ -303,7 +301,7 @@ static int attempt_writeback(const char } } - if (cg_write_numeric(test_group, "memory.zswap.max", zswap_usage/2)) + if (cg_write_numeric(cgroup, "memory.zswap.max", zswap_usage/2)) goto out; /* @@ -312,7 +310,7 @@ static int attempt_writeback(const char * If writeback is disabled, memory reclaim will fail as zswap is limited and * it can't writeback to swap. */ - ret = cg_write_numeric(test_group, "memory.reclaim", memsize); + ret = cg_write_numeric(cgroup, "memory.reclaim", memsize); if (!wb_enabled) ret = (ret == -EAGAIN) ? 0 : -1; @@ -321,12 +319,38 @@ out: return ret; } +static int test_zswap_writeback_one(const char *cgroup, bool wb) +{ + long zswpwb_before, zswpwb_after; + + zswpwb_before = get_cg_wb_count(cgroup); + if (zswpwb_before != 0) { + ksft_print_msg("zswpwb_before = %ld instead of 0\n", zswpwb_before); + return -1; + } + + if (cg_run(cgroup, attempt_writeback, (void *) &wb)) + return -1; + + /* Verify that zswap writeback occurred only if writeback was enabled */ + zswpwb_after = get_cg_wb_count(cgroup); + if (zswpwb_after < 0) + return -1; + + if (wb != !!zswpwb_after) { + ksft_print_msg("zswpwb_after is %ld while wb is %s", + zswpwb_after, wb ? "enabled" : "disabled"); + return -1; + } + + return 0; +} + /* Test to verify the zswap writeback path */ static int test_zswap_writeback(const char *root, bool wb) { - long zswpwb_before, zswpwb_after; int ret = KSFT_FAIL; - char *test_group; + char *test_group, *test_group_child = NULL; test_group = cg_name(root, "zswap_writeback_test"); if (!test_group) @@ -336,29 +360,32 @@ static int test_zswap_writeback(const ch if (cg_write(test_group, "memory.zswap.writeback", wb ? "1" : "0")) goto out; - zswpwb_before = get_cg_wb_count(test_group); - if (zswpwb_before != 0) { - ksft_print_msg("zswpwb_before = %ld instead of 0\n", zswpwb_before); + if (test_zswap_writeback_one(test_group, wb)) goto out; - } - if (cg_run(test_group, attempt_writeback, (void *) test_group)) + if (cg_write(test_group, "memory.zswap.max", "max")) + goto out; + if (cg_write(test_group, "cgroup.subtree_control", "+memory")) goto out; - /* Verify that zswap writeback occurred only if writeback was enabled */ - zswpwb_after = get_cg_wb_count(test_group); - if (zswpwb_after < 0) + test_group_child = cg_name(test_group, "zswap_writeback_test_child"); + if (!test_group_child) + goto out; + if (cg_create(test_group_child)) + goto out; + if (cg_write(test_group_child, "memory.zswap.writeback", "1")) goto out; - if (wb != !!zswpwb_after) { - ksft_print_msg("zswpwb_after is %ld while wb is %s", - zswpwb_after, wb ? "enabled" : "disabled"); + if (test_zswap_writeback_one(test_group_child, wb)) goto out; - } ret = KSFT_PASS; out: + if (test_group_child) { + cg_destroy(test_group_child); + free(test_group_child); + } cg_destroy(test_group); free(test_group); return ret; _ Patches currently in -mm which might be from me@yhndnzj.com are mm-memcontrol-respect-zswapwriteback-setting-from-parent-cg-too.patch selftests-test_zswap-add-test-for-hierarchical-zswapwriteback.patch