From patchwork Fri Jan 3 01:50:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JP Kobryn X-Patchwork-Id: 13925086 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 D61A0E77197 for ; Fri, 3 Jan 2025 01:50:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 334966B0089; Thu, 2 Jan 2025 20:50:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E58B6B008A; Thu, 2 Jan 2025 20:50:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 136496B008C; Thu, 2 Jan 2025 20:50:40 -0500 (EST) 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 E3C176B0089 for ; Thu, 2 Jan 2025 20:50:39 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 92475AEB6E for ; Fri, 3 Jan 2025 01:50:39 +0000 (UTC) X-FDA: 82964460180.15.9B49EB3 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf07.hostedemail.com (Postfix) with ESMTP id E47A34000F for ; Fri, 3 Jan 2025 01:49:03 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="M5rdg/CO"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735868990; a=rsa-sha256; cv=none; b=w+UrlwEMRd9tGuYS8jNV4quH4DB8qrzhJbzezz//VkvSwFR/P4496ezyM4evuVWzUmAPJf H7Y3LfZPQfUxSjMUQAz7zCZ7fO87bvjQErz8Lt2wFBoCquD8W1yL1I4l/LwyQ5ZysnSWM2 3SrfPpDhbKy4H1XlPCz6xnZpjo1V5NI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="M5rdg/CO"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735868990; 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=13LzpkMgO0b7mnyCmlNhqmibgyHhCXjzFtjSKM6aNYI=; b=w8CGIXPvRUNcjvhvGtP8Svl1zHCZS3J0dDYkyHVgXvwTHY3oHct4m9DvnK/2zo4TqydhX9 MMZhbR1fENpgkH+LHnXl0dzMiItnBqppeNQyY9AKkIXWurfQsc7RGxVugNkhOEkm5OJVq7 8y/EAPEOb+xRgtJoW6LdiZrCeJvQ/Rw= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2166651f752so189385695ad.3 for ; Thu, 02 Jan 2025 17:50:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735869036; x=1736473836; 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=13LzpkMgO0b7mnyCmlNhqmibgyHhCXjzFtjSKM6aNYI=; b=M5rdg/CO3tJ85wTL4NJOSDzmBhEjdCWaFkIUHi0AqtbZyYV4DrhW0yCIFG4DKUqHkJ MsKPYalSB+boszBqryZ1qRKGUgoU7wgr5HUXmzUezria2Sbyyjo3RFiwvLHEg59FJwR7 HClXE6MDPGNWL+Rfr5Q4TdmZB3YlmTRCDvBd1RsGidAN1Nie1Aivc3y6cTWKYNL/0845 nzAtvMZIi6lTzrY1hmMEB2lLII66C3edBipe4zpNSRdltIHq/dGZ9dEvC9KVId3Dhf0j UUx0d8xJeXIW9QjQVzCfURgLN/eMHwJniONQzISPazO9EXX3Mji2ve2gYHzECn5roF5Z 6RgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735869036; x=1736473836; 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=13LzpkMgO0b7mnyCmlNhqmibgyHhCXjzFtjSKM6aNYI=; b=oo+OF2dyR+V87YTACsCrQsCvO+WCuRKW0gmLW9nQ09QU0v5MK32maU378qGDa3E2se HNzTfFcDa76IWcsnvNJg0l5P4leqRtAwvWGAG3H98znpYR7U3rNo96W9QzgSNvA37dLC /1xSfct8ojexpXFVXmVebf+cYP9bq+gQ9N9ee6MykI49QlRVz9Nu69NPuoZQ3A/nmg/b g47ZMkHVESYrvvBHwO348yLlvTBebj0UAAnnEqhNQO6vaGQmYF1n6V8VnbSTKtOY9dx8 KMTYv+Q0XjT+yClWaamQMaOOE+Ww8Gg4YQyBrAASUIW9PzftzYnwgiHHOfLXll1P1yYG hEWA== X-Gm-Message-State: AOJu0Yz11OacC3KezkKNlg6nXe5fO7RjfwsGCVmk2jRqOF+k/GzsbvRg LwYt7PJtXtGPWinJ1sXqctWuk6JC58QKOK9CDX5Z17ALFY/o4kpd X-Gm-Gg: ASbGnctEilGuYI56HMMyflCpczILqody29wKGH9EmIbU1JHsIe1ZvQjwr57qjb7gkKO 51ocmIZPiXg5c4+wvNaNYIbiHb8SMK9AUhb/TGdKSyLDogJToFbf8t2HxizA6EhXcGtC2HE4gE7 qwyLE/DUKo+di7rzNGriQfAFqAmqVAPvJCfVwVsbIbKZbyjMpGHC8iwl38xCfwlP7uWjbfanC2d iIiLaAZwWBnxESbfXaIw+6WO5hbW8kN3NHnSpxFFc1d7IAR32I3FEq2Ju9RNNJaaAeuJgPOf1+u guEMZ0/7CPGpxDwK4g== X-Google-Smtp-Source: AGHT+IEWZ1I3vK8+zRzdBRThBatrKNxc73IbhcbqXpn8Rkn5yh7Bv+OzoAldowPIPiXgzKBnPFiCjw== X-Received: by 2002:a17:903:24e:b0:215:5625:885b with SMTP id d9443c01a7336-219e6f28552mr729349425ad.52.1735869036439; Thu, 02 Jan 2025 17:50:36 -0800 (PST) Received: from saturn.. (c-67-188-127-15.hsd1.ca.comcast.net. [67.188.127.15]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca04ce7sm228851505ad.283.2025.01.02.17.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 17:50:35 -0800 (PST) From: JP Kobryn To: shakeel.butt@linux.dev, tj@kernel.org, mhocko@kernel.org, hannes@cmpxchg.org, yosryahmed@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, cgroups@vger.kernel.org Subject: [RFC PATCH 4/9 v2] cgroup: split rstat from cgroup into separate css Date: Thu, 2 Jan 2025 17:50:15 -0800 Message-ID: <20250103015020.78547-5-inwardvessel@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103015020.78547-1-inwardvessel@gmail.com> References: <20250103015020.78547-1-inwardvessel@gmail.com> MIME-Version: 1.0 X-Stat-Signature: b78doqntwrb9r6na7c6qduw3osbziww9 X-Rspam-User: X-Rspamd-Queue-Id: E47A34000F X-Rspamd-Server: rspam08 X-HE-Tag: 1735868943-610708 X-HE-Meta: U2FsdGVkX1+E8VYToOhvIsKW6m+4glBhNeHRiDa9Ydvm/B6b4d+ZyAyBRJp4usGCHK3xxX+ALWVEKQMolu0OZ3eHoL2+5MRrKWPZkLOyCrFUTyxijcDwdXKzncQqzddy2KfUb8TK9lwhZqkitVZvn9n3jD86dyo074rMOaBBCmJ/Q2XfRf2/98UkQ8QLMKmgqiPvxcZVQa7sNkg0RSpxZ7b6I3wDIxdgqT6UOWMuYMaIJNppK+q9+h1LbL/gZlIRvWcnlwbNbCkXM76zGlFLwf/Ibkhirf/bBmP9yaXlZbKqlZeXTm41BKhU5z5BsStp3o2YN156Y8ezvS0ZkgFgHvm6F84QgW6yoiQesk5VcjPECxc76zvUZyKKHOXZt9Trg+tnco0F+YX7C8Sgmph6//XGsxHyPjOpQnT9COnpDJ7hvq8NZiUfDzjH3cO6E7LX1XJXSsV0sa1jdaZ3Db8zYC6RzyxyoiVTAwIjpZkx6rIGzn/k+vpShqu1a5huKfHJEVLJzoKaqHGt+NKmml8lZzH5sYzyhAV/Mvxie7C7ZzBpt8lS/Tt5+CS8V42+aYefqUsl7RY+aUXnSNqe+K3sy3rDohhJfE1GTU8aRad9hWemm+nQxWolj/kkOzvJwLDK0LdXYbA7OfcrzFTcbOK98ScIDhjMwhHwG9yZXAewogMcquQ1RMz3I+vO/9kuQSjwxlikvdGtqBu7KLgy6jNHDCKgIE5m94bJ3PakzH9EZClgoaGJ80aQosj/fZNilGtUfdOc9FBRSmVCh5H3eB9rVzcJGo8F935mRhoYckXg/iqACGQg4Ts23t9NoU7Uob1KG1pRcAG6bp4nvTYVsW03bycbllfrXXtH9th7738m6aNqHQRLqIzlS/Bi0XSMLtdsYCBcd0X89PEwtHM1iE6oUh3aEK9EyCjrTCh7tQIjVFIa8aY3KZYE2VBRtxwUadpI7Z783OV84CcCc2ZCYOl 5L3dEgNM S6PLcJfB2/Dot9MjNpn16DN/50qAlT4siQDAbQ4oJ14qq9J2lWeyG+ELGkLzXe4sSWfL4YMZikd7BYlNKChAiig6ls604MWBGgm4dxN39FoR2gdSvZiBp5Gi4l0HpkwP7GHiJb4InO7rxmGidP7PdKx3MF3IwlpscuqUyfOx42atOCwWSHr1FEEluUyLdRuzLyniL2R1EWZlJexJ9Y8azUBcdTorLdzt4oavoAUHE/mlV/f+l6C6W9Rn9RhQlGu15nnhwW7WGGqf558MbHdLv34VzcsP7PV0/ySGw09jfiMKsL7rSNVOtt7kjKE/9Y0Tbe1ZKFJroda/+qFVGt1aTpYQZcSOZNs7fjBF4JdkU2scAmBpE0oIy1LuPlQ== 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: Move the rstat entities off of the cgroup struct and onto the cgroup_subsys_state struct. Adjust related code to reflect this new ownership. Signed-off-by: JP Kobryn --- include/linux/cgroup-defs.h | 40 ++++++++-------- kernel/cgroup/cgroup.c | 65 ++++++++++++++++++-------- kernel/cgroup/rstat.c | 92 ++++++++++++++++++------------------- 3 files changed, 111 insertions(+), 86 deletions(-) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 1b20d2d8ef7c..1932f8ae7995 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -180,6 +180,24 @@ struct cgroup_subsys_state { struct list_head sibling; struct list_head children; + /* per-cpu recursive resource statistics */ + struct cgroup_rstat_cpu __percpu *rstat_cpu; + struct list_head rstat_css_list; + + /* + * Add padding to separate the read mostly rstat_cpu and + * rstat_css_list into a different cacheline from the following + * rstat_flush_next and *bstat fields which can have frequent updates. + */ + CACHELINE_PADDING(_pad_); + + /* + * A singly-linked list of cgroup structures to be rstat flushed. + * This is a scratch field to be used exclusively by + * cgroup_rstat_flush_locked() and protected by cgroup_rstat_lock. + */ + struct cgroup_subsys_state *rstat_flush_next; + /* flush target list anchored at cgrp->rstat_css_list */ struct list_head rstat_css_node; @@ -389,8 +407,8 @@ struct cgroup_rstat_cpu { * * Protected by per-cpu cgroup_rstat_cpu_lock. */ - struct cgroup *updated_children; /* terminated by self cgroup */ - struct cgroup *updated_next; /* NULL iff not on the list */ + struct cgroup_subsys_state *updated_children; /* terminated by self cgroup */ + struct cgroup_subsys_state *updated_next; /* NULL iff not on the list */ }; struct cgroup_freezer_state { @@ -516,24 +534,6 @@ struct cgroup { struct cgroup *dom_cgrp; struct cgroup *old_dom_cgrp; /* used while enabling threaded */ - /* per-cpu recursive resource statistics */ - struct cgroup_rstat_cpu __percpu *rstat_cpu; - struct list_head rstat_css_list; - - /* - * Add padding to separate the read mostly rstat_cpu and - * rstat_css_list into a different cacheline from the following - * rstat_flush_next and *bstat fields which can have frequent updates. - */ - CACHELINE_PADDING(_pad_); - - /* - * A singly-linked list of cgroup structures to be rstat flushed. - * This is a scratch field to be used exclusively by - * cgroup_rstat_flush_locked() and protected by cgroup_rstat_lock. - */ - struct cgroup *rstat_flush_next; - /* cgroup basic resource statistics */ struct cgroup_base_stat last_bstat; struct cgroup_base_stat bstat; diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 848e09f433c0..96a2d15fe5e9 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -164,7 +164,7 @@ static struct static_key_true *cgroup_subsys_on_dfl_key[] = { static DEFINE_PER_CPU(struct cgroup_rstat_cpu, cgrp_dfl_root_rstat_cpu); /* the default hierarchy */ -struct cgroup_root cgrp_dfl_root = { .cgrp.rstat_cpu = &cgrp_dfl_root_rstat_cpu }; +struct cgroup_root cgrp_dfl_root = { .cgrp.self.rstat_cpu = &cgrp_dfl_root_rstat_cpu }; EXPORT_SYMBOL_GPL(cgrp_dfl_root); /* @@ -1826,6 +1826,7 @@ int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask) struct cgroup_root *src_root = ss->root; struct cgroup *scgrp = &src_root->cgrp; struct cgroup_subsys_state *css = cgroup_css(scgrp, ss); + struct cgroup_subsys_state *dcss = cgroup_css(dcgrp, ss); struct css_set *cset, *cset_pos; struct css_task_iter *it; @@ -1867,7 +1868,7 @@ int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask) list_del_rcu(&css->rstat_css_node); synchronize_rcu(); list_add_rcu(&css->rstat_css_node, - &dcgrp->rstat_css_list); + &dcss->rstat_css_list); } /* default hierarchy doesn't enable controllers by default */ @@ -2052,7 +2053,6 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp) cgrp->dom_cgrp = cgrp; cgrp->max_descendants = INT_MAX; cgrp->max_depth = INT_MAX; - INIT_LIST_HEAD(&cgrp->rstat_css_list); prev_cputime_init(&cgrp->prev_cputime); for_each_subsys(ss, ssid) @@ -2088,7 +2088,8 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask) struct cgroup *root_cgrp = &root->cgrp; struct kernfs_syscall_ops *kf_sops; struct css_set *cset; - int i, ret; + struct cgroup_subsys *ss; + int i, ret, ssid; lockdep_assert_held(&cgroup_mutex); @@ -2132,10 +2133,6 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask) if (ret) goto destroy_root; - ret = cgroup_rstat_init(&root_cgrp->self); - if (ret) - goto destroy_root; - ret = rebind_subsystems(root, ss_mask); if (ret) goto exit_stats; @@ -2174,7 +2171,10 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask) goto out; exit_stats: - cgroup_rstat_exit(&root_cgrp->self); + for_each_subsys(ss, ssid) { + struct cgroup_subsys_state *css = init_css_set.subsys[ssid]; + cgroup_rstat_exit(css); + } destroy_root: kernfs_destroy_root(root->kf_root); root->kf_root = NULL; @@ -3229,6 +3229,10 @@ static int cgroup_apply_control_enable(struct cgroup *cgrp) int ssid, ret; cgroup_for_each_live_descendant_pre(dsct, d_css, cgrp) { + ret = cgroup_rstat_init(&dsct->self); + if (ret) + return ret; + for_each_subsys(ss, ssid) { struct cgroup_subsys_state *css = cgroup_css(dsct, ss); @@ -3239,6 +3243,10 @@ static int cgroup_apply_control_enable(struct cgroup *cgrp) css = css_create(dsct, ss); if (IS_ERR(css)) return PTR_ERR(css); + + ret = cgroup_rstat_init(css); + if (ret) + goto err_free_css; } WARN_ON_ONCE(percpu_ref_is_dying(&css->refcnt)); @@ -3252,6 +3260,20 @@ static int cgroup_apply_control_enable(struct cgroup *cgrp) } return 0; + +err_free_css: + cgroup_for_each_live_descendant_pre(dsct, d_css, cgrp) { + cgroup_rstat_exit(&dsct->self); + + for_each_subsys(ss, ssid) { + struct cgroup_subsys_state *css = cgroup_css(dsct, ss); + + if (css != &dsct->self) + cgroup_rstat_exit(css); + } + } + + return ret; } /** @@ -5403,6 +5425,7 @@ static void css_free_rwork_fn(struct work_struct *work) struct cgroup_subsys_state, destroy_rwork); struct cgroup_subsys *ss = css->ss; struct cgroup *cgrp = css->cgroup; + int ssid; percpu_ref_exit(&css->refcnt); @@ -5435,7 +5458,12 @@ static void css_free_rwork_fn(struct work_struct *work) cgroup_put(cgroup_parent(cgrp)); kernfs_put(cgrp->kn); psi_cgroup_free(cgrp); - cgroup_rstat_exit(css); + for_each_subsys(ss, ssid) { + struct cgroup_subsys_state *css = cgrp->subsys[ssid]; + + if (css) + cgroup_rstat_exit(css); + } kfree(cgrp); } else { /* @@ -5541,6 +5569,7 @@ static void init_and_link_css(struct cgroup_subsys_state *css, css->id = -1; INIT_LIST_HEAD(&css->sibling); INIT_LIST_HEAD(&css->children); + INIT_LIST_HEAD(&css->rstat_css_list); INIT_LIST_HEAD(&css->rstat_css_node); css->serial_nr = css_serial_nr_next++; atomic_set(&css->online_cnt, 0); @@ -5551,7 +5580,7 @@ static void init_and_link_css(struct cgroup_subsys_state *css, } if (ss->css_rstat_flush) - list_add_rcu(&css->rstat_css_node, &cgrp->rstat_css_list); + list_add_rcu(&css->rstat_css_node, &css->rstat_css_list); BUG_ON(cgroup_css(cgrp, ss)); } @@ -5686,14 +5715,6 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name, if (ret) goto out_free_cgrp; - /* init self cgroup early so css->cgroup is valid within cgroup_rstat_init() - * note that this will go away in a subsequent patch in this series - */ - cgrp->self.cgroup = cgrp; - ret = cgroup_rstat_init(&cgrp->self); - if (ret) - goto out_cancel_ref; - /* create the directory */ kn = kernfs_create_dir_ns(parent->kn, name, mode, current_fsuid(), current_fsgid(), @@ -5784,7 +5805,6 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name, kernfs_remove(cgrp->kn); out_stat_exit: cgroup_rstat_exit(&cgrp->self); -out_cancel_ref: percpu_ref_exit(&cgrp->self.refcnt); out_free_cgrp: kfree(cgrp); @@ -6189,6 +6209,8 @@ int __init cgroup_init(void) cgroup_unlock(); for_each_subsys(ss, ssid) { + struct cgroup_subsys_state *css; + if (ss->early_init) { struct cgroup_subsys_state *css = init_css_set.subsys[ss->id]; @@ -6200,6 +6222,9 @@ int __init cgroup_init(void) cgroup_init_subsys(ss, false); } + css = init_css_set.subsys[ss->id]; + BUG_ON(cgroup_rstat_init(css)); + list_add_tail(&init_css_set.e_cset_node[ssid], &cgrp_dfl_root.cgrp.e_csets[ssid]); diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 01a5c185b02a..4381eb9ac426 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -14,9 +14,10 @@ static DEFINE_PER_CPU(raw_spinlock_t, cgroup_rstat_cpu_lock); static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu); -static struct cgroup_rstat_cpu *cgroup_rstat_cpu(struct cgroup *cgrp, int cpu) +static struct cgroup_rstat_cpu *css_rstat_cpu( + struct cgroup_subsys_state *css, int cpu) { - return per_cpu_ptr(cgrp->rstat_cpu, cpu); + return per_cpu_ptr(css->rstat_cpu, cpu); } /* @@ -96,15 +97,16 @@ __bpf_kfunc void cgroup_rstat_updated(struct cgroup_subsys_state *css, int cpu) * instead of NULL, we can tell whether @cgrp is on the list by * testing the next pointer for NULL. */ - if (data_race(cgroup_rstat_cpu(cgrp, cpu)->updated_next)) + if (data_race(css_rstat_cpu(css, cpu)->updated_next)) return; flags = _cgroup_rstat_cpu_lock(cpu_lock, cpu, cgrp, true); /* put @cgrp and all ancestors on the corresponding updated lists */ while (true) { - struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu); - struct cgroup *parent = cgroup_parent(cgrp); + struct cgroup_rstat_cpu *rstatc = css_rstat_cpu(css, cpu); + struct cgroup_subsys_state *parent = css->parent +; struct cgroup_rstat_cpu *prstatc; /* @@ -116,15 +118,15 @@ __bpf_kfunc void cgroup_rstat_updated(struct cgroup_subsys_state *css, int cpu) /* Root has no parent to link it to, but mark it busy */ if (!parent) { - rstatc->updated_next = cgrp; + rstatc->updated_next = css; break; } - prstatc = cgroup_rstat_cpu(parent, cpu); + prstatc = css_rstat_cpu(parent, cpu); rstatc->updated_next = prstatc->updated_children; - prstatc->updated_children = cgrp; + prstatc->updated_children = css; - cgrp = parent; + css = parent; } _cgroup_rstat_cpu_unlock(cpu_lock, cpu, cgrp, flags, true); @@ -142,12 +144,13 @@ __bpf_kfunc void cgroup_rstat_updated(struct cgroup_subsys_state *css, int cpu) * into a singly linked list built from the tail backward like "pushing" * cgroups into a stack. The root is pushed by the caller. */ -static struct cgroup *cgroup_rstat_push_children(struct cgroup *head, - struct cgroup *child, int cpu) +static struct cgroup_subsys_state *cgroup_rstat_push_children( + struct cgroup_subsys_state *head, + struct cgroup_subsys_state *child, int cpu) { - struct cgroup *chead = child; /* Head of child cgroup level */ - struct cgroup *ghead = NULL; /* Head of grandchild cgroup level */ - struct cgroup *parent, *grandchild; + struct cgroup_subsys_state *chead = child; /* Head of child cgroup level */ + struct cgroup_subsys_state *ghead = NULL; /* Head of grandchild cgroup level */ + struct cgroup_subsys_state *parent, *grandchild; struct cgroup_rstat_cpu *crstatc; child->rstat_flush_next = NULL; @@ -156,13 +159,13 @@ static struct cgroup *cgroup_rstat_push_children(struct cgroup *head, while (chead) { child = chead; chead = child->rstat_flush_next; - parent = cgroup_parent(child); + parent = child->parent; /* updated_next is parent cgroup terminated */ while (child != parent) { child->rstat_flush_next = head; head = child; - crstatc = cgroup_rstat_cpu(child, cpu); + crstatc = css_rstat_cpu(child, cpu); grandchild = crstatc->updated_children; if (grandchild != child) { /* Push the grand child to the next level */ @@ -201,16 +204,15 @@ static struct cgroup *cgroup_rstat_push_children(struct cgroup *head, * within the children list and terminated by the parent cgroup. An exception * here is the cgroup root whose updated_next can be self terminated. */ -static struct cgroup *cgroup_rstat_updated_list(struct cgroup_subsys_state *root_css, - int cpu) +static struct cgroup_subsys_state *cgroup_rstat_updated_list( + struct cgroup_subsys_state *root, int cpu) { - struct cgroup *root = root_css->cgroup; raw_spinlock_t *cpu_lock = per_cpu_ptr(&cgroup_rstat_cpu_lock, cpu); - struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(root, cpu); - struct cgroup *head = NULL, *parent, *child; + struct cgroup_rstat_cpu *rstatc = css_rstat_cpu(root, cpu); + struct cgroup_subsys_state *head = NULL, *parent, *child; unsigned long flags; - flags = _cgroup_rstat_cpu_lock(cpu_lock, cpu, root, false); + flags = _cgroup_rstat_cpu_lock(cpu_lock, cpu, root->cgroup, false); /* Return NULL if this subtree is not on-list */ if (!rstatc->updated_next) @@ -220,17 +222,17 @@ static struct cgroup *cgroup_rstat_updated_list(struct cgroup_subsys_state *root * Unlink @root from its parent. As the updated_children list is * singly linked, we have to walk it to find the removal point. */ - parent = cgroup_parent(root); + parent = root->parent; if (parent) { struct cgroup_rstat_cpu *prstatc; - struct cgroup **nextp; + struct cgroup_subsys_state **nextp; - prstatc = cgroup_rstat_cpu(parent, cpu); + prstatc = css_rstat_cpu(parent, cpu); nextp = &prstatc->updated_children; while (*nextp != root) { struct cgroup_rstat_cpu *nrstatc; - nrstatc = cgroup_rstat_cpu(*nextp, cpu); + nrstatc = css_rstat_cpu(*nextp, cpu); WARN_ON_ONCE(*nextp == parent); nextp = &nrstatc->updated_next; } @@ -247,7 +249,7 @@ static struct cgroup *cgroup_rstat_updated_list(struct cgroup_subsys_state *root if (child != root) head = cgroup_rstat_push_children(head, child, cpu); unlock_ret: - _cgroup_rstat_cpu_unlock(cpu_lock, cpu, root, flags, false); + _cgroup_rstat_cpu_unlock(cpu_lock, cpu, root->cgroup, flags, false); return head; } @@ -316,13 +318,13 @@ static void cgroup_rstat_flush_locked(struct cgroup_subsys_state *css) lockdep_assert_held(&cgroup_rstat_lock); for_each_possible_cpu(cpu) { - struct cgroup *pos = cgroup_rstat_updated_list(css, cpu); + struct cgroup_subsys_state *pos = cgroup_rstat_updated_list(css, cpu); for (; pos; pos = pos->rstat_flush_next) { struct cgroup_subsys_state *css_iter; - cgroup_base_stat_flush(pos, cpu); - bpf_rstat_flush(pos, cgroup_parent(pos), cpu); + cgroup_base_stat_flush(pos->cgroup, cpu); + bpf_rstat_flush(pos->cgroup, cgroup_parent(pos->cgroup), cpu); rcu_read_lock(); list_for_each_entry_rcu(css_iter, &pos->rstat_css_list, @@ -392,21 +394,20 @@ void cgroup_rstat_flush_release(struct cgroup_subsys_state *css) int cgroup_rstat_init(struct cgroup_subsys_state *css) { - struct cgroup *cgrp = css->cgroup; int cpu; - /* the root cgrp has rstat_cpu preallocated */ - if (!cgrp->rstat_cpu) { - cgrp->rstat_cpu = alloc_percpu(struct cgroup_rstat_cpu); - if (!cgrp->rstat_cpu) + /* the root cgrp css has rstat_cpu preallocated */ + if (!css->rstat_cpu) { + css->rstat_cpu = alloc_percpu(struct cgroup_rstat_cpu); + if (!css->rstat_cpu) return -ENOMEM; } /* ->updated_children list is self terminated */ for_each_possible_cpu(cpu) { - struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu); + struct cgroup_rstat_cpu *rstatc = css_rstat_cpu(css, cpu); - rstatc->updated_children = cgrp; + rstatc->updated_children = css; u64_stats_init(&rstatc->bsync); } @@ -415,22 +416,21 @@ int cgroup_rstat_init(struct cgroup_subsys_state *css) void cgroup_rstat_exit(struct cgroup_subsys_state *css) { - struct cgroup *cgrp = css->cgroup; int cpu; - cgroup_rstat_flush(&cgrp->self); + cgroup_rstat_flush(css); /* sanity check */ for_each_possible_cpu(cpu) { - struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu); + struct cgroup_rstat_cpu *rstatc = css_rstat_cpu(css, cpu); - if (WARN_ON_ONCE(rstatc->updated_children != cgrp) || + if (WARN_ON_ONCE(rstatc->updated_children != css) || WARN_ON_ONCE(rstatc->updated_next)) return; } - free_percpu(cgrp->rstat_cpu); - cgrp->rstat_cpu = NULL; + free_percpu(css->rstat_cpu); + css->rstat_cpu = NULL; } void __init cgroup_rstat_boot(void) @@ -471,7 +471,7 @@ static void cgroup_base_stat_sub(struct cgroup_base_stat *dst_bstat, static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu) { - struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu); + struct cgroup_rstat_cpu *rstatc = css_rstat_cpu(&cgrp->self, cpu); struct cgroup *parent = cgroup_parent(cgrp); struct cgroup_rstat_cpu *prstatc; struct cgroup_base_stat delta; @@ -501,7 +501,7 @@ static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu) cgroup_base_stat_add(&cgrp->last_bstat, &delta); delta = rstatc->subtree_bstat; - prstatc = cgroup_rstat_cpu(parent, cpu); + prstatc = css_rstat_cpu(&parent->self, cpu); cgroup_base_stat_sub(&delta, &rstatc->last_subtree_bstat); cgroup_base_stat_add(&prstatc->subtree_bstat, &delta); cgroup_base_stat_add(&rstatc->last_subtree_bstat, &delta); @@ -513,7 +513,7 @@ cgroup_base_stat_cputime_account_begin(struct cgroup *cgrp, unsigned long *flags { struct cgroup_rstat_cpu *rstatc; - rstatc = get_cpu_ptr(cgrp->rstat_cpu); + rstatc = get_cpu_ptr(cgrp->self.rstat_cpu); *flags = u64_stats_update_begin_irqsave(&rstatc->bsync); return rstatc; }