From: Zhen Ni <zhen.ni@easystack.cn>
To: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com
Cc: cgroups@vger.kernel.org, Zhen Ni <zhen.ni@easystack.cn>
Subject: [PATCH] cgroup: Simplify cgroup_disable loop given limited count
Date: Wed, 30 Jul 2025 16:10:15 +0800 [thread overview]
Message-ID: <20250730081015.910435-1-zhen.ni@easystack.cn> (raw)
This patch refactors the cgroup_disable loop in cgroup_disable() to
leverage the fact that OPT_FEATURE_COUNT can only be 0 or 1, making
the loop structure unnecessary complex.
Key insights:
- OPT_FEATURE_COUNT is defined as an enum value that is either:
* 0 when CONFIG_PSI is disabled (no optional features)
* 1 when CONFIG_PSI is enabled (only "pressure" feature)
- Therefore, the loop will either:
* Run 0 times (when no features exist)
* Run exactly 1 time (when only one feature exists)
Performance considerations:
- The change has no performance impact since the loop runs at most once
Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
---
kernel/cgroup/cgroup.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index a723b7dc6e4e..71059b61b341 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -6895,11 +6895,11 @@ static int __init cgroup_disable(char *str)
}
for (i = 0; i < OPT_FEATURE_COUNT; i++) {
- if (strcmp(token, cgroup_opt_feature_names[i]))
- continue;
- cgroup_feature_disable_mask |= 1 << i;
- pr_info("Disabling %s control group feature\n",
- cgroup_opt_feature_names[i]);
+ if (!strcmp(token, cgroup_opt_feature_names[i])) {
+ cgroup_feature_disable_mask |= 1 << i;
+ pr_info("Disabling %s control group feature\n",
+ cgroup_opt_feature_names[i]);
+ }
break;
}
}
--
2.20.1
next reply other threads:[~2025-07-30 8:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-30 8:10 Zhen Ni [this message]
2025-07-30 8:36 ` [PATCH] cgroup: Simplify cgroup_disable loop given limited count Michal Koutný
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=20250730081015.910435-1-zhen.ni@easystack.cn \
--to=zhen.ni@easystack.cn \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=mkoutny@suse.com \
--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;
as well as URLs for NNTP newsgroup(s).