From mboxrd@z Thu Jan 1 00:00:00 1970 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 1EF0EC54742 for ; Tue, 27 Aug 2024 23:11:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A42066B0088; Tue, 27 Aug 2024 19:11:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CB356B008A; Tue, 27 Aug 2024 19:11:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81C066B008C; Tue, 27 Aug 2024 19:11:43 -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 62E726B0088 for ; Tue, 27 Aug 2024 19:11:43 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 93735120573 for ; Tue, 27 Aug 2024 23:11:42 +0000 (UTC) X-FDA: 82499574444.28.35E6D56 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf02.hostedemail.com (Postfix) with ESMTP id C781580012 for ; Tue, 27 Aug 2024 23:11:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=oNMMifdo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3K13OZggKCFwECHM8SBIAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--kinseyho.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3K13OZggKCFwECHM8SBIAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--kinseyho.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724800203; 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=uLJnrvY/TNbJZgveXjXzKwi1waLm2OswD6XrKXtY0Dg=; b=BoXXS7paHl29T4eFbi1h42yT9A2cYNwUsKRZSmcLS5qZ4S4cQ+dtFD9caWcDHTcHf7XNCE RVBaTeWBHu6aeAlXWj+ROb7g39PsiLOIHFNCUeBhoKvBTC+oSmXOdSvEhX+kukdNOrEzgu 6gawmihZA6ZBwbNaRpBzDU7pKOnnaqo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724800203; a=rsa-sha256; cv=none; b=66bRhQeRDZ0OhgsYSs4cJLY0tX1Ra3rHzrldoAArx7rJVRRwag+AamgfJ8vLgcx/nLf2Hl 5qeDbbJUk9gcngalrDgvxrcJcvtk6lztmDjO0kpwjnme3G7MWn9hvlvJ5vglxr0J21Ly8/ JxdJxVsnO3o6IyvD2mJ3hggScHkqPnA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=oNMMifdo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3K13OZggKCFwECHM8SBIAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--kinseyho.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3K13OZggKCFwECHM8SBIAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--kinseyho.bounces.google.com Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7cd7cd2f915so4785097a12.3 for ; Tue, 27 Aug 2024 16:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724800299; x=1725405099; 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=uLJnrvY/TNbJZgveXjXzKwi1waLm2OswD6XrKXtY0Dg=; b=oNMMifdoyd4HGcN88WBLwJV/zLBNE4DujjHmVTxT0UQ+D9vPltRDCyPPHm6VsqekH6 tPkXNA3V9rrcdMygW6bVDbkJd1KFqzn5HP0uHbma2emx0+nlBQIBlXoUs89ciEuZeGs+ QHzoGiOPVSApNZwZjrx7+COLWb/VvhH6QIk+CBDTFZ4lxfn1Es+3rU7oumXfBZD926o8 4XtbBDcysWHNcByG0OcT48RelCvU6OSe5p8k+pCkAb7NK32pVOZlzsclRFHziGOpvEM4 /acvJOx3LTsid4pKbsuKgWvLueDSQGRPDinHpk6YYI57hBsNYktu/tiqAG7CJzNXtduO mfTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724800299; x=1725405099; 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=uLJnrvY/TNbJZgveXjXzKwi1waLm2OswD6XrKXtY0Dg=; b=A9QDw3dIQIFIYr0j0HXCDVsEVFrdUQZKe4hvLGdzXBywGAa66+i1LryXxvPX7lOtYV 2h96qt/hO6nudwN+u00mHNoSbxnfgipI31yRTu7NqOWIEZgt8aNnJPz8IKzLXi+ucdB3 Sb8ArAjG/okNorqrxJd7i+QnHTs+PRnj3i/F3/KeQ7wZq/RyctNq99w1ZlLBFfznzhWy pMKediepT+fr+Ej6c2zgysIVul1NTLoJwC3pI8VC3c0oH8PlMVooAVX6ejzuUwHQzYBh iIzoytTH1+GwP/Sx1EhqmldZWJ8G1hGD5oixGh4OqSvzK+oI1+LjYm4oPN8Feu9PWjWX WXog== X-Gm-Message-State: AOJu0YxXdOS24hOTJ4Io6ruxi8/fV+q/ubDznMxc8iQfQb4QYO18Utbw J8qSz9F8dEkROfhgpS+/9dn6DMn29Y361JO9YHo4KCEIG8uGbNUdKQi72YKNviHnifXi9SExCWE S+nTChIPR6g== X-Google-Smtp-Source: AGHT+IEokv9e6LuULnuwid4WZdlPlarG8J+pXfvpDb7CgbDsiCb9RtBxcqB82FKfSIIge11nvt7XccQqszzV4Q== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a05:6a02:5aa:b0:6e7:95d3:b35c with SMTP id 41be03b00d2f7-7d2228eb22fmr302a12.5.1724800299140; Tue, 27 Aug 2024 16:11:39 -0700 (PDT) Date: Tue, 27 Aug 2024 23:07:38 +0000 In-Reply-To: <20240827230753.2073580-1-kinseyho@google.com> Mime-Version: 1.0 References: <20240827230753.2073580-1-kinseyho@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Message-ID: <20240827230753.2073580-2-kinseyho@google.com> Subject: [PATCH mm-unstable v3 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C781580012 X-Stat-Signature: 7ak8i3k36p5kgj3mhqqj7tu48isdzd4k X-Rspam-User: X-HE-Tag: 1724800300-310666 X-HE-Meta: U2FsdGVkX18jjg/IbB9eS17AaPN++cXOv6qAAtgGNMYe0jrWU3hbRfhnp8Xsn033CuCdv7WgvkvXl1qAbyP9SAWGq+gy8d9Ecae9uc+iW3L42M/wPRsaUEEn7HnePRoWQrnd1SaGERSAxCDu/lHxSL3u+QjN4sW1Q5R5105yucIXuAB9yw5m2jU4p0udOJLWaIezhKGkJVLkwjCZ+jicERJP1cu4OAhzQZ3k9TM2PW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q3Rbh5gdXUMNLhAyLRTsWS9nJV8JMWaV1YdjPpKe56DKxgsAsmrbdfjQa2SGO3tV/QbOB00gBbX+/H/LQw+TIxVmZSzTghu0sWmEHYN9DeduSXoeH+vm4jCsJF+d5lTNL8WuxJyehSReWlON5VDsi+Qh0mWQNDrkF84osMs6KGfDMhYlto77OzjM1+84znIm0VLRZwyWIHLu8F5w2PDmB6WRz5svrcNsOpxOe6AZya8gErt2rkSZf/gdpYHeHySp7AhRh39NrIojKvCnFe/3inqw1cJfcevbT+MIcbzUzxMJOUpe6tEbKSpSFCEX42gipT8QJHIBRr78BAR94Wl7t83gOBkmawjHpoj1wHewG/JjJ 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=C3=BD Signed-off-by: Kinsey Ho --- 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; =20 - /* 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; =20 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 cgr= oup_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 critica= l - * 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 critica= l - * 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 *p= os) * * While this function requires cgroup_mutex or RCU read locking, it * doesn't require the whole traversal to be contained in a single critica= l - * 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 --=20 2.46.0.295.g3b9ea8a38a-goog