From patchwork Thu Sep 5 00:30:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 13791565 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 6339DCD4F4A for ; Thu, 5 Sep 2024 00:31:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E34A26B01F5; Wed, 4 Sep 2024 20:31:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBD4E6B01F6; Wed, 4 Sep 2024 20:31:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC1C06B01F8; Wed, 4 Sep 2024 20:31:52 -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 96D816B01F5 for ; Wed, 4 Sep 2024 20:31:52 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 50565120F57 for ; Thu, 5 Sep 2024 00:31:52 +0000 (UTC) X-FDA: 82528806864.21.E9EB4D9 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf13.hostedemail.com (Postfix) with ESMTP id 80DB620004 for ; Thu, 5 Sep 2024 00:31:49 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=joyyH0Rc; spf=pass (imf13.hostedemail.com: domain of 38_vYZggKCIw0y38uEx4w44w1u.s421y3AD-220Bqs0.47w@flex--kinseyho.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=38_vYZggKCIw0y38uEx4w44w1u.s421y3AD-220Bqs0.47w@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=1725496181; 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=OCIYE2bxjzqInsqy6M77OBXOLSiNi2ahaVS1P1UY4eQ=; b=oM1YnjYPnjtqCLF3f/GwJwiXFahQ7n+4zdN3uiOUirvCQ5NjHdhNQQlpPK+229kgFQny4D yWFU/kBy2G0MOVHbcER3J2ZA6KrWU7yfH5ZT8ydTGr+SDoOtYn+EboqVewT8uMH0kQWN0z 4j3MK7v1I3UxaSaUxMFzjK4vi6K/6w4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=joyyH0Rc; spf=pass (imf13.hostedemail.com: domain of 38_vYZggKCIw0y38uEx4w44w1u.s421y3AD-220Bqs0.47w@flex--kinseyho.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=38_vYZggKCIw0y38uEx4w44w1u.s421y3AD-220Bqs0.47w@flex--kinseyho.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725496181; a=rsa-sha256; cv=none; b=2HNhXWyrz3KHGAx0knR1sUvlsjfH31FHgIYWpYqH5SkxXtNH3GWmoHZL8UQ+ihtTvsBG9w H3graLI9HVkCcaHV8pqgWb/SMrg5PaU6tJ3JYcS8VdgyCoz9DOBDaEtod22vI/Fl2Llnbt lfEUqmBY9HZbwsEB0HU7TcPv9vOjqks= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-717453c0677so265456b3a.0 for ; Wed, 04 Sep 2024 17:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725496308; x=1726101108; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=OCIYE2bxjzqInsqy6M77OBXOLSiNi2ahaVS1P1UY4eQ=; b=joyyH0RcblKxhnnsniUWvgrVNYgCxHF9LFLKBuhQ00Q+2/HXf6QLK4Zyb1k1Fr+ZCT fIR/8hy1KMlPv6Zj93HTesflId5b1ptZoErIQfio7008NbsfUEfi7XqMhOgF9F+AsAXI elWDMJp+P4u/mL4z/Yr9+oJmaEj5+n+tYFunAPms9l6vhDrlsx2aj8qhl+gK+1Wh4TVG fhwVC56bg4fFG6sRFCCNN+51Dmjk/e+nBRhT4cLy5Hec7e770li4K5GIH8Jx5wb3d0RL EcmTGjFU75/U3xDXfS3uNBVQTIUvScHcgmF97sBk9QmzOyamoZOkleuoS3eGMOPRkoWV /9vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725496308; x=1726101108; h=content-transfer-encoding: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=OCIYE2bxjzqInsqy6M77OBXOLSiNi2ahaVS1P1UY4eQ=; b=xCQVc42vy9/ZOQHwrfB+C8yMdAtLIBMMTGubT6e4aKDkQQVnlAvVXcdnmGDEZgk2Ye QzS6m1fG7Y+oYSPjNJwp9J2UUFxQCnmL8gYoo6lXJR0zpIURs5+FkIKTul778l5B0g1X qDKK+nTM+SbMpR0AkKoa4N3rQSXsyIIhvR6DhbI3MAvC4AmMRlTdUtKJpy5XEPkc0B+/ drM0tgevNGUninFvtT9wQQInsXei7RBEAqEKufutR6Ux7GohAp4/BxZPakPljNgrfier UKhCSmiK6UxTm9LbtFiBAGSN/ZBhb5V+zB9uL5JP/LNKq4kX5/YruzME66qZ+sZy8evi +kmw== X-Gm-Message-State: AOJu0YzWWlP3QRbIZCag1vlHlCn/WOqXd2AdnwrwOFZcIfv3Pal001k0 fF37FYMK/t5/loUPsIOkg1ngFgjvcBWnG05Lzzd+OnIjJtUy5vVmJd9WJgN6YOhzEbJbyA7HnDJ EnJeyjQDi2Q== X-Google-Smtp-Source: AGHT+IHUPQSbmeHjhZigLeW58QOY18ICrs203NRPh39wz9VYTS5JC1PdHx3HOB6u+ncLsUa1QDiBpyCBj6pKLQ== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a05:6a00:8682:b0:714:1e0f:4477 with SMTP id d2e1a72fcca58-71730791c72mr43937b3a.5.1725496307872; Wed, 04 Sep 2024 17:31:47 -0700 (PDT) Date: Thu, 5 Sep 2024 00:30:50 +0000 In-Reply-To: <20240905003058.1859929-1-kinseyho@google.com> Mime-Version: 1.0 References: <20240905003058.1859929-1-kinseyho@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240905003058.1859929-2-kinseyho@google.com> Subject: [PATCH mm-unstable v4 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, "T . J . Mercier" , Hugh Dickins , Kinsey Ho X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 80DB620004 X-Stat-Signature: gjw3jpegfddimg98qaerfk7bp9xftbqb X-Rspam-User: X-HE-Tag: 1725496309-358706 X-HE-Meta: U2FsdGVkX19iAV+pPD6GV4m/V5yiD6qJQLQSwErgoAlpws6sfExr1h4labV5EPF+b1SLye5iBAYcEgtuYG9AhhyV5uGszk96o7JP/0PhgzF65RrbxoQ7zX5NzV0UE2Rv3lRLr/CFZUpk0kLMiMhM3S8uKMjyiRFw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FR1SSpKR+SddyrRzhinPZfV+LdY1Mu/N30aQLsZWleptR0rn9bjbz70XQbtJeE7gAXOUIS8OKtzsQOkgrkfbzzO22FYk0unT+ZQM2+D3uV/jbPpidCXJQKt2vav5ll7Cho15NQId8Qm1ZZVmRGD6g4X7Q9SdGkOIF6GeznZdM8Emxunb82FD6tVMG6X+SPHvjmoG4jYUDaJyBrzHfjcYUFtV/4iYEuCeb5dIL+VrE//Ach3/0afXZTLDx7CZtxPlHoEHVBcX8kbD+OOSmBkmw1Djn+OUGvaqKnHC9VWcCu8PNuz+aaFT0vYNq7RHDnM2pbKEBzNvfc+WBbMYRHfy6XqvNTGQTVyMzH2fAuncYFPC9bX/2LDMakn2MPDlAEVu2O509w2ZCx2DVOi5OVACoIHS/Y4MZ0o2jWU1hS8Z2kKjLQNkUdxE1KcTrcHch70lMlPXBRB2phuHElm3SKWRRURI6sQ7nfBJLpoKFYuB8M6j/ZoxKQdMZC0lCZa7xob/nF/aZ+HNrmOMhAyHQ= 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: 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 it 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 Reviewed-by: Michal Koutný Signed-off-by: Kinsey Ho Cc: Johannes Weiner Cc: Michal Hocko Cc: Muchun Song Cc: Roman Gushchin Cc: Shakeel Butt Cc: Tejun Heo Cc: Zefan Li Cc: Hugh Dickins Cc: T.J. Mercier --- 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..ca7e912b8355 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