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/mvs3wLyqirBcaq2YU5HE2eXCGIZXPUWRSkEG9EMLJAt0DaxlVPv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qlwWkwGj4gR0UyfEAzP01bVAyjl1kEkR84Sw== 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,