From patchwork Tue Aug 13 20:47:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13762480 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 C00BCC52D7C for ; Tue, 13 Aug 2024 20:47:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 544B16B0088; Tue, 13 Aug 2024 16:47:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CE426B0089; Tue, 13 Aug 2024 16:47:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36EA96B008A; Tue, 13 Aug 2024 16:47:58 -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 1B0536B0088 for ; Tue, 13 Aug 2024 16:47:58 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CFC3080AA5 for ; Tue, 13 Aug 2024 20:47:57 +0000 (UTC) X-FDA: 82448408994.08.0D4BF28 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf25.hostedemail.com (Postfix) with ESMTP id 18C6DA0002 for ; Tue, 13 Aug 2024 20:47:55 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KY0qMkMM; spf=pass (imf25.hostedemail.com: domain of 3esa7ZggKCDMZXchTnWdVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--kinseyho.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3esa7ZggKCDMZXchTnWdVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723582040; a=rsa-sha256; cv=none; b=votLucSxZDV64eFrqeYV13Vk34GErBFjYiF6uzNfiE5LiLJeEoccjymxyY2XxqgkBDWmiP AYWGAsKlE5lRFEGG+HmDqVEqjGqltiMThjVdcdUXQu5NB7iexQopoS6ylET93X8Q0H7V+Y Q2l5q01A5GYzxJj74Wyc+/lMMt+5Oqk= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KY0qMkMM; spf=pass (imf25.hostedemail.com: domain of 3esa7ZggKCDMZXchTnWdVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--kinseyho.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3esa7ZggKCDMZXchTnWdVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723582040; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BYWJhwEE6NYCkgyDLBhCsOHKcazNm9LYuzYyiRCtiIM=; b=6RthOxdi4l0PbSc9Um3fpSphKiuwextS8PHxlhNJy3xoKIBPI2rSIV6vo0IWrIRE87WEaw CTZ2afUDA+Q/hcETF1Erjtg4kWUMxw6xU8n0c8AlelkyaTtfq/Sk15GUxBIQAN3uTmaJVa DjMNIS0M3MtP5P5kWzm+poV8GNL/mx0= Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7163489149fso5671087a12.3 for ; Tue, 13 Aug 2024 13:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723582075; x=1724186875; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BYWJhwEE6NYCkgyDLBhCsOHKcazNm9LYuzYyiRCtiIM=; b=KY0qMkMM74trKa4IbhOc6/gMRi1YFaCX9McZxjn4mz+Wvg8WUJxqETzJhlQrXLGGxr ZvpcGoXZMJY6oPqf8Z85eJquMU2MwdIMjSSvTVZbIpgFTRG+oCB79w0dGshtgdXnXg6/ K0ogped9qx7wlosOniisfkR+bpvYbnOoj4IgmB+9P/E2ndvbmAINfenyDm1si/gxwnCG wQa/k3g0Zi1SXtm+odkyjDiSFun4LAld7VDRdwu/oOQM76VNV2mwzI1sAXJ41w+JwJJC eeIEViAXsitRzwzbHYQhGVMRXmn6UIQp+rTCGlafGQrj5M8Q7YMGylAOE4pABVc4hOgF Vy+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723582075; x=1724186875; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BYWJhwEE6NYCkgyDLBhCsOHKcazNm9LYuzYyiRCtiIM=; b=qSfigpbTMX0TvyksR7GKUOPyaeNA4cdf59zltu8cftMTMSJOgxhsxwD/Vp8FiDoCqc 0xAc5zbpcdlOdGUEc+CsaPT41M12VTIsY2qNJoXzrH1G59viYx2AjWLc9CT3MLavJBf4 WUJQYK28s8r9daTnQpBpZP+5JXdPFOmS3YqZl+WRhLL7Oea/nbNcke05XoFDHRI+Wswu uyXlZ1lp9s8SIsAl8vpC5fd1LTauBBw7xiC7ffHgndH9Gma9/lxg7rjiYv38CEP6xGtc ikAFbPtzVe60CxAkD68h6rIpBxeTu0HTXuf4inH4NPDKP2bMH9L8UA6tALvo4gUNoNV/ 6JsQ== X-Gm-Message-State: AOJu0YxhegXTY8AX2rCklB77GZVqDL5TWWOXwfr/1xct69oT6u4rbQJp Mb9jJ+OPVJeYt6BmcQmBJPfsGJsqaMd812ZiPUoCLIXhNYRNkMn4B2jI8QyyFYFObHSvlqBHQwz 5BLJVLjSMVw== X-Google-Smtp-Source: AGHT+IHxMBB1WIpSpQKruSLzaZb5mFQ79yQ49km4F0bFBxJKf7BgUc4XswgMUAKJQxmwnNey7FUrSuzdOv6Aag== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a63:114a:0:b0:694:4311:6eb4 with SMTP id 41be03b00d2f7-7c6a587fd3fmr1059a12.8.1723582074503; Tue, 13 Aug 2024 13:47:54 -0700 (PDT) Date: Tue, 13 Aug 2024 20:47:11 +0000 In-Reply-To: <20240813204716.842811-1-kinseyho@google.com> Mime-Version: 1.0 References: <20240813204716.842811-1-kinseyho@google.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog Message-ID: <20240813204716.842811-2-kinseyho@google.com> Subject: [PATCH mm-unstable v2 1/5] cgroup: clarify css sibling linkage is protected by cgroup_mutex or RCU From: Kinsey Ho To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Yosry Ahmed , Roman Gushchin , Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Tejun Heo , Zefan Li , mkoutny@suse.com, Kinsey Ho X-Stat-Signature: 8qeat1dawfiq7z46zic83u55qabu6cns X-Rspamd-Queue-Id: 18C6DA0002 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723582075-442775 X-HE-Meta: U2FsdGVkX19YnT9lu8eRfdBF+FdFR9fyiR9uIfUl+EduA27chLdIG4ZkyS8LoLietaKipP58NtnpUUy2A0EL+ZpDHNUjfRz6yIZIgEZCn9f6Ceh00lW7/JHuUnfCBJMTGwOHvaGNt6QDUrC/Pa44owU8BR47Ith4suPbDZCMzormXYlmZorkLP6u/OcB4eL8riVBrLxKASivUwxg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4HFIajxGpY9HvfGMFWPwqjt7mwzbLAntkATdjKFz3PMCBXWrXKE5rOxV7xyuMeZdyME/BLD6DYGHTAKV+Wim0aph/BB4Sx61nT52jEdZm2VnFreW+vTZ4jgL0HJAt3+FOP+QJJ28aW+g8sy+9I9W/8p0ftlYjQ1ICFQnK7R2DzAmD9CL9P8eimfdn2l88dyKEgBq/iPL+xKxP72tS0Hm7VRlyaZCfRhr6+I+k+iZ6Gmn9KqqVm4TZYgkfYoWONvbDgA9JqHuh9yHSCmUsZTg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Explicitly document that css sibling/descendant linkage is protected by cgroup_mutex or RCU. Also, document in css_next_descendant_pre() and similar functions that is isn't necessary to hold a ref on @pos. The following changes in this patchset rely on this clarification for simplification in memcg iteration code. Suggested-By: Yosry Ahmed Signed-Off-By: Kinsey Ho Reviewed-by: Michal Koutný --- include/linux/cgroup-defs.h | 6 +++++- kernel/cgroup/cgroup.c | 16 +++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 7fc2d0195f56..6862243bd1c2 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -172,7 +172,11 @@ struct cgroup_subsys_state { /* reference count - access via css_[try]get() and css_put() */ struct percpu_ref refcnt; - /* siblings list anchored at the parent's ->children */ + /* + * siblings list anchored at the parent's ->children + * + * linkage is protected by cgroup_mutex or RCU + */ struct list_head sibling; struct list_head children; diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 0a97cb2ef124..ece2316e2bca 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -4602,8 +4602,9 @@ struct cgroup_subsys_state *css_next_child(struct cgroup_subsys_state *pos, * * While this function requires cgroup_mutex or RCU read locking, it * doesn't require the whole traversal to be contained in a single critical - * section. This function will return the correct next descendant as long - * as both @pos and @root are accessible and @pos is a descendant of @root. + * section. Additionally, it isn't necessary to hold onto a reference to @pos. + * This function will return the correct next descendant as long as both @pos + * and @root are accessible and @pos is a descendant of @root. * * If a subsystem synchronizes ->css_online() and the start of iteration, a * css which finished ->css_online() is guaranteed to be visible in the @@ -4651,8 +4652,9 @@ EXPORT_SYMBOL_GPL(css_next_descendant_pre); * * While this function requires cgroup_mutex or RCU read locking, it * doesn't require the whole traversal to be contained in a single critical - * section. This function will return the correct rightmost descendant as - * long as @pos is accessible. + * section. Additionally, it isn't necessary to hold onto a reference to @pos. + * This function will return the correct rightmost descendant as long as @pos + * is accessible. */ struct cgroup_subsys_state * css_rightmost_descendant(struct cgroup_subsys_state *pos) @@ -4696,9 +4698,9 @@ css_leftmost_descendant(struct cgroup_subsys_state *pos) * * While this function requires cgroup_mutex or RCU read locking, it * doesn't require the whole traversal to be contained in a single critical - * section. This function will return the correct next descendant as long - * as both @pos and @cgroup are accessible and @pos is a descendant of - * @cgroup. + * section. Additionally, it isn't necessary to hold onto a reference to @pos. + * This function will return the correct next descendant as long as both @pos + * and @cgroup are accessible and @pos is a descendant of @cgroup. * * If a subsystem synchronizes ->css_online() and the start of iteration, a * css which finished ->css_online() is guaranteed to be visible in the