cgroup: Simplify cgroup_disable loop given limited count
PATCH 1/1 cgroup: Simplify cgroup_disable loop given limited count
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
--- kernel/cgroup/cgroup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/cgroup/cgroup.c +5 -5
@@ -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 ; } }
Signature · 1 line
2.20.1
Michal Koutný
maintainerQuoted 3 lines · Zhen Ni
This patch refactors the
cgroup_disableloop incgroup_disable()to leverage the fact thatOPT_FEATURE_COUNTcan 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