* [PATCH] cgroup: Simplify cgroup_disable loop given limited count
@ 2025-07-30 8:10 Zhen Ni
2025-07-30 8:36 ` Michal Koutný
0 siblings, 1 reply; 2+ messages in thread
From: Zhen Ni @ 2025-07-30 8:10 UTC (permalink / raw)
To: tj, hannes, mkoutny; +Cc: cgroups, Zhen Ni
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cgroup: Simplify cgroup_disable loop given limited count
2025-07-30 8:10 [PATCH] cgroup: Simplify cgroup_disable loop given limited count Zhen Ni
@ 2025-07-30 8:36 ` Michal Koutný
0 siblings, 0 replies; 2+ messages in thread
From: Michal Koutný @ 2025-07-30 8:36 UTC (permalink / raw)
To: Zhen Ni; +Cc: tj, hannes, cgroups
[-- Attachment #1: Type: text/plain, Size: 484 bytes --]
On Wed, Jul 30, 2025 at 04:10:15PM +0800, Zhen Ni <zhen.ni@easystack.cn> wrote:
> 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.
(The complexity measure here is subjective.)
But this rework would make the parsing subtly broken when enum
cgroup_opt_features is expandded in the future, it should be generic not
crafted for a particular value.
Michal
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-30 8:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-30 8:10 [PATCH] cgroup: Simplify cgroup_disable loop given limited count Zhen Ni
2025-07-30 8:36 ` Michal Koutný
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).