From patchwork Fri Aug 23 16:27:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Yuan X-Patchwork-Id: 13775538 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34EF2C531DC for ; Fri, 23 Aug 2024 16:27:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA0B8800B2; Fri, 23 Aug 2024 12:27:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B29E2800A4; Fri, 23 Aug 2024 12:27:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CC24800B2; Fri, 23 Aug 2024 12:27:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7D477800A4 for ; Fri, 23 Aug 2024 12:27:18 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1D111C1DFB for ; Fri, 23 Aug 2024 16:27:18 +0000 (UTC) X-FDA: 82484040156.10.FD659B9 Received: from mail-4323.proton.ch (mail-4323.proton.ch [185.70.43.23]) by imf27.hostedemail.com (Postfix) with ESMTP id 2A0A440011 for ; Fri, 23 Aug 2024 16:27:15 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b="FJCEeAV/"; dmarc=pass (policy=quarantine) header.from=yhndnzj.com; spf=pass (imf27.hostedemail.com: domain of me@yhndnzj.com designates 185.70.43.23 as permitted sender) smtp.mailfrom=me@yhndnzj.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724430344; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pPXe71q6zQu0gR03S4i42QC6rYTNhfx/AM5wdnFWiQA=; b=NMu8VoEsEMHh3DyuScEpUirq0X6EKT4A55y8uJ0+z/Md7IBAH2ZGMBtSQ54vW94/iG7K6L R8Yn4T4ZFVnwK3SwYGCqeF8182SMhxzWqLSJQnQSnSfaI+NYNoYKWLujAEWIkOMTeJzPgd jZcTvbjfzmEEkOWLm7s+SBKXOjIAiVU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724430344; a=rsa-sha256; cv=none; b=zW2DObWia0RPIKI9N7pEMpikYxsbtEIHO/QaSXikPYbQrXDRJouT7wqCLKZrFRCUOW4fBa XvRnJTUOdgc0PkORBNX7cT8cR3V282pHrk3UxA72HyISWVnl/NP3ZWwOO/FLQgj34K+OOA TSNu1tVZRv8itEosR3uLM9Jk1pQYyB4= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b="FJCEeAV/"; dmarc=pass (policy=quarantine) header.from=yhndnzj.com; spf=pass (imf27.hostedemail.com: domain of me@yhndnzj.com designates 185.70.43.23 as permitted sender) smtp.mailfrom=me@yhndnzj.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yhndnzj.com; s=protonmail; t=1724430433; x=1724689633; bh=pPXe71q6zQu0gR03S4i42QC6rYTNhfx/AM5wdnFWiQA=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=FJCEeAV/aa+vtVuUy1WGdECUAyqfATK7G2xjTJX0LpFlfr4g88ffgiVBfgvOlQ/Cq YjZGWPHpkgqxfdzFx3zMy4FEcROwykDQm6cf93oklMGIjN2DshieH126wQUK0qUKYL Z/ZRIeXAcKRikpnJ1onggF+6VVeis2kz1jiwyA8A13VW2WC6U9w7HCvqE7GxpbJ872 eA5xqJKaN8+uX8Dx0ka8wXgV7FPgy3HeGDvRAbQvNy9nEoPIfZ0U6QTIABzfDmQXNm Z1pi5U6GtrdsqORxW1cCiLrOWMkUHV6ptKT/M5IdXaOgRP8boKV3hKlWRRcA8spke7 mUzpcZ1zjSFuw== Date: Fri, 23 Aug 2024 16:27:09 +0000 To: linux-kernel@vger.kernel.org From: Mike Yuan Cc: Mike Yuan , linux-mm@kvack.org, cgroups@vger.kernel.org, Nhat Pham , Yosry Ahmed , Johannes Weiner , Andrew Morton , Muchun Song , Shakeel Butt , Roman Gushchin , Michal Hocko Subject: [PATCH v3 2/3] selftests: test_zswap: add test for hierarchical zswap.writeback Message-ID: <20240823162506.12117-2-me@yhndnzj.com> In-Reply-To: <20240823162506.12117-1-me@yhndnzj.com> References: <20240823162506.12117-1-me@yhndnzj.com> Feedback-ID: 102487535:user:proton X-Pm-Message-ID: 253c4c7b771f5dea02d28fcf54ec72ae63c6395f MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2A0A440011 X-Stat-Signature: kd3sdi1tsd4oqq47i1z5ephar6djdhks X-Rspam-User: X-HE-Tag: 1724430435-569912 X-HE-Meta: U2FsdGVkX1/Rn0OtzbjPro9sXN34/fdmoRx5bI/qmVbXpfzBIlBvcte+LYYrrUiwTPeXreArACIAkIfzSXDGg9ZkimnMRUaeXyfyQYN5w0skdHZ9jN5mk8qCs1/tMWv3RuHRZJZXk/ODHXtHADHQpumGzsSkszc8lf1Do/kVD1Wqq0JUXccJTHrfXUiYYREbtClyhRQAGtuOVCsjPdEsxw3d+GkERJ6Lzo+ZqUPUkPDFhDIeBZaYd9f7wEpyudbYNp9BaZi5hURh5VW2X99IWRHckLVqs8XFFlHXPyQ+5lH7MT/NUT7XDh9GQnlyCSzwzNWwxgX58FeIAGf78wlyNkm4kJkD8r4jQPdeXLn+Eq7ir2D/cFHHQGSbl1xOeQYhO4ngtKhSlSyKBjgFKXoZOoYheqOMXdaXNoersYfgh7gi5WpOFSwLe2hWFfIzO/rUFRjQMPLza+yrCX+W30fxPi8mhkTZTrXcDA1F2zUYo8nmqejlbDKq1U8uzGuw0BAArs4AdIrvsC4bGQ7EVnnUqSrpYx90ZK1szRpdGk09wPNkT5hd8jyqbmRXFBwdVZBpppzSdU4/D62d0gq18OC5vXCBTxS3vTWKnZ+O9WOB9Eq+0rNzrxWUbMxo/XHE1uoIi5viHfR13ZNy7BJ7g1S/wfBhDp9vXitEXhs1bRFjJHsVb0wll86TnnpHbVdtykGOFz7B2IGg4fy2LZFwXyJMyDg1/aObegbysHeIF/+fOI3O4XiI8t8dlBFg3AYLIYZCceN6pLznjtlq/V3GyskNabE5KHwUPvzFC/1/btiN39hm90eELpc5+w6USw0Y35w1rA7YYD2IArfDzBvA3P0JyXtWMuomTQrOVukmp7s0DNsbdI2DJiQgNO1azkIKA/7eva6lVGKBI4djbK0I4dLc3usSVGjBmyGGpHjcG6id3xjqacBTaFJOBQt412RC5NyNiS3N8kO2wz4MCs8Rcpa 7GGw4daK QD31NhVN0sPIdbjoeTwNpcDz1yb+mkbchUKmf+N4XFEearuajuSxaWog7RrdlRRkiYqI49pT5lTuyypAEQwZi7m3n4dWyU9KoBlaJeGRi4jf88JpV6dE5G9wOk4gFqzr31j+cIix9C0nsu4pMRGYcZNxfBTSP707xWxS6LK2no5tLKiFnBbJkDLehSAjlX8sIvXSt1ZwcR4nHqC0w7PRkdPZqGdGr35Z4B/yQp2nYOc2vMxnVKvwEbCunuPnlv9IzFoCQeagd7BcgttsmGMWqWPBGzsYxYFw1RmMu5JU9vDabldSu0vTy9a1FNKLQj9M1xA5BcpNUHq2pFVI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000161, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Ensure that zswap.writeback check goes up the cgroup tree, i.e. is hierarchical. Create a subcgroup which has zswap.writeback set to 1, and the upper hierarchy's restrictions shall apply. Changes in v3: - Skip the zswap.writeback test if root cgroup has it disabled (I still think adding a whole new test is a bit of overkill, though, instead came up with this alternative approach) - Add comment about hardcoding child cg's zswap.writeback=1 which might not be obvious Link to v2: https://lore.kernel.org/all/20240816144344.18135-2-me@yhndnzj.com/ Signed-off-by: Mike Yuan --- tools/testing/selftests/cgroup/test_zswap.c | 75 +++++++++++++++------ 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c index 190096017f80..40de679248b8 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -263,15 +263,13 @@ static int test_zswapin(const char *root) 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 *cgroup, void *arg) 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 *cgroup, void *arg) } } - 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 *cgroup, void *arg) * 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,41 @@ static int attempt_writeback(const char *cgroup, void *arg) 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; + + if (cg_read_strcmp(root, "memory.zswap.writeback", "1")) + return KSFT_SKIP; test_group = cg_name(root, "zswap_writeback_test"); if (!test_group) @@ -336,29 +363,35 @@ static int test_zswap_writeback(const char *root, bool wb) 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)) + /* Reset memory.zswap.max to max (modified by attempt_writeback), and + * set up child cgroup, whose memory.zswap.writeback is hardcoded to 1. + * Thus, the parent's setting shall be what's in effect. */ + 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;