From patchwork Wed Aug 14 17:20:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Yuan X-Patchwork-Id: 13763765 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 EC26AC3DA4A for ; Wed, 14 Aug 2024 17:21:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 867D56B0092; Wed, 14 Aug 2024 13:21:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 817EC6B0093; Wed, 14 Aug 2024 13:21:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 706126B0095; Wed, 14 Aug 2024 13:21:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 515876B0092 for ; Wed, 14 Aug 2024 13:21:04 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DB2FB1410B3 for ; Wed, 14 Aug 2024 17:21:03 +0000 (UTC) X-FDA: 82451516406.10.CBE1B40 Received: from mail-4323.proton.ch (mail-4323.proton.ch [185.70.43.23]) by imf14.hostedemail.com (Postfix) with ESMTP id 7C30110000D for ; Wed, 14 Aug 2024 17:21:00 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=rX0Hz9+x; spf=pass (imf14.hostedemail.com: domain of me@yhndnzj.com designates 185.70.43.23 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=1723655990; 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=IgZ7iXb0VplK9LNa2MsWb2FY183hnDcwKBS1+wCHqWU=; b=C6Zd1MHlcU1xF+RvrNtuAoDk/JmBoWlZzJnI1doMpudA9CJ4lN+h8wFjlWRbExNCqk56Ok ahXRyTxf56jI0sF80BUPhl/ggoYKaOK2nJhFGagNNR1tVp3tf1PpzY8z1PeFM3CH2U9xVE bK9Bt/CeoPyA0ucHNWoEijxP3LWbWLk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723655990; a=rsa-sha256; cv=none; b=qJ5taW9NI9YAvae8e07217TbNaJxsyvAe1rtVV5zmgD57g+bYsnGohKpTOS9uq+NPrDBat TM2UK/RTMh1M8uLE3o51NEG+Jx8PXftqYRCLGHGolPSX8WNnVzUnElGqBKQ+EA+8vkq1pH qIIKzJGkAKEzZAwQTfNPVoaCw4hW/e4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=yhndnzj.com header.s=protonmail header.b=rX0Hz9+x; spf=pass (imf14.hostedemail.com: domain of me@yhndnzj.com designates 185.70.43.23 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=1723656056; x=1723915256; bh=IgZ7iXb0VplK9LNa2MsWb2FY183hnDcwKBS1+wCHqWU=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=rX0Hz9+xpmgIMUX2RhrFnScChBoAd+veIg6XS7a0ra8P/29v+kwF5Sst8pVelnspP gTV3bmKGNI+6A6DG9Q3YfgfEpmSB+FuW3jCsDxwqf927kgqteRdYmD9Lh7qGDdPqj2 YCzOh8qvPHJa/EKDeMu9NSSLWbw0hTkUifMSw6cdOP1amBg7eBgSybrG09xfWc8ir+ m75d0ZebHQivD8kuz+X/6t9bsqPUN6AgW6M6kgS+dSbN4VFxeBY7vEGYWzr9t+nhqQ U/AaoQnWum2NzNyEw17V8/y2wHIS1mMd2nC9kRO5trqpVUWNnGZ8ZoEuwckMDZTKWB /vf2P2I9wUunw== Date: Wed, 14 Aug 2024 17:20:54 +0000 To: linux-kernel@vger.kernel.org From: Mike Yuan Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, Andrew Morton , Muchun Song , Shakeel Butt , Roman Gushchin , Michal Hocko , Johannes Weiner , Nhat Pham , Mike Yuan Subject: [PATCH] mm/memcontrol: respect zswap.writeback setting from parent cg too Message-ID: <20240814171800.23558-1-me@yhndnzj.com> Feedback-ID: 102487535:user:proton X-Pm-Message-ID: 969223f01f1ac371f277dee78cd59a00649796cc MIME-Version: 1.0 X-Rspamd-Queue-Id: 7C30110000D X-Stat-Signature: qds3a1nqmd8bp3gbdu9e1mchgptcikbz X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1723656060-131809 X-HE-Meta: U2FsdGVkX1+nOZt4UQsQ7kyOPhjWf5Eu9GWYLPIBsdTZ+0nZc56dA/QFXRWdrkiW9yNbseWKOR8enpWQwvMiWnTPevj1soYWHCCH4VaXQCh3pVdfzH+AJYzZXDKoejcUpmqD3ZpT9kwTlutqlwZoe9ESMeIZdBYjBpC29unCuqxKLtX9zOx7ITZvqqfkGG3Qj6x5Vs0zRJ7WtAtk2oKHTkdzcCi2a+ykWT9ZaUA72cCjMFaHNlTl2J4H2jlN4FeIMWSqgiy6avdbwsTpLhQN6fZjd8w5Br7aqqx7NkAG8BXkltwQdxE6F7Ps2JwFjS3hc/bofwvKy4ogOBvXNRXsbgWLNRpIBSIumZRmuDPQUvAXCBwrswzMHuVdBFvMllSosKBaMEyr8CWBwfLpVPtwyuZXoCEVhNXgOIzeJYIZNqxQlSy3NdXItVwEOHRrUy5Cxjvb5xRWC07Y0XPf/q6yGy62I/L/zAgKJMHrP9EuKuFb9YbzScpWSY2WjsHF6YAXtdCyE+5PcHpVORIoOKbvUTsGbegEEhIK9eSUVqR+yAmvyWsDQAeAF4SZmeJud1ll/yrIh1EvFIlOeOc1kyfBtp3CvZEZMld05mMX4JlV1gc2TGcFufbT+T6kvVeBSkToejpO6QRGHLbQLeSOrWY+5Jo+0DpfLB/sGpRYZWAKSFBGWc5jN/DUWej5Pt7aMnRaV1JY8ZBdRXmOyP0/WLZTDgflLxOXOX/z0oP1Eby7+Y6y8reHECV95mhQOUcqCKw+Yw1GC4QOgN/2wb5AnGoZA3ycaMV1bxzzlu6Ynz9VO5qCVMtLNZJBOxWK+Tt7mocCpVV96pGjsQdPEztVKhLkc3/jNSB5vvJNwG0N/DfBTQZoBL5Hmn3jouR4KYpiRGWLowmC81K7MqpNpZqSC/gTMjTEl7c6XSnR31mn31r3XN+keHpfVTHG5bVQUJNb+Dv0W053YfT91rEZakkVXz+ C8now5wh w3W2mKLUYMrwMYquorNNV2w/QkF519X+mcha1rbt1+1A46ITYJr+YholZ9l0bRPnW8s0O18ODe8NWYuMUNO32W/dT2d3abO3/MZAzsygp39HmICMD/C7vGqTPSffDUyFPs3IK1Dq1EqtjTBvdoRbbPBSBITsl4mY6IGrxktTbIEH+0uqeQiWpAzunmj9kZhbaN66K8kH8g+ChdGZaHATdvU4T/vKYmrSVQIY88aA1ENFfXJe79xk2p609bKGpf8zbPICOWCHuYPBMnWIZvuE8Rp29+2raXtVpKdS7SdaWqHehpKI= 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 consistency 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 inherit 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 Signed-off-by: Mike Yuan Reviewed-by: Nhat Pham --- mm/memcontrol.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 8f2f1bb18c9c..2dcdaaf358ce 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -8423,7 +8423,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 !is_zswap_enabled() || !memcg || READ_ONCE(memcg->zswap_writeback); + if (!is_zswap_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,