From patchwork Fri Aug 16 14:44:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Yuan X-Patchwork-Id: 13766404 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 0B7D7C3DA4A for ; Fri, 16 Aug 2024 14:44:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89DAF8D0082; Fri, 16 Aug 2024 10:44:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84DD88D007E; Fri, 16 Aug 2024 10:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EEAA8D0082; Fri, 16 Aug 2024 10:44:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4F5D88D007E for ; Fri, 16 Aug 2024 10:44:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E16381A1C64 for ; Fri, 16 Aug 2024 14:44:19 +0000 (UTC) X-FDA: 82458379038.14.3952203 Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) by imf30.hostedemail.com (Postfix) with ESMTP id 42E0180019 for ; Fri, 16 Aug 2024 14:44:15 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=OfGzmRg7; spf=pass (imf30.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=1723819382; 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: references:dkim-signature; bh=d31/1askkQWIiO9ejP6OOS7hCzAz8Xh2PnZ0tdJxyps=; b=ZXeAv7HKom3GuJYDOp0Su9cmSw7FmDAjKvrTOcHdGvsqWKJf9fAXtHVmk2jw+SBWPjkWGE flP+1sHaqaLmKR6pgPotThRUkdafWuwgT40A23KbfPX7N1iU8wjbZQClWm1RYjfAvS419X yuQgZaFij50zN6HGJNNaFFeRLH6rdGU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723819382; a=rsa-sha256; cv=none; b=adA5h15yQLb7JtIJl7lCWT0ik11voMEJKyqeqWYgHCFKqQgwnkQU9nchsxLp9RatqwRTxm nzsTjAB5xVtop8xdhmuQpnrhmLa7xkDm8fp3O7MtWD4VJ8VldoknuzGXeZgr8jRV+7yX+r n4S3FBYtCMHTbm1iDOCsRzdDBv3vRHM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=OfGzmRg7; spf=pass (imf30.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yhndnzj.com; s=protonmail; t=1723819453; x=1724078653; bh=d31/1askkQWIiO9ejP6OOS7hCzAz8Xh2PnZ0tdJxyps=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=OfGzmRg7R/S8KDBfXeTlcbpe4PtSI81sM7m/uKiFEtMVxactPM2OJef+iv67P6lc8 wEniqvP9+c87GFkscBq9ulGOTF6VSWrNsasSSjSMavwtYSL+ZAzSMQg/jq9ffq+uXg ah+by0+3p4FiJy0DGifvCQvEPl7PiOvJUb5KBs6JKrZCpMt0dB0j8678TZz/2UUEcO K5bGhm6/Wukq6Yxwdmde8/1xwdIMrNnz/sZgttxFvdsQZGtNdQbkRGI9r6nHUrPwbo btmllxS1++tGNgFRracVBorrrz+Huk4KM7yr7UAuXMOwR4GaQrbkxCwj4biYsTFzKR GMNLQVVNo3rqQ== Date: Fri, 16 Aug 2024 14:44:07 +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 1/2] mm/memcontrol: respect zswap.writeback setting from parent cg too Message-ID: <20240816144344.18135-1-me@yhndnzj.com> Feedback-ID: 102487535:user:proton X-Pm-Message-ID: 9c7b4dfd44ee35e2926420d9f191edee1ce7950e MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 42E0180019 X-Stat-Signature: 5tszwm7c1zbt66e66swmypkqhs9pnpe7 X-HE-Tag: 1723819455-712828 X-HE-Meta: U2FsdGVkX1/9SGWyOxM0oSF4yhyyVVB/9gSEqIz3i5a6N0puKLPS5L5/ofthiWAjQuiIINPZirIhj37xEuY8lBPWOAxYoo18T0NPgql7KhoogZWZQ7Yccx23fn4xLQ49ZN3MUu16KkATogx1fu0KWGmjpC/qvZa64Cs0i/GfXVhzAG75o6YEnc5seH4p3ykinaQYfppElStmrJIpwvTbUDo7YUhqUasoQ1mfyjh0iTItAzP+QWFKlNXmZHKWjUlphlWFdD/6iHkjEpEZiRV/YIA3xPpQRD5dCizdinEoWBPgcq3AspVXt5wt/6qFCiLrvUKZsB56FxtuTyi9e9r6cQ8x93UPl5IhEQLRk4i03W8u+UOUS/mvs3wLyqirBcaq2YU5HE2eXCGIZXPUWRSkEG9EMLJAt0DaxlVPvMLc1mh+9TSy6jlA+dDGPCohiwTl5p+IUOkJNeXvjbtSMcI/fE7cAg7V975CCJRPs+njfuKOWz/uJoy+FTtK5FWxEVHUBaj1IxtuOY53+evVyW4R33ZCmzhFLrTlf0yXnMBnpP/CfX5st/O4LTWgHwC3fp++FZRKd9LlfXHSlll8hIsm/AEO7hpRTWtbqUjJVKO83pQkMbbbRpcd1DZjQ+70T2zWmaXc/wrOCr8KjdsW1ILmsewGXlk59gmQHoULHOBcNjFG8CEQdLwIQuYOpUUpyDIVnyL4GEFrGaoPPz0N/0JGPFf5Jh3h/+NOautZuHK8ohXo6sLXx7lxdAExqQ8nKf8krkP+agFKhF2RDNXpikiwYTZ7HJjhW+5HN8Fm/vwh2W2Y0b8j3+HvVyz7mHChsgtr5ttVZNi5N199lt07Gw24ofK+HKz+gUNZKYrPUGbArJLGA0O/hjkG0rSpxZFkBu28qFWastbzac0//LXsReDmPtaOm0jL6txc+LSuAzxuoetAnA/HroRHullxZ7EfBi0ZA++prJzeIGbym4UTwtc AjR5UD8f +cMcCO5/DAqMqDRKRbKsaUNQF2wl8h7TKhLOAuvCo+rK/TKsjFN+1HoGV15jT55t++6WIwqK+2d4SswWOaJ/E4mJx48ZQZ9FTeYT0UXwUzEsvErTZZSlrfLY80ytp9HxpU5BF6p1x8cuGxhXwCmGm87PD2u4FRHHe82LJ5stAJY5jtF6GMkyFbW8nSzpFbU7yyCL7uPPybu/To81t1FM2Za7O9qCbCocT8fueL4rZ+7kFmB5FnqUjh3KWIfEMx7y3tRv1f5RbEWqXLbXgLClFPt0K1KXKxs2e8TkRbXBkdsM0Np22nue/ZQMntOl/ZbeontF91Nyf4Ena7dwRdbDDsDYjrZY1SXSEjlHwmDwcGiqQtN6Q6kkbqW6DCTZLs2ZOzex6gM9DQM6SBCVS0XyD1/QmxJ0Ebc0vSPv5qwuxTwEYPyg1R3Ut1hygj5dE4EeebxZPKmu5AQjRuHq38FMDBwC+TaAElWNb5uVXV4+gr5CYWy8ykX6NvpqlwWkwGj4gR0UyfEAzP01bVAyjl1kEkR84Sw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Currently, the behavior of zswap.writeback wrt. the cgroup hierarchy seems a bit odd. Unlike zswap.max, it doesn't honor the value from parent cgroups. This surfaced when people tried to globally disable zswap writeback, i.e. reserve physical swap space only for hibernation [1] - disabling zswap.writeback only for the root cgroup results in subcgroups with zswap.writeback=1 still performing writeback. The inconsistency became more noticeable after I introduced the MemoryZSwapWriteback= systemd unit setting [2] for controlling the knob. The patch assumed that the kernel would enforce the value of parent cgroups. It could probably be workarounded from systemd's side, by going up the slice unit tree and inheriting the value. Yet I think it's more sensible to make it behave consistently with zswap.max and friends. [1] https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Disable_zswap_writeback_to_use_the_swap_space_only_for_hibernation [2] https://github.com/systemd/systemd/pull/31734 Changes in v2: - Actually base on latest tree (is_zswap_enabled() -> zswap_is_enabled()) - Updated Documentation/admin-guide/cgroup-v2.rst to reflect the change Link to v1: https://lore.kernel.org/linux-kernel/20240814171800.23558-1-me@yhndnzj.com/ Cc: Nhat Pham Cc: Yosry Ahmed Cc: Johannes Weiner Cc: Andrew Morton Signed-off-by: Mike Yuan Reviewed-by: Nhat Pham Acked-by: Yosry Ahmed --- Documentation/admin-guide/cgroup-v2.rst | 5 ++++- mm/memcontrol.c | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) base-commit: d07b43284ab356daf7ec5ae1858a16c1c7b6adab diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 86311c2907cd..80906cea4264 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1719,7 +1719,10 @@ The following nested keys are defined. memory.zswap.writeback A read-write single value file. The default value is "1". The initial value of the root cgroup is 1, and when a new cgroup is - created, it inherits the current value of its parent. + created, it inherits the current value of its parent. Note that + this setting is hierarchical, i.e. the writeback would be + implicitly disabled for child cgroups if the upper hierarchy + does so. When this is set to 0, all swapping attempts to swapping devices are disabled. This included both zswap writebacks, and swapping due diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f29157288b7d..327b2b030639 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5320,7 +5320,14 @@ void obj_cgroup_uncharge_zswap(struct obj_cgroup *objcg, size_t size) bool mem_cgroup_zswap_writeback_enabled(struct mem_cgroup *memcg) { /* if zswap is disabled, do not block pages going to the swapping device */ - return !zswap_is_enabled() || !memcg || READ_ONCE(memcg->zswap_writeback); + if (!zswap_is_enabled()) + return true; + + for (; memcg; memcg = parent_mem_cgroup(memcg)) + if (!READ_ONCE(memcg->zswap_writeback)) + return false; + + return true; } static u64 zswap_current_read(struct cgroup_subsys_state *css, 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;