From patchwork Thu Nov 30 19:40:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13474956 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 F3717C10DC2 for ; Thu, 30 Nov 2023 19:40:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E47C76B048D; Thu, 30 Nov 2023 14:40:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DF5FA6B048E; Thu, 30 Nov 2023 14:40:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C225C6B048F; Thu, 30 Nov 2023 14:40:28 -0500 (EST) 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 B60EF6B048D for ; Thu, 30 Nov 2023 14:40:28 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8D98DC029D for ; Thu, 30 Nov 2023 19:40:28 +0000 (UTC) X-FDA: 81515637336.18.CB07916 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf27.hostedemail.com (Postfix) with ESMTP id C68324000E for ; Thu, 30 Nov 2023 19:40:26 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ks0954qq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701373226; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wu5h2uK3efWNzQSn40V3SLhhxDZPSFSFXXaEbLeDNVU=; b=Mlm5UlwrBYPULHOvtOcFFytKkk8EoTv1GhoWexletb0f02wFd50UNF79yt3Nr5eWmRjRL/ tRfdyJOcreBrMooEZ+DlDFKSmL9eJLX/mOFaJ6VkMObL+7QjoUAC9SeLjwkSml+05isuqF drrMjqzcpLa8vSf8M6OIAVVonl8AEYk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ks0954qq; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701373226; a=rsa-sha256; cv=none; b=DiMt9mrR0v+fzOClAqAw1zEKpg7A6iIQgjQDaSe3+GykVltcLps9PLl82XvquW/+dRA0ct D5gvFwIGAYAC5JSmecQ/3cxIYDFkxsxBylxFougPi0SCjEnb73Be7MMdXTKqRF6/qwsNqR j2Y6HqAjl1fRI6ZzUfcYg4UxAM/3cQk= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6cdd13c586fso1268906b3a.0 for ; Thu, 30 Nov 2023 11:40:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701373226; x=1701978026; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wu5h2uK3efWNzQSn40V3SLhhxDZPSFSFXXaEbLeDNVU=; b=Ks0954qqRpADN8lp9so9dbbTJQu0FLqCVdh4qjTBG1Cq/Fpc4/GK63HUAgsZ/jd8Ct LGPMZrPbQNi0sGHLbuj6bhoJjkJHlYLISPvbJ6BYjQeAjukbnoUo4ZEi6mYp1V+6qgSJ nXN76wFYiWPR1ewlsrVfN6l3BKxMiDzThyZ7SgxQwbvuf9OaSLF2e9O4TS4XCduVppCX P89YPxSYbJxfMq+VW5qcAHEmABUP/uKDT999ylD8l2ZLdImQAwGL2omUBbigE7ZfqRgO RfVaCK/qs3H4sGksQGjU9xgicvwrvLqSMiqLsssOv4drNKQmmcpgXt9j5Grs3wgoo+5v +M2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701373226; x=1701978026; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wu5h2uK3efWNzQSn40V3SLhhxDZPSFSFXXaEbLeDNVU=; b=vQr4S35vjqSnTxtlFsiac/BopsFoASM6avBrLoIY16cbZBSvr9i/sk0UgdCHAIpR3w oOZt6r34JU3KsL6N6m9jlf+ocqr6mKb968A//hF6JfZOQXRVTFGlrRB+eI+8rVOCir80 ull67rs+yhPyr1pIpfsm9Rr06xpr7i97PqFhSIOlJBrylOS9OzI/RiWIos1F8eJFBPM6 Ul/PS+XE4VLJWd7XALDcN8bMfbKB79IvXXx2wIeAEL9f5lwUCw+dHMrGlB9ocl9Lcjlj YYB20o5fJ4kMgZFtKh53/5vOnwncS00y1Yr1QmztpBureJqdNNZRRpQq2FCK+pzr19aQ M1NA== X-Gm-Message-State: AOJu0Yy9s0nuC87N8uV3DgG34PxBaOx1/BJMXWYpdC2Cm/3dRQjgYQsv XzW82Cc8JEkJru+HT4K3od8= X-Google-Smtp-Source: AGHT+IHAYv2QywW+kJu67uQmw9fkTUq5k9I3OqO0/TQg0O7WFleUTQj+azK6qIpJqRZiFpj/7FBacg== X-Received: by 2002:a05:6a00:1894:b0:6cd:eb43:f1cd with SMTP id x20-20020a056a00189400b006cdeb43f1cdmr2816622pfh.9.1701373225625; Thu, 30 Nov 2023 11:40:25 -0800 (PST) Received: from localhost (fwdproxy-prn-005.fbsv.net. [2a03:2880:ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id g2-20020aa78742000000b006cda62f118bsm1593501pfo.60.2023.11.30.11.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 11:40:25 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, cerasuolodomenico@gmail.com, yosryahmed@google.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, chrisl@kernel.org, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: [PATCH v8 2/6] memcontrol: implement mem_cgroup_tryget_online() Date: Thu, 30 Nov 2023 11:40:19 -0800 Message-Id: <20231130194023.4102148-3-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130194023.4102148-1-nphamcs@gmail.com> References: <20231130194023.4102148-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C68324000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 8mqtks915bctci4mjbaq7987jbh1jigf X-HE-Tag: 1701373226-189298 X-HE-Meta: U2FsdGVkX1/tF0GkAczgO1ziHu0sR89R7jQiLqf/1gxQv+QncQ7bKZUbHjSqR8xUeUCeAMdqFQgUKxoTRqmfq6hAsPZ1EwWL1VkaXYICIS5wSUoPd+lxNJwCIBJKWMcr9S/kjPjo9+7KqBFUww808IRL4bhm3GvDDyfDGvo/JcwfdkUDZrl6zwkgtjMazwUXX0sSiZBI6pLgRG1akAQyVEhiv/AKj4B421o4Rj3TqaqxmTP3T4FdrhVVqcpmLL4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rLzBtWTdB5lqL6cZGqc4+2eeGDbZnV+TGsnTMdgKIoOXXT4bNOBg8LxcDcA6fPcTxp8/y69qdidBXnN8rTaFUNAXfJeojk/HiYd00MLWY43ClSZ5Q1XiIE2ZOht+aJ8ZWJKxT0cqJre1rzJdZzGiWeMyIH X-Bogosity: Ham, tests=bogofilter, spamicity=0.000073, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This patch implements a helper function that try to get a reference to an memcg's css, as well as checking if it is online. This new function is almost exactly the same as the existing mem_cgroup_tryget(), except for the onlineness check. In the !CONFIG_MEMCG case, it always returns true, analogous to mem_cgroup_tryget(). This is useful for e.g to the new zswap writeback scheme, where we need to select the next online memcg as a candidate for the global limit reclaim. Signed-off-by: Nhat Pham Reviewed-by: Yosry Ahmed --- include/linux/memcontrol.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 7bdcf3020d7a..2bd7d14ace78 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -821,6 +821,11 @@ static inline bool mem_cgroup_tryget(struct mem_cgroup *memcg) return !memcg || css_tryget(&memcg->css); } +static inline bool mem_cgroup_tryget_online(struct mem_cgroup *memcg) +{ + return !memcg || css_tryget_online(&memcg->css); +} + static inline void mem_cgroup_put(struct mem_cgroup *memcg) { if (memcg) @@ -1349,6 +1354,11 @@ static inline bool mem_cgroup_tryget(struct mem_cgroup *memcg) return true; } +static inline bool mem_cgroup_tryget_online(struct mem_cgroup *memcg) +{ + return true; +} + static inline void mem_cgroup_put(struct mem_cgroup *memcg) { }