From patchwork Fri Aug 16 14:44:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Yuan X-Patchwork-Id: 13766405 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 22B0AC531DC for ; Fri, 16 Aug 2024 14:44:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A250C8D0083; Fri, 16 Aug 2024 10:44:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D8998D007E; Fri, 16 Aug 2024 10:44:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8764C8D0083; Fri, 16 Aug 2024 10:44:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 68A088D007E for ; Fri, 16 Aug 2024 10:44:28 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D0B27C1B4C for ; Fri, 16 Aug 2024 14:44:27 +0000 (UTC) X-FDA: 82458379374.29.E79BCCC Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) by imf08.hostedemail.com (Postfix) with ESMTP id 0C39B160011 for ; Fri, 16 Aug 2024 14:44:25 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=JjTQLGGi; spf=pass (imf08.hostedemail.com: domain of me@yhndnzj.com designates 185.70.43.17 as permitted sender) smtp.mailfrom=me@yhndnzj.com; dmarc=pass (policy=quarantine) header.from=yhndnzj.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723819429; a=rsa-sha256; cv=none; b=3LF1nu0MyH9gWaAVvLchrJ4Qs/PlM8efB/OPvMvQf6xbLNUcr7cQRtzDBp63/xSE19ldMU l9vIplcxRi+u+yiySWtARUMsSbglXm/d1Hn7WgE9q5XIGSnUsmJML0IFyGUzP7E5JfUkig G5H7O8TVH39aSceKmGHeiy2oMsTskpc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=JjTQLGGi; spf=pass (imf08.hostedemail.com: domain of me@yhndnzj.com designates 185.70.43.17 as permitted sender) smtp.mailfrom=me@yhndnzj.com; dmarc=pass (policy=quarantine) header.from=yhndnzj.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723819429; 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=Gc1o9cTUJaR+h1yUcosk0h+kJQ8Gs/QU31qzG4T87Rw=; b=26+5atW7otJDfVqfOfI95EjiNNjH34p1txj1SrPEB4lCmd8Em81ZxBdTCWw2yrxoVtFyhJ Jl05Kher97XUoYtQhxe93pIisI2C9H9nV2g2xyFWpiRevUImvwdnW+R/PgTsJ+SnqR89Ss XC0Ycj0ayw+rMBS+j7rpO2ItDVph+kY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yhndnzj.com; s=protonmail; t=1723819464; x=1724078664; bh=Gc1o9cTUJaR+h1yUcosk0h+kJQ8Gs/QU31qzG4T87Rw=; 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=JjTQLGGikdm9o1KJKl5Wy2RXkAkVAlk2WRhuTLS+tj2GTKMACiDWbyLVz+xj5DUeF yt7pXmuEFlIYlNMzMEg+cGwYiWqMA5qAVlTITTF0XKbIQ5bKA536tY8eJOBysCVcOX iN5TQTWzMmSQgFJToxGs+tVNbJ08ko0Y4HgUhpcj+UMfQm9nQS22iX+BCZH5wp4eMk wIX232jFNlAit5iD1RqUbaV/x3J/sHvB3eCWXkh3NMFfWfkgRXfoTB/2t3P8WKlZ1w Yq2ALMWShSWVJdsLoOgTvMveUsPrV5ghncW41HIkScRxSTa9hu+b4iqTc4Lt6SmpHN awwDbuBpyTBzg== Date: Fri, 16 Aug 2024 14:44:19 +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 v2 2/2] selftests: test_zswap: add test for hierarchical zswap.writeback Message-ID: <20240816144344.18135-2-me@yhndnzj.com> In-Reply-To: <20240816144344.18135-1-me@yhndnzj.com> References: <20240816144344.18135-1-me@yhndnzj.com> Feedback-ID: 102487535:user:proton X-Pm-Message-ID: 98424e4be63cbb1cd3dc1512fd5d74a155ca5d44 MIME-Version: 1.0 X-Stat-Signature: ms4dqjna719w1qh5w57nketejw1fw3z1 X-Rspamd-Queue-Id: 0C39B160011 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723819465-236133 X-HE-Meta: U2FsdGVkX1/YKBXbL7sAnViWgc5qWdTPKO/bxjeN566JnRnN49LnFd5bJKZ3Mpyr9Z9BZPiEOB6jnjdYcygnL44u2nDOA/8B54kjhqtun7kWjMMh26OY2qkGNvGaGwQQeGzfCHqlyV6ON0RYpLStrZYHLMCREqeSlWHup40ytV8w4NItoTo+GjFViotxBybFbN7CCXxkPCHG25EpJE91DayEEQurNX28Kz61Ah/heJk+OGV0hWGYFaabG5ym/v+kzvRjOWaDSLUZUTbdxPBeitOZhbIF+dFWDKyvLTK7ysP2/Sig6EpKhikzpwHLEyD6ZcshTA4UYQ2jAebOTWWqIdt822NO/f8UFiWWr7DB467JHHj1UAo5dc+nuV0rCJTgiYX2TCnGVYcx56T4Hm174wMHKc77tSZigCvotMCwdbU8gFcBoMKGQhPOoA7hU2PSyVa9K594BjJV3JBWQIdEUes/9jMeOlFMyWaioHMvFEt7uKqjWEvOJizF/Vum4IWyVg3kwdwg8fUy9vSk8KGTUbabUq6l193FRHCJRa91rpZxBvMmpc0jnIdJc5UMalAFMGdty4kop+NQ5fJXZoEkFBd3rNxbD5e7xAcCKXirgh0QH6vGQiEkmb3q9baWykXRVMYfx6JRXD/sx5jSi3AGWOZ99CRpxYzXiNvB/rD2c4aMFKsGB4BW5xN7zpNdfU9mJy6rA0dZxnahN6E7IGc1bbiWP1TUE9DHXM0txt/uDbRLpY7M5otlKkqA/KSIUUzp1whpw4+PXuUmI6XCPcl8FW8kH1ZEjBI5x12YpvK1BvcQsbDBP0vvnWsiyOoR1WCmNohQryuAsNraiBgcvxj0zQo0lvPcILaHfK5UEv3qoxFDAwFxtr+XOvT4nEzLsFUOqTjRAK0VOwNA5SiRXmtqZy4ptooqxc/UtC7eccO9EZkG7B8Zz9pzohoza6vrcm+OW8ag7I6aX+JTk430TvG i1NjsDfm JIClcYgcfCi62byLw3sYjnvhfPtML438cKd/5bkBnZkGl0WfPIczi3c7g9RHqsFsH6HoY73Rb4Ix5cPKUcrcuWu/28cEm69HEFeP7N8rHwtDxUlZRoJrFmc1Nn5VBYP+JxLEyVMXL+MWu/Or1Osfm3xGMuXbd/39gWHYH6ksIYtLnY4GArVPy7U0Y1wX7uftkbRvauqV0e4F0sg9XeTCntuQZ5wX1oSj0+euMpVJXEFGWEKERBjLtg3sQ3AiOuOIiSu5BqtR6QDpnAK4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000012, 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. Signed-off-by: Mike Yuan --- tools/testing/selftests/cgroup/test_zswap.c | 69 ++++++++++++++------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c index 190096017f80..7da6f9dc1066 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,38 @@ 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; test_group = cg_name(root, "zswap_writeback_test"); if (!test_group) @@ -336,29 +360,32 @@ 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)) + 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;