From: Chen Ridong <chenridong@huawei.com>
To: <tj@kernel.org>, <lizefan.x@bytedance.com>, <hannes@cmpxchg.org>,
<longman@redhat.com>, <adityakali@google.com>,
<sergeh@kernel.org>, <mkoutny@suse.com>
Cc: <cgroups@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<chenridong@huaweicloud.com>
Subject: [PATCH v1 -next 2/3] cgroup/freezer: Reduce redundant propagation for cgroup_propagate_frozen
Date: Thu, 5 Sep 2024 13:41:29 +0000 [thread overview]
Message-ID: <20240905134130.1176443-3-chenridong@huawei.com> (raw)
In-Reply-To: <20240905134130.1176443-1-chenridong@huawei.com>
When a cgroup is frozen/unfrozen, it will always propagate down to up.
However it is unnecessary to propagate to the top every time. This patch
aims to reduce redundant propagation for cgroup_propagate_frozen.
For example, subtree like:
a
|
b
/ | \
c d e
If c is frozen, and d and e are not frozen now, it doesn't have to
propagate to a; Only when c, d and e are all frozen, b and a could be set
to frozen. Therefore, if nr_frozen_descendants is not equal to
nr_descendants, just stop propagate. If a descendant is frozen, the
parent's nr_frozen_descendants add child->nr_descendants + 1. This can
reduce redundant propagation.
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
kernel/cgroup/freezer.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/kernel/cgroup/freezer.c b/kernel/cgroup/freezer.c
index 02af6c1fa957..e4bcc41b6a30 100644
--- a/kernel/cgroup/freezer.c
+++ b/kernel/cgroup/freezer.c
@@ -13,7 +13,7 @@
*/
static void cgroup_propagate_frozen(struct cgroup *cgrp, bool frozen)
{
- int desc = 1;
+ struct cgroup *child = cgrp;
/*
* If the new state is frozen, some freezing ancestor cgroups may change
@@ -23,23 +23,38 @@ static void cgroup_propagate_frozen(struct cgroup *cgrp, bool frozen)
*/
while ((cgrp = cgroup_parent(cgrp))) {
if (frozen) {
- cgrp->freezer.nr_frozen_descendants += desc;
+ /*
+ * A cgroup is frozen, parent nr frozen descendants should add
+ * nr cgroups of the entire subtree , including child itself.
+ */
+ cgrp->freezer.nr_frozen_descendants += child->nr_descendants + 1;
+
+ /*
+ * If there is other descendant is not frozen,
+ * cgrp and its parent couldn't be frozen, just break
+ */
+ if (cgrp->freezer.nr_frozen_descendants !=
+ cgrp->nr_descendants)
+ break;
+
+ child = cgrp;
if (!test_bit(CGRP_FROZEN, &cgrp->flags) &&
- test_bit(CGRP_FREEZE, &cgrp->flags) &&
- cgrp->freezer.nr_frozen_descendants ==
- cgrp->nr_descendants) {
+ test_bit(CGRP_FREEZE, &cgrp->flags)) {
set_bit(CGRP_FROZEN, &cgrp->flags);
cgroup_file_notify(&cgrp->events_file);
TRACE_CGROUP_PATH(notify_frozen, cgrp, 1);
- desc++;
}
} else {
- cgrp->freezer.nr_frozen_descendants -= desc;
+ cgrp->freezer.nr_frozen_descendants -= (child->nr_descendants + 1);
+
+ child = cgrp;
if (test_bit(CGRP_FROZEN, &cgrp->flags)) {
clear_bit(CGRP_FROZEN, &cgrp->flags);
cgroup_file_notify(&cgrp->events_file);
TRACE_CGROUP_PATH(notify_frozen, cgrp, 0);
- desc++;
+ } else {
+ /* If parent is unfrozen, don't have to propagate more */
+ break;
}
}
}
--
2.34.1
next prev parent reply other threads:[~2024-09-05 13:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 13:41 [PATCH v1 -next 0/3] Some optimizations about freezer Chen Ridong
2024-09-05 13:41 ` [PATCH v1 -next 1/3] cgroup/freezer: Reduce redundant traversal for cgroup_freeze Chen Ridong
2024-09-09 19:01 ` Michal Koutný
2024-09-10 2:39 ` Chen Ridong
2024-09-05 13:41 ` Chen Ridong [this message]
2024-09-09 19:02 ` [PATCH v1 -next 2/3] cgroup/freezer: Reduce redundant propagation for cgroup_propagate_frozen Michal Koutný
2024-09-10 3:08 ` Chen Ridong
2024-09-10 11:33 ` Michal Koutný
2024-09-05 13:41 ` [PATCH v1 -next 3/3] cgroup/freezer: Add freeze selftest Chen Ridong
2024-09-09 19:03 ` Michal Koutný
2024-09-10 3:09 ` Chen Ridong
2024-09-09 19:04 ` [PATCH v1 -next 0/3] Some optimizations about freezer Michal Koutný
2024-09-10 3:16 ` Chen Ridong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240905134130.1176443-3-chenridong@huawei.com \
--to=chenridong@huawei.com \
--cc=adityakali@google.com \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huaweicloud.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=longman@redhat.com \
--cc=mkoutny@suse.com \
--cc=sergeh@kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®