From patchwork Fri Aug 23 16:27:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mike Yuan X-Patchwork-Id: 13775537 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 E451CC5321D for ; Fri, 23 Aug 2024 16:27:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D368800B1; Fri, 23 Aug 2024 12:27:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5834C800A4; Fri, 23 Aug 2024 12:27:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47236800B1; Fri, 23 Aug 2024 12:27:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 26946800A4 for ; Fri, 23 Aug 2024 12:27:15 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C6D9E120DC8 for ; Fri, 23 Aug 2024 16:27:14 +0000 (UTC) X-FDA: 82484039988.05.2EB59B2 Received: from mail-4323.proton.ch (mail-4323.proton.ch [185.70.43.23]) by imf11.hostedemail.com (Postfix) with ESMTP id A9E4B40006 for ; Fri, 23 Aug 2024 16:27:12 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=PMK7RTWW; dmarc=pass (policy=quarantine) header.from=yhndnzj.com; spf=pass (imf11.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=1724430341; 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=7LV5wuij5UHvq2TzSAXYR/Fp+ylFof5gSswrfbA2tBU=; b=B9efDXSSqCM9GSqY/RuxMk9JC/K/x5JLMp90POxNzL3sX3YTQdU2GhKfuN1s6MAZ1zGjff ui+ier/so5Y/UI2jSLT6241yQuc7WzRSeF+dTgPSAfxhDSp10fWIYnj2xr1hSve/HtsIky vtrlti4AuQIdmZxAn8G3K5bswdZw05c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724430341; a=rsa-sha256; cv=none; b=ibwz/w9QT9y6EmzyAe891hrAHn0lQwTbrJ/DVq8f0F3OqZvbBCERq/d83QukrMXhC1eldJ YRav+jsooMZI7EWLfSX6QGM2wbwpgutau88JvZj7ANTtyNNdwIkXVKljyAMe3QaLmMcnmP E+4EjaxJPSPPPZMdftyGlWwCm4E7d8A= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=PMK7RTWW; dmarc=pass (policy=quarantine) header.from=yhndnzj.com; spf=pass (imf11.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=1724430429; x=1724689629; bh=7LV5wuij5UHvq2TzSAXYR/Fp+ylFof5gSswrfbA2tBU=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=PMK7RTWWQ6HcUw0ixQgF0emg4ra1NhSx9KpxtrQMlLZYDWnFBZy0RQO1CwCmjCMQM OnmXPC9rN66VxdZYrhN3DKTzN4R+aIATv5/e9Y+eA3XhN7o/7n/WUm99K54f0Zro2+ n+VEfPQ4vl2CnM4RCh6qFXzfZSJkwrkHfFM46H01QfwvgAPY7GPMn+BMRyzfQR1anh QJtwfmfojLVv+CQ0DKU0Xkf+3/CTbaqJLJP6pygG6H+efzD49m6AfgSu0UjpdvuT+I VwiD9tCmdJVex+RBKf02uM5qASyWyHPvBP38SXprzDIo0iNEc3K29ltQOZ23schN7d zN915e3f1w1Zw== Date: Fri, 23 Aug 2024 16:27:06 +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 , =?utf-8?q?Michal_Koutn=C3=BD?= , stable@vger.kernel.org Subject: [PATCH v3 1/3] mm/memcontrol: respect zswap.writeback setting from parent cg too Message-ID: <20240823162506.12117-1-me@yhndnzj.com> Feedback-ID: 102487535:user:proton X-Pm-Message-ID: 1aeab9fed9e0166d41ca57d11d544d5490bc3859 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A9E4B40006 X-Stat-Signature: itrruh1xk3h73wkidxt8xn3yduonqa3s X-Rspam-User: X-HE-Tag: 1724430432-524369 X-HE-Meta: U2FsdGVkX19bQPAdXmneqsFT11WsAvMr+6MxIO80Egyi1ew3pTjVOi3Pv9nRmhJ46bKZoVaVITPUPddIVdYtC4ReAsgA2RrkFlzjqzxfSnu93BqAldKoITnrwJ2MlHBrJvEPKw2dY4+MFEGzXXVghMBYmUzlVYLNoFcHL0H3UA+h05q8+BuzEX/poU0EXneVIOnUA9PDA8FFtrfJeRbR//DD6Dm7jymKM98elCLGrsLFiJjjRAk8ctlz16/qGSkPtXLyDq2mTjKYvYRpIEJkAP0t9G2Dq9wFa7pbVMltE9Iqf66aJjFgPYiOHvLGwlNzWSkZ5BEzBX8xuefUSzVjPI+u/sa/iiSs7nGCVzHe8YkTkYDubT9jNxWvbXSICWeB/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HOzyWBL75jkxGvukFxJ6lSEmcCbe5DVPqqzH0M7JhzP7HzdnVNOaT72xtA+2GQ2JS4Y48rUv58QrbMuYyeGdbg+BeIXIlu5nvn/ev/s3yu8s7EbHbyf0olEcjVyAh9n6tDEQ3JqWi2QFnloAnUBPhc= 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 v3: - Additionally drop inheritance of zswap.writeback setting on cgroup creation, which is no longer needed Link to v2: https://lore.kernel.org/linux-kernel/20240816144344.18135-1-me@yhndnzj.com/ Changes in v2: - Actually base on latest tree (is_zswap_enabled() -> zswap_is_enabled()) - Update 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 Cc: Michal Koutný Fixes: 501a06fe8e4c ("zswap: memcontrol: implement zswap writeback disabling") Cc: Signed-off-by: Mike Yuan Reviewed-by: Nhat Pham Acked-by: Yosry Ahmed --- Documentation/admin-guide/cgroup-v2.rst | 7 ++++--- mm/memcontrol.c | 12 +++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) base-commit: 47ac09b91befbb6a235ab620c32af719f8208399 diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 86311c2907cd..95c18bc17083 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1717,9 +1717,10 @@ The following nested keys are defined. entries fault back in or are written out to disk. 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. + A read-write single value file. The default value is "1". + 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..d563fb515766 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3613,8 +3613,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) memcg1_soft_limit_reset(memcg); #ifdef CONFIG_ZSWAP memcg->zswap_max = PAGE_COUNTER_MAX; - WRITE_ONCE(memcg->zswap_writeback, - !parent || READ_ONCE(parent->zswap_writeback)); + WRITE_ONCE(memcg->zswap_writeback, true); #endif page_counter_set_high(&memcg->swap, PAGE_COUNTER_MAX); if (parent) { @@ -5320,7 +5319,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 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; From patchwork Fri Aug 23 16:27:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Yuan X-Patchwork-Id: 13775539 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 D6A87C5321D for ; Fri, 23 Aug 2024 16:27:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69781800B3; Fri, 23 Aug 2024 12:27:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 646C1800A4; Fri, 23 Aug 2024 12:27:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 535E7800B3; Fri, 23 Aug 2024 12:27:22 -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 280E6800A4 for ; Fri, 23 Aug 2024 12:27:22 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D8295A113E for ; Fri, 23 Aug 2024 16:27:21 +0000 (UTC) X-FDA: 82484040282.29.FF7264B Received: from mail-40136.proton.ch (mail-40136.proton.ch [185.70.40.136]) by imf19.hostedemail.com (Postfix) with ESMTP id ED04D1A001A for ; Fri, 23 Aug 2024 16:27:19 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=DQHbWinR; spf=pass (imf19.hostedemail.com: domain of me@yhndnzj.com designates 185.70.40.136 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=1724430357; 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=q54uHymsuuCJEUwRG3OoSXXb4G9nERztgFbdZCGsU1k=; b=l2lJMP12jcWH73AbhpasTJiX59W8SuQLVpHIrEQqXmLHiXoBuo4lCstH3hkwenFcotwJUd +v8qzobKueq66n0I8x7T+dWN3/WGrpfnMm6myiejTuq09o5inLFKPFzKqO1jcifcYEYM9G hGb7LojWJ30YM1k/Pn6VOFFYxSzgaqI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724430357; a=rsa-sha256; cv=none; b=ZBhsXSCjLwyXiGckJzCSw7YD9DxOW5npELWAuEW75ErCPSLkELj/1zoPT6Hr91tABH5opn LEVjFsyHqJncDxa9cMgIClQibIZokTA7SHydKNoOOG/BOK7zaqGVP4hjj2b3YrxdlE45n7 7OV5dHOze7fPrifY88df686esMWjMlQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=DQHbWinR; spf=pass (imf19.hostedemail.com: domain of me@yhndnzj.com designates 185.70.40.136 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=1724430435; x=1724689635; bh=q54uHymsuuCJEUwRG3OoSXXb4G9nERztgFbdZCGsU1k=; 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=DQHbWinRSf8CSE01rY0HlqkE38LF2s/U/brRHorICuBLyeylZpqxeaAgxSWjFF4Bk GzMcMuahFDfIY90587qr4QwIu0Qm/PZOnlvDfWMJporXBGgkzG+Xn0mA8PKjAu+9Us x0ppn3sJfYmNs9baC0DW+jm11o3S2HdS9wyH2hSj4qaR/vmJsHf9E0WCaQCDrVD9Jv elGMu0jSg3pn3KrMGO2UfyWmE0jaHb/To++mf7eX5rMWiOTW6qliZCz7uYCZvwz1o3 /G/RmNPfP8a2wZOx5w38D+DH27NBNp1caftLqeDNqnE4hPFJU/YSsQD1cPhDrecrH2 gv8yWTiimiHTQ== Date: Fri, 23 Aug 2024 16:27:11 +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 3/3] Documentation/cgroup-v2: clarify that zswap.writeback is ignored if zswap is disabled Message-ID: <20240823162506.12117-3-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: 9391cbe5faffb78cda607cff6563b688bbb16fc0 MIME-Version: 1.0 X-Stat-Signature: tcz6gcppq68ppk7w7aj6mdbkzqu76cc1 X-Rspamd-Queue-Id: ED04D1A001A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724430439-698287 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mSz4An/iTz4Hd+Rig1UnPUvqQPsbfAkPvi1s8HRpSgw74k9KDIUti+b0TIlsh5eBsQTRqgFbmHPeBu7F5INk5ydazP1kmBE6rHOPUrozKjOKMUnuSDvPKlFj5Ycn0r5SGWZIK7HTArU/0AL2g4awcB9F7ra/l9gQjE+dtDSY6m/km/gCPTEnmeKKrtdFRIUM27yiQn3unQx2rcrzyTKYAuSag1XlXPFTcYGYTTlrfZfr 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: As discussed in [1], zswap-related settings natually lose their effect when zswap is disabled, specifically zswap.writeback here. Be explicit about this behavior. [1] https://lore.kernel.org/linux-kernel/CAKEwX=Mhbwhh-=xxCU-RjMXS_n=RpV3Gtznb2m_3JgL+jzz++g@mail.gmail.com/ Cc: Nhat Pham Cc: Yosry Ahmed Signed-off-by: Mike Yuan --- Documentation/admin-guide/cgroup-v2.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 95c18bc17083..a1723e402596 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1731,6 +1731,8 @@ The following nested keys are defined. Note that this is subtly different from setting memory.swap.max to 0, as it still allows for pages to be written to the zswap pool. + This setting has no effect if zswap is disabled, and swapping + would be allowed unless memory.swap.max is set to 0. memory.pressure A read-only nested-keyed file.